cpp
#include<conio.h>
#include<windows.h>
#include<bits/stdc++.h>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<string>
using namespace std;
int Your=6,Other=6;
string daojuname[]={"放大镜","shou'k","太监(刀)","羽毛(烟)","马尿(饮料)"};
double Yourmoney;
int ex=0,level=1,money=100,hp=112,fangyu=0,hurt=10,mhp=112;
int huixie=0;
int win=0;
int levelfe=0,levelcloth=0;
int fe=0,cloth=0;
int n;
int shi,kong;
int q[10],qlen;
int Rand(int x,int y){
int A=rand(),B=rand();
return A*1ll*B%(y-x+1)+x;
}
// 技能结构体
struct Skill {
std::string name;
int damage;
int manaCost;
double critRate;
};
// 战斗函数
void battle(int& playerHealth, int playerMana, bool hasSword) {
int enemyHealth = 120;
int enemyDefense = 10;
int playerDefense = hasSword? 15 : 10;
int playerBaseAttack = hasSword? 30 : 15;
int enemyBaseAttack = 25;
// 定义玩家技能
Skill normalAttack = {"普通攻击", playerBaseAttack, 0, 0.1};
Skill powerSlash = {"强力斩击", 50, 20, 0.3};
Skill magicBlast = {"魔法冲击", 60, 30, 0.4};
std::cout << "战斗开始!" << std::endl;
while (playerHealth > 0 && enemyHealth > 0) {
std::cout << "你的生命值: " << playerHealth << ",魔法值: " << playerMana << std::endl;
std::cout << "敌人生命值: " << enemyHealth << std::endl;
std::cout << "请选择技能: 1. 普通攻击(无消耗) 2. 强力斩击(消耗20魔法值) 3. 魔法冲击(消耗30魔法值): ";
int choice;
std::cin >> choice;
Skill selectedSkill;
switch (choice) {
case 1:
selectedSkill = normalAttack;
break;
case 2:
if (playerMana < 20) {
std::cout << "魔法值不足,只能使用普通攻击。" << std::endl;
selectedSkill = normalAttack;
} else {
selectedSkill = powerSlash;
playerMana -= 20;
}
break;
case 3:
if (playerMana < 30) {
std::cout << "魔法值不足,只能使用普通攻击。" << std::endl;
selectedSkill = normalAttack;
} else {
selectedSkill = magicBlast;
playerMana -= 30;
}
break;
default:
std::cout << "无效选择,使用普通攻击。" << std::endl;
selectedSkill = normalAttack;
break;
}
// 暴击判断
bool isCrit = (double)std::rand() / RAND_MAX < selectedSkill.critRate;
int finalDamage = selectedSkill.damage;
if (isCrit) {
finalDamage *= 2;
std::cout << "暴击!造成双倍伤害!" << std::endl;
}
int actualDamage = finalDamage - enemyDefense;
if (actualDamage < 0) actualDamage = 0;
enemyHealth -= actualDamage;
std::cout << "你使用 " << selectedSkill.name << ",对敌人造成 " << actualDamage << " 点伤害。" << std::endl;
if (enemyHealth <= 0) {
std::cout << "你打败了敌人!" << std::endl;
break;
}
// 敌人攻击
isCrit = (double)std::rand() / RAND_MAX < 0.2;
finalDamage = enemyBaseAttack;
if (isCrit) {
finalDamage *= 2;
std::cout << "敌人暴击!造成双倍伤害!" << std::endl;
}
actualDamage = finalDamage - playerDefense;
if (actualDamage < 0) actualDamage = 0;
playerHealth -= actualDamage;
std::cout << "敌人发起攻击,对你造成 " << actualDamage << " 点伤害。" << std::endl;
if (playerHealth <= 0) {
std::cout << "你被敌人打败了,游戏结束。" << std::endl;
break;
}
}
}
void over()
{
system("cls");
cout<<endl<<endl;
cout<<" $$$感 谢 游 玩 本 游 戏$$$"<<endl<<endl;
cout<<" 按任意键退出"<<endl;
char x=_getch();
return ;
}
class Player {
public:
int gold;
int reputation; // 声誉影响NPC态度
Player() : gold(100), reputation(0) {}
};
void clearInputBuffer() {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
bool diceGame(Player& player) {
cout << "\n=== 骰子游戏 ===" << endl;
cout << "下注金额(你当前有" << player.gold << "金): ";
int bet;
cin >> bet;
if (bet <= 0 || bet > player.gold) {
cout << "无效的下注!" << endl;
clearInputBuffer();
return false;
}
srand(time(0));
int playerRoll = rand() % 6 + 1;
int dealerRoll = rand() % 6 + 1;
// 欺诈机制:30%概率作弊
if ((rand() % 100) < 30) {
dealerRoll += 2; // 庄家作弊
cout << "(你感觉庄家眼神有些可疑...)" << endl;
}
cout << "你的点数: " << playerRoll << endl;
cout << "庄家点数: " << dealerRoll << endl;
if (playerRoll > dealerRoll) {
player.gold += bet;
cout << "你赢了!获得 " << bet << " 金!" << endl;
player.reputation++;
} else {
player.gold -= bet;
cout << "你输了!失去 " << bet << " 金!" << endl;
player.reputation--;
}
return true;
}
void talkToNPC(int reputation) {
string npcLines[] = {
"来一杯麦酒吗?","你还剩多少钱?···(他看着你钱)","来玩骰子吗?","听说东边森林有宝藏...(但他说这话时在回避你的目光)",
"酒保可能在酒里掺水...",
"最近商队会带着稀有货物经过",
"别信那个赌鬼的话,他出老千!"
};
if (reputation < 0) {
cout << "\n醉汉: 你个菜鸟别烦我!" << endl;
} else {
int index = rand() % 4;
cout << "\n旅行者: " << npcLines[index] << endl;
if (rand() % 100 < 50) {
cout << "(你感觉他可能没有说实话...)" << endl;
}
}
}
void tavernMenu() {
Player player;
bool inTavern = true;
while (inTavern) {
cout << "\n=== 骗子酒馆 ===" << endl;
cout << "1. 玩骰子游戏" << endl;
cout << "2. 与NPC交谈" << endl;
cout << "3. 买麦酒(10金)" << endl;
cout << "4. 离开酒馆" << endl;
cout << "选择操作: ";
int choice;
cin >> choice;
switch(choice) {
case 1:
diceGame(player);
break;
case 2:
talkToNPC(player.reputation);
break;
case 3: {
int cost = 10;
if (player.gold >= cost) {
player.gold -= cost;
cout << "你买了一杯麦酒"
<< ((rand()%100 < 30) ? "(尝起来有点淡...)" : "")
<< endl;
} else {
cout << "金币不足!" << endl;
}
break;
}
case 4:
inTavern = false;
cout << "你离开了酒馆..." << endl;
break;
default:
cout << "无效的选择!" << endl;
clearInputBuffer();
}
if (player.gold <= 0) {
cout << "\n你破产了!被赶出酒馆!" << endl;
inTavern = false;
}
}
}
// 原代码其他部分保持不变,以下是原有代码...
void risecloth()
{
cout<<endl<<endl;
cout<<" 装备等级:"<<levelcloth<<endl<<endl;
cout<<" 装备效果:防御+"<<levelcloth<<endl<<endl;
cout<<" 升级需要"<<levelcloth/2+1<<"布匹"<<endl<<endl;
cout<<" 按1 升级"<<endl<<endl;
cout<<" 按2 返回上一步"<<endl<<endl;
cout<<" 布匹:"<<cloth<<endl;
return ;
}
void risefe()
{
cout<<endl<<endl;
cout<<" 武器等级:"<<levelfe<<endl<<endl;
cout<<" 武器效果:伤害+"<<levelfe<<endl<<endl;
cout<<" 升级需要"<<levelfe/2+1<<"精铁"<<endl<<endl;
cout<<" 按1 升级"<<endl<<endl;
cout<<" 按2 返回上一步"<<endl<<endl;
cout<<" 精铁:"<<fe<<endl;
return ;
}
void situation()
{
cout<<" 血量:"<<hp<<" / "<<mhp<<endl<<endl;
cout<<" 经验:"<<ex<<" / "<<level*100<<endl<<endl;
cout<<" 防御:"<<fangyu<<endl<<endl;
cout<<" 等级:"<<level<<endl<<endl;
cout<<" 伤害:"<<hurt<<endl<<endl;
cout<<" 金币:"<<money<<endl<<endl;
cout<<" 精铁:"<<fe<<endl<<endl;
cout<<" 布匹:"<<cloth<<endl<<endl;
cout<<" 按任意键返回上一步";
return ;
}
void shop()
{
cout<<endl<<endl;
cout<<" 按1 购买更快速回血(加快5秒回血速度) 100金币 ";
if(huixie==3) cout<<"已售罄";
cout<<endl<<endl;
cout<<" 按2 购买精铁 10金币"<<endl<<endl;
cout<<" 按3 购买布匹 10金币"<<endl<<endl;
cout<<" 按4 返回上一步"<<endl<<endl;
cout<<" 金币:"<<money;
return ;
}
void rise()
{
while(ex>=level*100){
ex-=level*100;
level++;
}
mhp=100+12*level;
hp=mhp;
return ;
}
void die()
{
ex=max(0,ex-(level*100/2));
hp=30;
return ;
}
int fight(int a,int b){
while(hp>0&&b>0){
Sleep(700);
system("cls");
cout<<endl<<endl;
cout<<" 你的血量:"<<hp<<" 对手的血量:"<<b<<endl;
hp-=max(0,a-fangyu);
b-=hurt;
}
Sleep(700);
system("cls");
cout<<endl<<endl;
cout<<" 你的血量:"<<hp<<" 对手的血量:"<<b<<endl;
if(hp<=0) return 0;
else return 1;
}
void common()
{
system("cls");
cout<<endl<<endl;
cout<<" 按1 冒险"<<endl<<endl;//OK
cout<<" 按2 升级武器"<<endl<<endl;//OK
cout<<" 按3 升级装备"<<endl<<endl;//OK
cout<<" 按4 进入商店"<<endl<<endl;//OK
cout<<" 按5 工作"<<endl<<endl;//OK
cout<<" 按6 查看状态"<<endl<<endl; //OK
cout<<" 按7 恢复血量"<<endl<<endl; //OK
}
void risk(){
system("cls");
cout<<endl;
cout<<" 你 想 去 哪 里"<<endl<<endl<<endl;
cout<<" 按1 前往 荒村(难度1)"<<endl<<endl;
cout<<" 按2 前往 洞穴(难度2)"<<endl<<endl;
cout<<" 按3 前往 森林(难度3)"<<endl<<endl;
cout<<" 按4 前往 主 城(难度5)"<<endl<<endl;
cout<<" 按5 前往< 皇城/外城 >(难度8)"<<endl<<endl;
cout<<" 按6 前往《 皇城/内城 》(难度12)"<<endl<<endl;
cout<<" 按7 前往 #* 圣 殿 *# (难度18)"<<endl<<endl;
cout<<" 按8 返回上一步"<<endl<<endl;
}
void choose()
{
int x=_getch();
if(x=='1'){
while(1){
risk();
x=_getch();
if(x=='1'){
system("cls");
int t=rand()%2;
if(t==0){
cout<<" 你遇到了野猪(伤害5,血量30),3秒后开始战斗"<<endl;
Sleep(3000);
system("cls");
if(fight(5,30)){
cout<<"你赢了,获得:"<<endl;
cout<<"10经验,10金币";
ex+=10;
rise();
money+=10;
Sleep(1500);
system("cls");
}
else{
cout<<"你死了"<<endl;
Sleep(2500);
die();
break;
}
}
else{
cout<<" 你遇到了流浪者(伤害3,血量50),3秒后开始战斗"<<endl;
Sleep(3000);
system("cls");
if(fight(3,50)){
cout<<"你赢了,获得:"<<endl;
cout<<"5经验,20金币";
ex+=5;
rise();
money+=20;
Sleep(1500);
system("cls");
}
else{
cout<<"你死了"<<endl;
Sleep(2500);
die();
break;
}
}
}
else if(x=='2'){
system("cls");
int t=rand()%2;
if(t==0){
cout<<" 你遇到了毒蛇(伤害20,血量20),3秒后开始战斗"<<endl;
Sleep(3000);
system("cls");
if(fight(20,20)){
int num=rand()%10;
cout<<"你赢了,获得:"<<endl;
cout<<num+15<<"经验,"<<18+num<<"金币";
ex+=num+15;
rise();
money+=18+num;
Sleep(1500);
system("cls");
}
else{
cout<<"你死了"<<endl;
Sleep(2500);
die();
break;
}
}
else{
cout<<" 你遇到了野人(伤害15,血量50),3秒后开始战斗"<<endl;
Sleep(3000);
system("cls");
if(fight(15,50)){
int num=rand()%10+5;
cout<<"你赢了,获得:"<<endl;
cout<<num+20<<"经验,"<<20+num<<"金币";
ex+=num+20;
rise();
money+=num+20;
Sleep(1500);
system("cls");
}
else{
cout<<"你死了"<<endl;
Sleep(2500);
die();
break;
}
}
}
else if(x=='3'){
system("cls");
int t=rand()%3;
if(t==0){
cout<<" 你遇到了老虎(伤害25,血量80),3秒后开始战斗"<<endl;
Sleep(3000);
system("cls");
if(fight(25,80)){
int num=rand()%20;
cout<<"你赢了,获得:"<<endl;
cout<<30+num<<"经验,"<<"50金币";
ex+=num+30;
rise();
money+=50;
Sleep(1500);
system("cls");
}
else{
cout<<"你死了"<<endl;
Sleep(2500);
die();
break;
}
}
else if(t==1){
cout<<" 你遇到了棕熊(伤害20,血量130),3秒后开始战斗"<<endl;
Sleep(3000);
system("cls");
if(fight(20,130)){
cout<<"你赢了,获得:"<<endl;
cout<<"50经验,50金币";
ex+=50;
rise();
money+=50;
Sleep(1500);
system("cls");
}
else{
cout<<"你死了"<<endl;
Sleep(2500);
die();
break;
}
}
else{
cout<<" 你遇到了狼群(总伤害35,总血量140),3秒后开始战斗"<<endl;
Sleep(3000);
system("cls");
if(fight(35,140)){
cout<<"你赢了,获得:"<<endl;
cout<<"65经验,70金币";
ex+=65;
rise();
money+=70;
Sleep(1500);
system("cls");
}
else{
cout<<"你死了"<<endl;
Sleep(2500);
die();
break;
}
}
}
else if(x=='4'){
system("cls");
int t=rand()%3;
if(t==0){
cout<<" 你受到了军队的攻击(总伤害60,总血量200),3秒后开始战斗"<<endl;
Sleep(3000);
system("cls");
if(fight(60,200)){
cout<<"你赢了,获得:"<<endl;
cout<<"105经验,100金币";
ex+=105;
rise();
money+=100;
Sleep(1500);
system("cls");
}
else{
cout<<"你死了"<<endl;
Sleep(2500);
die();
break;
}
}
if(t==1){
cout<<" 你遇到了武术高手(伤害130,血量85),3秒后开始战斗"<<endl;
Sleep(3000);
system("cls");
if(fight(130,85)){
cout<<"你赢了,获得:"<<endl;
int num=rand()%45+100;
cout<<num+100<<"经验,"<<num+95<<"金币";
ex+=num+100;
rise();
money+=95+num;
Sleep(1500);
system("cls");
}
else{
cout<<"你死了"<<endl;
Sleep(2500);
die();
break;
}
}
else{
cout<<" 主城城主(伤害130,血量200)找到了你,与你进行战斗,3秒后开始战斗"<<endl;
Sleep(3000);
system("cls");
if(fight(130,200)){
cout<<"你赢了,获得:"<<endl;
cout<<"180经验,200金币";
ex+=180;
rise();
money+=200;
Sleep(1500);
system("cls");
}
else{
cout<<"你死了"<<endl;
Sleep(2500);
die();
break;
}
}
}
else if(x=='5'){
system("cls");
int t=rand()%10;
if(t==9){
cout<<" 你捡到了一个宝箱,获得200金币"<<endl;
money+=200;
Sleep(1500);
system("cls");
}
else if(t==6||t==8||t==7){
cout<<" 你遇到了皇城分城主(伤害220,血量350),3秒后开始战斗"<<endl;
Sleep(3000);
system("cls");
if(fight(220,350)){
cout<<"你赢了,获得:"<<endl;
int num=rand()%120+260;
cout<<num<<"经验,"<<num<<"金币";
ex+=num+160;
rise();
money+=num+160;
Sleep(1500);
system("cls");
}
else{
cout<<"你死了"<<endl;
Sleep(2500);
die();
break;
}
}
else{
cout<<" 你遇到了皇城护卫军(伤害170,血量300),3秒后开始战斗"<<endl;
Sleep(3000);
system("cls");
if(fight(170,300)){
cout<<"你赢了,获得:"<<endl;
cout<<"155经验,155金币"<<endl;
ex+=155;
rise();
money+=155;
Sleep(1500);
system("cls");
}
else{
cout<<"你死了"<<endl;
Sleep(2500);
die();
break;
}
}
}
else if(x=='6'){
system("cls");
int t=rand()%10;
if(t==9){
cout<<" 你捡到了一个宝箱,获得150精铁,150布匹"<<endl;
fe+=150;
cloth+=150;
Sleep(1500);
system("cls");
}
else if(t==8){
cout<<" 你捡到了一个宝箱,获得1000经验"<<endl;
ex+=1000;
rise();
Sleep(1500);
system("cls");
}
else if(t==7||t==6){
cout<<" 你遇到了皇城城主(伤害400,血量1000),三秒后开始战斗"<<endl;
Sleep(3000);
system("cls");
if(fight(400,1000)){
cout<<"你赢了,获得:"<<endl;
cout<<"300经验,300金币"<<endl;
ex+=300;
rise();
money==300;
Sleep(1500);
system("cls");
}
else{
cout<<"你死了"<<endl;
Sleep(2500);
die();
break;
}
}
else{
cout<<" 你遇到了顶级刺客(伤害360,血量560),三秒后开始战斗"<<endl;
Sleep(3000);
system("cls");
if(fight(360,560)){
cout<<"你赢了,获得:"<<endl;
cout<<"280经验,200金币"<<endl;
ex+=280;
rise();
money+=200;
Sleep(1500);
system("cls");
}
else{
cout<<"你死了"<<endl;
Sleep(2500);
die();
break;
}
}
}
else if(x=='7'){
system("cls");
int t=rand()%3;
if(t==0){
cout<<" 你遇到了盛殿教皇(伤害1000,血量2000),三秒后开始战斗"<<endl;
Sleep(3000);
if(fight(1000,2000)){
cout<<"你打败了教皇,成为了这个世界的最强者,"<<endl;
cout<<"是否继续游戏(y/n)"<<endl;
while(1){
x=getch();
if(x=='y')
break;
else if(x=='n'){
over();
exit(0);
}
}
}
else{
cout<<"你死了"<<endl;
Sleep(2500);
die();
break;
}
}
else if(t==1){
cout<<" 你遇到了一位顶级强者(伤害650,血量1300),三秒后开始战斗"<<endl;
Sleep(3000);
if(fight(650,1300)){
cout<<"你赢了,获得:"<<endl;
cout<<"500经验,500金币";
ex+=500;
rise();
money+=500;
Sleep(1500);
system("cls");
}
else{
cout<<"你死了"<<endl;
Sleep(2500);
die();
break;
}
}
else if(t==2){
cout<<" 你遇到了一位隐世高手(伤害700,血量1500),3秒后开始战斗"<<endl;
Sleep(3000);
if(fight(700,1500)){
cout<<"你赢了,获得:"<<endl;
cout<<"600经验,500金币";
ex+=600;
rise();
money+=500;
Sleep(1500);
system("cls");
}
else{
cout<<"你死了"<<endl;
Sleep(2500);
die();
break;
}
}
}
else if(x=='8'){
break;
}
}
}
else if(x=='4'){
while(1){
system("cls");
shop();
x=_getch();
if(x=='1'){
if(money<100){
cout<<endl<<" 你没有足够的钱";
Sleep(500);
system("cls");
}
else if(huixie==3){
cout<<endl<<" 已售罄"<<endl;
Sleep(500);
system("cls");
}
else{
huixie++;
money-=100;
Sleep(50);
system("cls");
}
}
else if(x=='2'){
if(money<10){
cout<<endl<<" 你没有足够的钱";
Sleep(500);
system("cls");
}
else{
money-=1000;
fe+=100;
Sleep(50);
system("cls");
}
}
else if(x=='3'){
if(money<10){
cout<<endl<<" 你没有足够的钱";
Sleep(500);
system("cls");
}
else
{
money-=1000;
cloth+=100;
Sleep(50);
system("cls");
}
}
else if(x=='4'){
break;
}
}
}
else if(x=='6'){
system("cls");
situation();
x=_getch();
}
else if(x=='7'){
system("cls");
cout<<endl<<endl;
cout<<" 回血中,请等待";
if(huixie==0) cout<<"2S",Sleep(2000);
else if(huixie==1) cout<<"1.5S",Sleep(1500);
else if(huixie==2) cout<<"1S",Sleep(1000);
else cout<<"5S",Sleep(5000);
hp=mhp;
system("cls");
}
else if(x=='5'){
system("cls");
cout<<endl<<endl;
cout<<" 正 在 工 作 , 请 等 待 1 秒";
Sleep(1000);
system("cls");
cout<<endl<<endl;
int t=rand()%3+2;
cout<<" 工作完成,获得"<<1e6<<"金币";
money+=1e6;
Sleep(1500);
system("cls");
}
else if(x=='2'){
while(1){
system("cls");
risefe();
x=_getch();
if(x=='1'){
if(fe<(levelfe/2+1)){
cout<<endl;
cout<<" 你没有足够的精铁";
Sleep(500);
system ("cls");
}
else{
fe-=(levelfe/2+1);
levelfe+=100;
hurt=10+levelfe;
Sleep(50);
system("cls");
}
}
if(x=='2')
break;
}
}
else if(x=='3'){
while(1){
system("cls");
risecloth();
x=_getch();
if(x=='1'){
if(cloth<(levelcloth/2+1)){
cout<<endl;
cout<<" 你没有足够的布匹";
Sleep(500);
system("cls");
}
else{
cloth-=(levelcloth/2+1);
levelcloth+=100;
fangyu=levelcloth;
Sleep(50);
system("cls");
}
}
if(x=='2'){
break;
}
}
}
}
int T;
int daojulen;
int daoju[10];
int daojulen1;
int daoju1[10];
void build_gun(){
kong=Rand(1,4);
shi=Rand(1,4);
qlen=0;
printf("%d发实弹,%d发空弹\n",shi,kong);
int a1=kong,a2=shi;
for(int i=1;i<=kong+shi;i++){
int sum=Rand(1,a1+a2);
if(sum<=a1){
a1--;
q[++qlen]=2;
}else{
a2--;
q[++qlen]=1;
}
}
int maxn=min(4,8-daojulen);
printf("你获得了%d个道具:\n",maxn);
daojulen+=maxn;
for(int i=1;i<=maxn;i++){
int kkk=Rand(0,4);
daoju[kkk]++;
cout<<daojuname[kkk];
if(i!=maxn){
printf(",");
}
}
printf("\n");
maxn=min(4,8-daojulen1);
printf("恶魔获得了%d个道具:\n",maxn);
daojulen1+=maxn;
for(int i=1;i<=maxn;i++){
int kkk=Rand(0,4);
daoju1[kkk]++;
cout<<daojuname[kkk];
if(i!=maxn){
printf(",");
}
}
printf("\n");
system("pause");
system("cls");
}
void IsOver(){
if(Your<=0){
printf("你输了\n");
system("pause");
exit(0);
}
if(Other<=0){
printf("你赢了\n你获得了奖金$%.2lf\n",Yourmoney);
system("pause");
exit(0);
}
}
void wait(){
for(int i=1;i<=3;i++){
Sleep(500);
printf(".");
}
Sleep(500);
}
int Hurt=1;
int shoukao_you;
void Timeyou(){
int x;
while(1){
printf("你的生命:%d/6\n恶魔生命:%d/6\n",Your,Other);
printf("剩余实弹数:%d 剩余空弹数:%d\n",shi,kong);
printf("你现在拥有的道具:\n");
for(int i=0;i<=4;i++){
cout<<daojuname[i];
printf("%d",daoju[i]);
printf("个");
if(i!=4){
printf(",");
}
}
printf("\n");
printf("恶魔现在拥有的道具:\n");
for(int i=0;i<=4;i++){
cout<<daojuname[i];
printf("%d",daoju1[i]);
printf("个");
if(i!=4){
printf(",");
}
}
printf("\n");
printf("现在是你的回合\n");
printf("你要\n1.向恶魔开枪\n2.向自己开枪\n");
for(int i=0;i<=4;i++){
printf("%d.使用",i+3);
cout<<daojuname[i]<<'\n';
}
scanf("%d",&x);
if(1<=x&&x<=7){
break;
}
printf("输入不合法\n");
Sleep(1145);
system("cls");
}
if(x==1){
printf("你决定向恶魔开枪");
T++;
wait();
if(q[qlen]==2){
Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(shi)*1.0/(double)(shi+kong)));
kong--;
qlen--;
Hurt=1;
printf("是空弹\n");
if(shoukao_you==1){
shoukao_you=0;
printf("因为你使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
}else{
Yourmoney+=(double)(5000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
shi--;
qlen--;
Other-=Hurt;
Hurt=1;
printf("是实弹\n");
Sleep(500);
IsOver();
if(shoukao_you==1){
shoukao_you=0;
Yourmoney+=1000.0;
printf("因为你使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
}
}else if(x==2){
printf("你决定向自己开枪");
wait();
if(q[qlen]==2){
Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
kong--;
qlen--;
Hurt=1;
printf("是空弹\n");
}else{
Yourmoney+=5000.0*(1+(double)(shi)*1.0/(double)(shi+kong));
T++;
shi--;
qlen--;
Your-=Hurt;
Hurt=1;
printf("是实弹\n");
Sleep(500);
IsOver();
if(shoukao_you==1){
shoukao_you=0;
printf("因为你使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
}
}else if(x==3){
if(daoju[0]){
daoju[0]--;
daojulen--;
printf("你使用了放大镜\n");
wait();
printf("\n你看到了");
if(q[qlen]==1){
printf("实弹\n");
Yourmoney+=2500.0;
}else{
printf("空弹\n");
}
Sleep(500);
printf("\n");
}else{
printf("你现在没有放大镜\n");
Sleep(1145);
system("cls");
}
}else if(x==4){
if(daoju[1]){
if(!shoukao_you){
daoju[1]--;
daojulen--;
printf("你使用了手铐\n");
printf("你获得了连开两枪的机会\n");
shoukao_you=1;
}else{
printf("你已经用过手铐了\n");
}
Sleep(1145);
system("cls");
}else{
printf("你现在没有手铐\n");
Sleep(1145);
system("cls");
}
}else if(x==5){
if(daoju[2]){
if(Hurt==1){
daoju[2]--;
daojulen--;
printf("你使用了小刀\n");
printf("若下一发为实弹则伤害+1\n");
Yourmoney+=500.0;
Hurt=2;
}else{
printf("你已经用过小刀了\n");
}
Sleep(1145);
system("cls");
}else{
printf("你现在没有小刀\n");
Sleep(1145);
system("cls");
}
}else if(x==6){
if(daoju[3]){
if(Your^6){
daoju[3]--;
daojulen--;
printf("你使用了烟\n");
printf("你回复了一点生命\n");
Yourmoney+=500.0;
Your++;
}else{
printf("你现在不需要烟\n");
}
Sleep(1145);
}else{
printf("你现在没有烟\n");
Sleep(1145);
system("cls");
}
}else{
if(daoju[4]){
daoju[4]--;
daojulen--;
printf("你使用了饮料\n");
wait();
printf("\n");
printf("你退了一发");
if(q[qlen]==2){
printf("空弹");
kong--;
}else{
printf("实弹");
Yourmoney+=500.0;
shi--;
}
qlen--;
Sleep(500);
}else{
printf("你现在没有饮料\n");
Sleep(1145);
system("cls");
}
}
Sleep(1000);
system("cls");
}
int Know;
int shoukaoemo;
void fightyou(){
printf("恶魔决定向你开枪");
T++;
wait();
if(q[qlen]==2){
Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
kong--;
qlen--;
Hurt=1;
Know=0;
printf("是空弹\n");
if(shoukaoemo){
printf("因为恶魔使用了手铐,所以可以再来一次\n");
T--;
Sleep(500);
shoukaoemo=0;
}
}else{
Yourmoney+=(double)(5000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
shi--;
qlen--;
Your-=Hurt;
Hurt=1;
printf("是实弹\n");
Know=0;
Sleep(500);
IsOver();
if(shoukaoemo){
printf("因为恶魔使用了手铐,所以可以再来一次\n");
Yourmoney+=1000.0;
T--;
Sleep(500);
shoukaoemo=0;
}
}
}
void fightemo(){
printf("恶魔决定向自己开枪");
wait();
if(q[qlen]==2){
Yourmoney+=2000.0*(1+(double)(shi)*1.0/(double)(shi+kong));
kong--;
qlen--;
printf("是空弹\n");
Know=0;
}else{
Yourmoney+=5000.0*(1+(double)(kong)*1.0/(double)(shi+kong));
shi--;
T++;
qlen--;
Other-=Hurt;
Hurt=1;
printf("是实弹\n");
Know=0;
Sleep(500);
IsOver();
if(shoukaoemo){
printf("因为恶魔使用了手铐,所以可以再来一次\n");
T--;
Sleep(500);
shoukaoemo=0;
}
}
}
void Timeother(){
printf("你的生命:%d/6\n恶魔生命:%d/6\n",Your,Other);
printf("剩余实弹数:%d 剩余空弹数:%d\n",shi,kong);
printf("你现在拥有的道具:\n");
for(int i=0;i<=4;i++){
cout<<daojuname[i];
printf("%d",daoju[i]);
printf("个");
if(i!=4){
printf(",");
}
}
printf("\n");
printf("恶魔现在拥有的道具:\n");
for(int i=0;i<=4;i++){
cout<<daojuname[i];
printf("%d",daoju1[i]);
printf("个");
if(i!=4){
printf(",");
}
}
printf("\n");
printf("现在是恶魔的回合\n");
Sleep(1500);
if(Other!=6){
if(daoju1[3]){
daoju1[3]--;
daojulen1--;
printf("恶魔使用了烟\n");
printf("恶魔回复了一点生命\n");
Other++;
Yourmoney+=500.0;
Sleep(1145);
system("cls");
return ;
}
}
if(Know==0&&kong==0){
Know=1;
}
if(Know==0){
if(abs(shi-kong)<2&&kong!=0){
if(daoju1[0]){
daoju1[0]--;
daojulen1--;
printf("恶魔使用了放大镜\n");
wait();
printf("\n恶魔看到了");
if(q[qlen]==1){
printf("实弹");
Yourmoney+=2500.0;
Know=1;
}else{
printf("空弹");
Know=2;
}
Sleep(1145);
system("cls");
return ;
}
}
}else if(Know==1){
if(Hurt==1&&daoju1[2]){
daoju1[2]--;
daojulen1--;
Hurt++;
printf("恶魔使用了小刀\n");
printf("若下一发为实弹则伤害+1");
Yourmoney+=500.0;
Sleep(1145);
system("cls");
return ;
}else{
if(shi>=kong+1&&daoju1[1]&&shoukaoemo!=1){
daoju1[1]--;
daojulen1--;
shoukaoemo=1;
printf("恶魔使用了手铐\n");
printf("恶魔获得了连开两枪的机会\n");
Sleep(1145);
system("cls");
return ;
}
fightyou();
system("cls");
return ;
}
}else{
if(daoju1[4]){
daoju1[4]--;
daojulen1--;
printf("恶魔使用了饮料\n");
wait();
printf("\n");
printf("恶魔退了一发");
if(q[qlen]==2){
printf("空弹");
kong--;
}else{
printf("实弹");
shi--;
}
Know=0;
qlen--;
Sleep(500);
Sleep(1145);
system("cls");
return ;
}else{
fightemo();
Sleep(1145);
system("cls");
return ;
}
}
if(shi>=kong){
fightyou();
}else{
fightemo();
}
Sleep(1145);
system("cls");
}
void Play(){
while(1){
if(shi==0){
build_gun();
T=0;
continue;
}
if(T%2==0){
Timeyou();
}else{
Timeother();
}
}
}
void danrenplay(){
for(int i=1;i<=3;i++){
printf(".");
}
printf("\n");
printf("又来了一位挑战者...\n");
Sleep(1000);
int x;
while(1){
printf("准备好参与恶魔的游戏吗?胜者带走奖金,败者将会在此长眠\n1.好的\n2.没问题\n");
scanf("%d",&x);
if(x==1||x==2){
break;
}
printf("输入不合法\n");
Sleep(1145);
system("cls");
}
while(1){
printf("你清楚我们的规则吗?\n1.清楚\n2.不清楚\n");
scanf("%d",&x);
if(x==1||x==2){
break;
}
printf("输入不合法\n");
Sleep(1145);
system("cls");
}
if(x==1){
}else{
for(int i=1;i<=3;i++){
printf(".");
Sleep(1000);
}
printf("\n");
printf("规则:\n");
printf("你和恶魔都各有6点生命\n") ;
printf("每一回合开始前,你将知道一共有几发实弹,几发空弹,同时双方都将获得4个道具作为补给(上限为8个)\n");
printf("每一回合,你可以选择对自己开枪,对恶魔开枪或者使用道具\n");
printf("如果你对自己开枪,若为空弹,则可以继续行动,否则,停止行动\n");
printf("如果你对恶魔开枪,无论如何,都将停止行动\n");
printf("道具一览:\n");
printf("放大镜:可以知道下一发子弹是空弹还是实弹\n");
printf("手铐:增加一次本回合的行动次数\n");
printf("小刀:若下一发子弹为实弹,则伤害+1\n");
printf("烟:可以回复1点体力\n");
printf("饮料:可以退一发子弹\n");
system("pause");
system("cls");
}
printf("好吧\n");
Sleep(1145);
printf("游戏将要开始了哦\n");
Sleep(1145);
system("cls");
Play();
}
void IsOver_duo(){
if(Your<=0){
printf("玩家B赢了\n玩家B获得了奖金$%.2lf\n",Yourmoney);
system("pause");
exit(0);
}else if(Other<=0){
printf("玩家A赢了\n玩家A获得了奖金$%.2lf\n",Yourmoney);
system("pause");
exit(0);
}
}
void build_gun_duo(){
kong=Rand(1,4);
shi=Rand(1,4);
qlen=0;
printf("%d发实弹,%d发空弹\n",shi,kong);
int a1=kong,a2=shi;
for(int i=1;i<=kong+shi;i++){
// Sleep(50);
int sum=Rand(1,a1+a2);
if(sum<=a1){
a1--;
q[++qlen]=2;
}else{
a2--;
q[++qlen]=1;
}
}
int maxn=min(2,8-daojulen);
printf("玩家A获得了%d个道具:\n",maxn);
daojulen+=maxn;
for(int i=1;i<=maxn;i++){
// Sleep(50);
int kkk=Rand(0,4);
daoju[kkk]++;
cout<<daojuname[kkk];
if(i!=maxn){
printf(",");
}
}
printf("\n");
maxn=min(2,8-daojulen1);
printf("玩家B获得了%d个道具:\n",maxn);
daojulen1+=maxn;
for(int i=1;i<=maxn;i++){
int kkk=Rand(0,4);
daoju1[kkk]++;
cout<<daojuname[kkk];
if(i!=maxn){
printf(",");
}
}
printf("\n");
system("pause");
system("cls");
}
void Timeyou_duo(){
int x;
while(1){
printf("玩家A的生命:%d/4\n玩家B的生命:%d/4\n",Your,Other);
printf("剩余实弹数:%d 剩余空弹数:%d\n",shi,kong);
printf("玩家A现在拥有的道具:\n");
for(int i=0;i<=4;i++){
cout<<daojuname[i];
printf("%d",daoju[i]);
printf("个");
if(i!=4){
printf(",");
}
}
printf("\n");
printf("玩家B现在拥有的道具:\n");
for(int i=0;i<=4;i++){
cout<<daojuname[i];
printf("%d",daoju1[i]);
printf("个");
if(i!=4){
printf(",");
}
}
printf("\n");
printf("现在是玩家A的回合\n");
printf("玩家A要\n1.向玩家B开枪\n2.向自己开枪\n");
for(int i=0;i<=4;i++){
printf("%d.使用",i+3);
cout<<daojuname[i]<<'\n';
}
scanf("%d",&x);
if(1<=x&&x<=7){
break;
}
printf("输入不合法\n");
Sleep(1145);
system("cls");
}
if(x==1){
printf("玩家A决定向玩家B开枪");
T++;
wait();
if(q[qlen]==2){
Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(shi)*1.0/(double)(shi+kong)));
kong--;
qlen--;
Hurt=1;
printf("是空弹\n");
if(shoukao_you==1){
shoukao_you=0;
printf("因为玩家A使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
}else{
Yourmoney+=(double)(5000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
shi--;
qlen--;
Other-=Hurt;
Hurt=1;
printf("是实弹\n");
Sleep(500);
IsOver_duo();
if(shoukao_you==1){
shoukao_you=0;
Yourmoney+=1000.0;
printf("因为玩家A使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
}
}else if(x==2){
printf("玩家A决定向自己开枪");
wait();
if(q[qlen]==2){
Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
kong--;
qlen--;
Hurt=1;
printf("是空弹\n");
}else{
Yourmoney+=5000.0*(1+(double)(shi)*1.0/(double)(shi+kong));
T++;
shi--;
qlen--;
Your-=Hurt;
Hurt=1;
printf("是实弹\n");
Sleep(500);
IsOver_duo();
if(shoukao_you==1){
shoukao_you=0;
printf("因为玩家A使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
}
}else if(x==3){//{"放大镜","手铐","小刀","烟","饮料"};
if(daoju[0]){
daoju[0]--;
daojulen--;
printf("玩家A使用了放大镜\n");
wait();
printf("\n玩家A看到了");
if(q[qlen]==1){
printf("实弹\n");
Yourmoney+=2500.0;
}else{
printf("空弹\n");
}
Sleep(500);
printf("\n");
}else{
printf("玩家A现在没有放大镜\n");
Sleep(1145);
system("cls");
}
}else if(x==4){
if(daoju[1]){
if(!shoukao_you){
daoju[1]--;
daojulen--;
printf("玩家A使用了手铐\n");
printf("玩家A获得了连开两枪的机会\n");
shoukao_you=1;
}else{
printf("玩家A已经用过手铐了\n");
}
Sleep(1145);
system("cls");
}else{
printf("玩家A现在没有手铐\n");
Sleep(1145);
system("cls");
}
}else if(x==5){
if(daoju[2]){
if(Hurt==1){
daoju[2]--;
daojulen--;
printf("玩家A使用了小刀\n");
printf("若下一发为实弹则伤害+1\n");
Yourmoney+=500.0;
Hurt=2;
}else{
printf("玩家A已经用过小刀了\n");
}
Sleep(1145);
system("cls");
}else{
printf("玩家A现在没有小刀\n");
Sleep(1145);
system("cls");
}
}else if(x==6){
if(daoju[3]){
if(Your^4){
daoju[3]--;
daojulen--;
printf("玩家A使用了烟\n");
printf("玩家A回复了一点生命\n");
Yourmoney+=500.0;
Your++;
}else{
printf("玩家A现在不需要烟\n");
}
Sleep(1145);
}else{
printf("玩家A现在没有烟\n");
Sleep(1145);
system("cls");
}
}else{
if(daoju[4]){
daoju[4]--;
daojulen--;
printf("玩家A使用了饮料\n");
wait();
printf("\n");
printf("玩家A退了一发");
if(q[qlen]==2){
printf("空弹");
kong--;
}else{
printf("实弹");
Yourmoney+=500.0;
shi--;
}
qlen--;
Sleep(500);
}else{
printf("玩家A现在没有饮料\n");
Sleep(1145);
system("cls");
}
}
Sleep(1000);
system("cls");
}
void Timeother_duo(){
int x;
while(1){
printf("玩家A的生命:%d/4\n玩家B的生命:%d/4\n",Your,Other);
printf("剩余实弹数:%d 剩余空弹数:%d\n",shi,kong);
printf("玩家A现在拥有的道具:\n");
for(int i=0;i<=4;i++){
cout<<daojuname[i];
printf("%d",daoju[i]);
printf("个");
if(i!=4){
printf(",");
}
}
printf("\n");
printf("玩家B现在拥有的道具:\n");
for(int i=0;i<=4;i++){
cout<<daojuname[i];
printf("%d",daoju1[i]);
printf("个");
if(i!=4){
printf(",");
}
}
printf("\n");
printf("现在是玩家B的回合\n");
printf("玩家B要\n1.向玩家A开枪\n2.向自己开枪\n");
for(int i=0;i<=4;i++){
printf("%d.使用",i+3);
cout<<daojuname[i]<<'\n';
}
scanf("%d",&x);
if(1<=x&&x<=7){
break;
}
printf("输入不合法\n");
Sleep(1145);
system("cls");
}
if(x==1){
printf("玩家B决定向玩家A开枪");
T++;
wait();
if(q[qlen]==2){
Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(shi)*1.0/(double)(shi+kong)));
kong--;
qlen--;
Hurt=1;
printf("是空弹\n");
if(shoukaoemo==1){
shoukaoemo=0;
printf("因为玩家B使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
}else{
Yourmoney+=(double)(5000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
shi--;
qlen--;
Your-=Hurt;
Hurt=1;
printf("是实弹\n");
Sleep(500);
IsOver_duo();
if(shoukaoemo==1){
shoukaoemo=0;
Yourmoney+=1000.0;
printf("因为玩家B使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
}
}else if(x==2){
printf("玩家B决定向自己开枪");
wait();
if(q[qlen]==2){
Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
kong--;
qlen--;
Hurt=1;
printf("是空弹\n");
}else{
Yourmoney+=5000.0*(1+(double)(shi)*1.0/(double)(shi+kong));
T++;
shi--;
qlen--;
Other-=Hurt;
Hurt=1;
printf("是实弹\n");
Sleep(500);
IsOver_duo();
if(shoukao_you==1){
shoukao_you=0;
printf("因为玩家B使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
}
}else if(x==3){
if(daoju1[0]){
daoju1[0]--;
daojulen1--;
printf("玩家B使用了放大镜\n");
wait();
printf("\n玩家B看到了");
if(q[qlen]==1){
printf("实弹\n");
Yourmoney+=2500.0;
}else{
printf("空弹\n");
}
Sleep(500);
printf("\n");
}else{
printf("玩家B现在没有放大镜\n");
Sleep(1145);
system("cls");
}
}else if(x==4){
if(daoju1[1]){
if(!shoukaoemo){
daoju1[1]--;
daojulen1--;
printf("玩家B使用了手铐\n");
printf("玩家B获得了连开两枪的机会\n");
shoukaoemo=1;
}else{
printf("玩家B已经用过手铐了\n");
}
Sleep(1145);
system("cls");
}else{
printf("玩家B现在没有手铐\n");
Sleep(1145);
system("cls");
}
}else if(x==5){
if(daoju1[2]){
if(Hurt==1){
daoju1[2]--;
daojulen1--;
printf("玩家B使用了小刀\n");
printf("若下一发为实弹则伤害+1\n");
Yourmoney+=500.0;
Hurt=2;
}else{
printf("玩家B已经用过小刀了\n");
}
Sleep(1145);
system("cls");
}else{
printf("玩家B现在没有小刀\n");
Sleep(1145);
system("cls");
}
}else if(x==6){
if(daoju1[3]){
if(Other^4){
daoju1[3]--;
daojulen1--;
printf("玩家B使用了烟\n");
printf("玩家B回复了一点生命\n");
Yourmoney+=500.0;
Other++;
}else{
printf("玩家B现在不需要烟\n");
}
Sleep(1145);
}else{
printf("玩家B现在没有烟\n");
Sleep(1145);
system("cls");
}
}else{
if(daoju1[4]){
daoju1[4]--;
daojulen1--;
printf("玩家B使用了饮料\n");
wait();
printf("\n");
printf("玩家B退了一发");
if(q[qlen]==2){
printf("空弹");
kong--;
}else{
printf("实弹");
Yourmoney+=500.0;
shi--;
}
qlen--;
Sleep(500);
}else{
printf("玩家B现在没有饮料\n");
Sleep(1145);
system("cls");
}
}
Sleep(1000);
system("cls");
}
int asdasd;
void duorenplay(){
while(1){
if(shi==0){
build_gun_duo();
T=asdasd;
asdasd++;
continue;
}
if(T%2==0){
Timeyou_duo();
}else{
Timeother_duo();
}
}
}
int main()
{
cout<<" 游戏机 " <<endl;
cout<<"1:恶魔轮盘赌 game"<<endl;
cout<<"2:模拟世界 game"<<endl;
cout<<"3:数字老虎机 game"<<endl;
cout<<"4:骗子酒馆 game"<<endl;
cout<<"5:抛硬币 game"<<endl;
cout<<"6:冒险 game"<<endl;
while(1)
{
cin>>n;
if(n==1)
{
cout<<"恶魔轮盘";
srand(time(0));
int x;
while(1){
printf("请选择你想要的模式:\n1.单人\n2.双人(此模式中,生命值为4,道具补给为2)\n");
scanf("%d",&x);
if(x==1||x==2){
break;
}
printf("输入不合法\n");
Sleep(1145);
system("cls");
}
system("cls");
if(x==1){
danrenplay();
}else{
Your=Other=4;
duorenplay();
}
}
if(n==2)
{
srand(time(0));
cout<<" 欢迎游玩该游戏"<<endl<<endl;
cout<<" 游戏背景:"<<endl;
cout<<" 一天,你正在机房里摸鱼,忽然,一"<<endl;
cout<<" 阵白光闪过,令你睁不开眼。在白光消失"<<endl;
cout<<" 后,你惊讶的发现,你穿越成了游戏世界"<<endl;
cout<<" 的一个小白,你该怎样活下去并称霸这个"<<endl;
cout<<" 世界呢"<<endl<<endl;
cout<<" 按任意键 开始游戏"<<endl;
char x=_getch();
while(1){
common();
choose();
}
}
if(n==3)
{
srand((unsigned)time(NULL));
int target = rand() % 100 + 1;
int guess, attempts = 5;
cout << "=== 猜数字游戏 ===" << endl;
cout << "目标数字在 1-100 之间,你有 " << attempts << " 次机会!\n";
while (attempts-- > 0) {
cout << "输入你的猜测:";
cin >> guess;
if (guess == target) {
cout << "恭喜!猜中了!\n";
return 0;
} else if (guess < target) {
cout << "太小了!剩余次数:" << attempts << endl;
} else {
cout << "太大了!剩余次数:" << attempts << endl;
}
}
cout << "游戏结束!正确数字是:" << target << endl;
return 0;
}
if(n==4) {system("cls"); // 清屏
srand(time(0));
cout << "=== 欢迎来到骗子酒馆 ===" << endl;
cout << "这里充满机会与欺诈,小心你的选择!" << endl;
tavernMenu();
}
if(n==5) {system("cls"); // 清屏
std::srand(std::time(0));
int coin = std::rand() % 2;
char guess;
std::cout << "欢迎来到抛硬币游戏!请猜测是正面(H)还是反面(T): ";
std::cin >> guess;
std::cout << "硬币结果是: ";
if (coin == 0) {
std::cout << "正面" << std::endl;
} else {
std::cout << "反面" << std::endl;
}
if ((coin == 0 && guess == 'H') || (coin == 1 && guess == 'T')) {
std::cout << "恭喜你,猜对了!" << std::endl;
} else {
std::cout << "很遗憾,猜错了。" << std::endl;
}
return 0;
}
if(n==6)
{system("cls"); // 清屏
cout<<" 冒险"<<endl;
srand(time(0));
// 单人模式添加战斗逻辑
int playerHealth = 150;
int playerMana = 100;
bool hasSword = false;
std::string choice;
std::cout << "你身处一片神秘森林,面前有两条路,一条向左,一条向右。你选择哪条路?(左/右): ";
std::cin >> choice;
if (choice == "左") {
std::cout << "你来到了一个古老的城堡,城堡大门敞开着,你要进去吗?(进/不进): ";
std::cin >> choice;
if (choice == "进") {
if (std::rand() % 2 == 0) {
std::cout << "你触发了陷阱,损失20点生命值。" << std::endl;
playerHealth -= 20;
if (playerHealth <= 0) {
std::cout << "你因伤势过重死亡,游戏结束。" << std::endl;
return 0;
}
}
std::cout << "你在城堡里发现了一把剑,你获得了剑。" << std::endl;
hasSword = true;
std::cout << "继续深入城堡,你发现了宝藏,但同时出现了一个守卫。你要战斗还是逃跑?(战斗/逃跑): ";
std::cin >> choice;
if (choice == "战斗") {
battle(playerHealth, playerMana, hasSword);
if (playerHealth > 0) {
std::cout << "你成功获得了宝藏,你赢了!" << std::endl;
}
} else {
std::cout << "你成功逃跑,但宝藏没了,游戏结束。" << std::endl;
}
} else {
std::cout << "你错过了宝藏,离开了城堡,游戏结束。" << std::endl;
}
} else if (choice == "右") {
std::cout << "你遇到了一只凶猛的野兽,你要战斗还是逃跑?(战斗/逃跑): ";
std::cin >> choice;
if (choice == "战斗") {
battle(playerHealth, playerMana, hasSword);
if (playerHealth > 0) {
std::cout << "你打败了野兽,继续前进。" << std::endl;
std::cout << "你发现了一个隐藏的洞穴,要进去看看吗?(进/不进): ";
std::cin >> choice;
if (choice == "进") {
std::cout << "你在洞穴里发现了宝藏,你赢了!" << std::endl;
} else {
std::cout << "你离开了洞穴,游戏结束。" << std::endl;
}
}
} else {
if (std::rand() % 2 == 0) {
std::cout << "你成功逃跑,但是迷失了方向,游戏结束。" << std::endl;
} else {
std::cout << "你逃跑时被野兽追上,受了重伤,损失30点生命值,游戏结束。" << std::endl;
}
}
} else {
std::cout << "无效的选择,游戏结束。" << std::endl;
}
}
return 0;
}
}
注意,本代码是原创,请勿抄袭,违者必究