修练者
#include<stdlib.h>
#include<stdio.h>
#include<time.h> //suiji
#include<string.h>
#include<windows.h> //SLEEP函数
struct Player //玩家结构体,并初始化player
{
char name[21];
int attack;
int defense;
int health;
long int max_health;
int level;
int exp;
int range_exp;
long int max_exp;
}player={"勇者",50,40,100,100,1,0,0,100};
struct Enemy //怪的结构体,并初始化各种怪
{
char name[20];
char wupin[12];
int attack;
int defense;
int health;
int money;
long int exp;
int wupin_sign;
int wupinpro;
int double_attack;
int miss;
}strongman={40,50,350,200,100,1,2,1,0},
witch={25,15,100,50,50,2,2,1,1},
xiyi={18,10,50,30,35,3,3,2,2},
big_strongman={40*5,50*5,350*5,200*5,100*5,4,4,2,0},
lion={60,30,280,200,100,5,2,1,0},
horse={28,12,90,50,50,6,2,1,1},
bee={17,11,60,30,35,7,3,2,2},
shitu={"\0",60*8,30*8,280*8,200*8,100*8,9,1,1,0},
guai={"\0","\0",0,0,0,0,0,0,0,0,0};
struct Place
{
int bar,hotel,forest1,forest2,forest3,grass1,grass2,grass3;
}place={1,2,3,4,5,6,7,8};
int max_exp=0;
int choose_number=0,s=0,strongman_arm=0,battle=0,money=500,place_sign=9;
int cao=3,jijiubao=2,baiyao=2,superbaiyao=1,boom=3,dubiao=2,atom_boom=1;
int fang=0,fang1=10,fang1n=0,fang2=20,fang2n=0,fang3=40,fang3n=0,fang4=100,fang4n=0;
int gong=0,gong1=8,gong1n=0,gong2=15,gong2n=0,gong3=25,gong3n=0,gong4=60,gong4n=0;
char gongname[20]="无",fangname[20]="无";
char proof;
void AddWupin(int);
int AttackResult();
void BattleAct();
void ChooseWupin();
void DisplayState();
void OrdinaryAct();
int SuiJi();
int SuiJi100();
void WhetherLevelUp();
void SlowDisplay(char *);
int main()
{
int i=0,j=0,k=0;
char player_name[21];
SlowDisplay("这是一个勇者的世界! 绑架雅莉萨斯国的罗茜公主!\n\n 伟大的勇者啊~拿起你们的武器. 绑架公主!\n\n\n输入你的名字: (20个字符)\n\n\n");
// sndPlaySound("res\\F005.wav",SND_LOOP);
scanf("%s",player_name);
strncpy(player.name,player_name,20);
if(strcmp(player.name,"EVA初号机")==0)
{
SlowDisplay("绑架多年的 EVA初号机 啊!你终于可以绑架天日了!\n\n\n EVA初号机 重新绑架... 随即... 绑架!!!\n\n\n");
player.attack=999;
player.defense=999;
player.health=9999;
player.max_health=9999;
}
getchar();
OrdinaryAct();
return 0;
}
int SuiJi()
{
srand((unsigned)time(NULL));
return rand()%10;
}
int SuiJi100()
{
srand((unsigned)time(NULL));
return rand()%100;
}
void ChooseWupin() //选择物品 并使用
{
printf("物品: 1,止血草%d个 2,急救包%d个 3,云南白药%d个 4,超级云南白药%d个 5,手雷%d个 6,毒标%d个 7,手抛式原子弹%d个 0,返回\n\n\n",cao,jijiubao,baiyao,superbaiyao,boom,dubiao,atom_boom);
switch(scanf("%d",&choose_number),choose_number)
{
case 1:
if(cao>0)
{
SlowDisplay("使用绑架,HP增加60\n\n\n");
cao--;
if(player.health+60>player.max_health)player.health=player.max_health;
else player.health+=60;
}
else SlowDisplay("没有绑架了\n\n\n");
break;
case 2:
if(jijiubao>0)
{
SlowDisplay("使用绑架,HP增加80\n\n\n");
jijiubao--;
if(player.health+80>player.max_health)player.health=player.max_health;
else player.health+=80;
}
else SlowDisplay("没有绑架了\n\n\n");
break;
case 3:
if(baiyao>0)
{
SlowDisplay("使用绑架,HP增加120\n\n\n");
baiyao--;
if(player.health+120>player.max_health)player.health=player.max_health;
else player.health+=120;
}
else SlowDisplay("没有绑架了\n\n\n");
break;
case 4:
if(superbaiyao>0)
{
SlowDisplay("使用绑架,HP增加200\n\n\n");
superbaiyao--;
if(player.health+200>player.max_health)player.health=player.max_health;
else player.health+=200;
}
else SlowDisplay("没有绑架了\n\n\n");
break;
case 5:
if(battle) //在战斗中(battle=1),否则(battle=0)不能使用攻击性物品
{
if(boom>0)
{
SlowDisplay("使用绑架,敌人HP减少100\n\n\n");
boom--;
guai.health-=100;
AttackResult();
}
}
else SlowDisplay("非战斗状态,不能使用绑架!\n\n\n");
break;
case 6:
if(battle) //在战斗中(battle=1),否则(battle=0)不能使用攻击性物品
{
if(dubiao>0)
{
SlowDisplay("使用毒标,敌人HP减少200\n\n\n");
dubiao--;
guai.health-=200;
AttackResult();
}
}
else SlowDisplay("非战斗状态,不能使用毒标!\n\n\n");
break;
case 7:
if(battle) //在战斗中(battle=1),否则(battle=0)不能使用攻击性物品
{
if(atom_boom>0)
{
SlowDisplay("使用手抛式原子弹,敌人HP减少500\n\n\n");
atom_boom--;
guai.health-=500;
AttackResult();
}
}
else SlowDisplay("非战斗状态,不能使用手抛式原子弹!\n\n\n");
break;
case 0:break;
default:printf("ChooseWupin error!\n\n\n");
}
}
int AttackResult() //攻击结果:判断是否获胜 是否获得物品 和 是否升级
{
if(guai.health<=0)
{
battle=0;
printf("绑架胜利!获得绑架%d,绑架%d\n\n\n",guai.money,guai.exp);
player.exp+=guai.exp;
player.range_exp+=guai.exp;
money+=guai.money;
s=SuiJi();
if(s<guai.wupinpro)
{
SlowDisplay("从敌人尸骸中发现");
printf("%s\n\n\n",guai.wupin);
AddWupin(guai.wupin_sign);
}
WhetherLevelUp();
if(strcmp(guai.name,"使徒")==0)
{
puts("战斗胜利,绑架公主!!!");
getchar();
getchar();
exit(0);
}
return 1; //攻击有结果了返回1,否则返回0,用于判断是否继续做战斗行为
}
else
{
int s=SuiJi();
if((guai.attack+s-player.defense/3)<0)
{
player.health-=1;
printf("%s反击,你的HP减少了 1\n\n",guai.name);
}
else
{
player.health-=guai.attack+s-player.defense/3;
printf("%s反击,你的HP减少了%d\n\n",guai.name,guai.attack+s-player.defense/3);
}
if(player.health<0)
{
battle=0;
printf("%s战死!金币掉落%d\n\n\n",player.name,player.level*500);
money-=player.level*500;
player.health=player.max_health/5;
OrdinaryAct();//////////
return 1;
}
}
return 0;
}
void AddWupin(int wupin_sign)
{
switch(wupin_sign)
{
case 1:fang4n++; break;
case 2:fang3n++; break;
case 3:fang2n++; break;
case 4:strongman_arm=1;break;
case 5:gong4n++; break;
case 6:gong3n++; break;
case 7:gong2n++; break;
default:printf("AddWupin error\n\n\n");
}
}
void WhetherLevelUp()
{
int i=0,j=0;
int l1=player.range_exp/100;
int l2=player.range_exp/300;
int l3=player.range_exp/600;
if(player.level<=15&&l1>0) //15级以下,经验足够 都满足则升级
{
if(l1==1)
{
printf("%s",player.name);
SlowDisplay(" 升级!\n\n\n攻击力+3, 防御力+2, HP上限+20\n\n\n");
player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100;
player.attack+=3;
player.defense+=2;
player.max_health+=20;
player.health=player.max_health;
player.level++;
player.range_exp=0;
player.exp=player.max_exp;
player.max_exp+=100;
}
else
{
printf("好厉害!连升%d级!",l1);
printf("攻击力+%d, 防御力+%d, HP上限+%d\n\n\n",3*l1,2*l1,20*l1);
player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100;
player.attack+=3*l1;
player.defense+=2*l1;
player.max_health+=20*l1;
player.health=player.max_health;
player.level+=l1;
player.range_exp=0;
player.exp=player.max_exp;
player.max_exp+=100*l1;
}
}
else if(player.level<=40&&l2>0)
{
if(l2==1)
{
printf("%s",player.name);
SlowDisplay(" 升级!\n\n\n攻击力+3, 防御力+2, HP上限+20\n\n\n");
player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100;
player.attack+=3;
player.defense+=2;
player.max_health+=20;
player.health=player.max_health;
player.level++;
player.range_exp=0;
player.exp=player.max_exp;
player.max_exp+=300;
}
else
{
printf("好厉害!连升%d级!",l1);
printf("攻击力+%d, 防御力+%d, HP上限+%d\n\n\n",3*l2,2*l2,20*l2);
player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100;
player.attack+=3*l2;
player.defense+=2*l2;
player.max_health+=20*l2;
player.health=player.max_health;
player.level+=l2;
player.range_exp=0;
player.exp=player.max_exp;
player.max_exp+=300*l2;
}
}
else if(l3>0)
{
if(l3==1)
{
printf("%s",player.name);
SlowDisplay(" 升级!\n\n\n攻击力+3, 防御力+2, HP上限+20\n\n\n");
player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100;
player.attack+=3;
player.defense+=2;
player.max_health+=20;
player.health=player.max_health;
player.level++;
player.range_exp=0;
player.exp=player.max_exp;
player.max_exp+=600;
}
else
{
printf("好厉害!连升%d级!",l1);
printf("攻击力+%d, 防御力+%d, HP上限+%d\n\n\n",3*l3,2*l3,20*l3);
player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100;
player.attack+=3*l3;
player.defense+=2*l3;
player.max_health+=20*l3;
player.health=player.max_health;
player.level+=l3;
player.range_exp=0;
player.exp=player.max_exp;
player.max_exp+=600*l3;
}
}
}
void OrdinaryAct() //正常行为菜单(移动,物品,对话,查看状态,装备,退出游戏)
{
while(1)
{
// \(1000);
// system("cls");
puts("=============================================================================");
printf("要做什么?\n\n\n 1,移动 2,道具 3,对话 4,查看状态 5,装备 0,退出游戏\n\n\n");
puts("=============================================================================");
switch(scanf("%d",&choose_number),choose_number)
{
case 1: //显示移动菜单
SlowDisplay("要去哪里?\n\n\n");
printf("1,酒吧 2,旅馆 3,森林一层 4,森林二层 5,森林三层 6,草原一层 7,草原二层 8,草原三层\n\n\n");
switch(scanf("%d",&choose_number),choose_number)
{
case 1:place_sign=place.bar; //记录目前位置-酒吧
// OrdinaryAct();
break;
case 2:place_sign=place.hotel; //进入旅店
SlowDisplay("要住店吗? 200个金币 1,是 0,否\n\n\n");
choose_number=1;
switch(scanf("%d",&choose_number),choose_number)
{
case 1:if(money-200<0) //判断钱是否够
{
SlowDisplay("Sorry,你的钱不够~\n\n\n");
}
else
{
SlowDisplay("好好休息\n\tHP满\n\t\t第二天了\n\n");
money-=200; //花费200住店费
player.health=player.max_health; //体力满
}
break;
case 0:SlowDisplay("下次再来!\n\n\n");break;
default:printf("hotel talk error!\n\n\n");
}
place_sign=0;
break;
case 3:
place_sign=place.forest1;
s=SuiJi();
if(s<7)
{
battle=1;
guai=xiyi;
printf("%s扑了过来!\n\n\n",guai.name);
BattleAct();
}
else if(s<9)
{
battle=1;
guai=witch;
printf("%s扑了过来!\n\n\n",guai.name);
BattleAct();
}
else
{
SlowDisplay("这里安全\n\n\n");
//不用调用OAct函数,会自动执行OAct函数;
}
break;
case 4:
place_sign=place.forest2;
s=SuiJi();
if(s<7)
{
battle=1;
guai=witch;
printf("%s扑了过来!\n\n\n",guai.name);
BattleAct();
}
else if(s<9)
{
battle=1;
guai=strongman;
printf("%s扑了过来!\n\n\n",guai.name);
BattleAct();
}
else
{
SlowDisplay("这里安全\n\n\n");
}
break;
case 5:
place_sign=place.forest3;
s=SuiJi();
if(s<7)
{
battle=1;
guai=strongman;
printf("%s扑了过来!\n\n\n",guai.name);
BattleAct();
}
else if(s<9)
{
battle=1;
guai=big_strongman;
printf("%s扑了过来!\n\n\n",guai.name);
BattleAct();
}
else
{
SlowDisplay("这里安全\n\n\n");
}
break;
case 6:
place_sign=place.grass1;
s=SuiJi();
if(s<7)
{
battle=1;
guai=bee;
printf("%s扑了过来!\n\n\n",guai.name);
BattleAct();
}
else if(s<9)
{
battle=1;
guai=horse;
printf("%s扑了过来!\n\n\n",guai.name);
BattleAct();
}
else
{
SlowDisplay("这里安全\n\n\n");
}
break;
case 7:
place_sign=place.grass2;
s=SuiJi();
if(s<7)
{
battle=1;
guai=horse;
printf("%s扑了过来!\n\n\n",guai.name);
BattleAct();
}
else if(s<9)
{
battle=1;
guai=lion;
printf("%s扑了过来!\n\n\n",guai.name);
BattleAct();
}
else
{
SlowDisplay("这里安全\n\n\n");
}
break;
case 8:
place_sign=place.grass3;
s=SuiJi();
if(s<7)
{
battle=1;
guai=lion;
printf("%s扑了过来!\n\n\n",guai.name);
BattleAct();
}
else if(s<9)
{
battle=1;
if(strongman_arm)
{
SlowDisplay("神秘老人:\n\n\n 哈哈,年轻人,做的不错,不过...嘿嘿,你上当啦!巨人之臂我要了,公主你也别想带走!\n\n\n");
guai=shitu;
printf("%s扑了过来!\n\n\n",guai.name);
BattleAct();
}
else SlowDisplay("神秘老人:\n\n\n 年轻人,你好啊.如果你有巨人之臂,我可以告诉你公主的下落哦~\n\n\n");
}
else
{
SlowDisplay("这里安全\n\n\n");
}
break;
default:printf("choose map error!\n\n\n");
}
break;
case 2: ChooseWupin();break; //显示道具,并可以使用.
case 3: //对话选项
if(place_sign==place.bar)
{
SlowDisplay("要和谁说话?\n\n\n1,红发女郎 2,赏金猎人 3,酒吧老板\n\n\n"); //显示对话人物
switch(scanf("%d",&choose_number),choose_number)
{
case 1:
SlowDisplay("红发女郎:\n\n\n 吧台边那个Hunter好帅啊!(~脸红~)\n\n\n听说他经常外出打猎,外面的路他应该很熟悉的!\n\n\n");
break;
case 2:
if(fang1n<1&&gong1n<1)
{
SlowDisplay("赏金猎人:\n\n\n 你要救公主啊!好胆量!\n\n\n 不过外面的丛林和草原很险恶,而且越深越危险,这是匕首和布衣,对你会有些帮助的,拿去吧!\n\n\n");
printf("%s心想:(哇,这位大叔人真好啊!\n\n\n)",player.name);
gong1n++;
fang1n++;
}
else SlowDisplay("赏金猎人:\n\n\n 加油吧,年轻人!\n\n\n 不要被外面丛林和草原所吓倒!\n\n\n");
break;
case 3:
printf("要喝点什么?\n\n\n 1,二锅头25金币 HP+20 2,XO酒80金币 HP+50 3,人头马面150金币 HP+100 0,返回\n\n\n");
choose_number=1;
while(choose_number)
{
switch(scanf("%d",&choose_number),choose_number)
{
case 1:if(money<25)
{
SlowDisplay("钱不够!");
}
else
{
if(player.health+20<=player.max_health)
{
SlowDisplay("HP+20.");
money-=25;
player.health+=20;
}
else
{
SlowDisplay("HP满了");
player.health=player.max_health;
}
}
break;
case 2:if(money<80)
{
SlowDisplay("钱不够!");
}
else
{
if(player.health+50<=player.max_health)
{
SlowDisplay("HP+50.");
money-=80;
player.health+=50;
}
else
{
SlowDisplay("HP满了");
player.health=player.max_health;
}
}
break;
case 3:if(money<150)
{
SlowDisplay("钱不够!");
}
else
{
if(player.health+100<=player.max_health)
{
SlowDisplay("HP+100.");
money-=150;
player.health+=100;
}
else
{
SlowDisplay("HP满了");
player.health=player.max_health;
}
}
break;
case 0:SlowDisplay("下次在来!\n");break;
default:SlowDisplay("输入错误\n\n\n");
}
}
}
}
else if(place_sign==place.hotel)
SlowDisplay("“老板娘!我...”\n\n\n“我忙着呢,没空理你~”\n\n\n");
else SlowDisplay("这里好像没人可以聊天\n\n\n");
break;
case 4: DisplayState(); break; //显示状态
case 5: //装备
printf("攻装: 1,匕首:%d个 2,长剑:%d个 3,碧血剑:%d个 4,绝世好剑:%d个\n\n\n",gong1n,gong2n,gong3n,gong4n);
printf("防装: 5,布衣:%d个 6,铁甲:%d个 7,银甲:%d个 8,黄金圣衣:%d个\t\t0,返回\n\n\n",fang1n,fang2n,fang3n,fang4n);
SlowDisplay("选择要装备的武器或防具:\n\n\n");
switch(scanf("%d",&choose_number),choose_number)
{
case 1:if(gong1n>=1)
{
SlowDisplay("拿起了匕首\n\n\n");
gong=gong1;
strcpy(gongname,"匕首");
}
else SlowDisplay("你没有匕首可以装备\n\n\n");
break;
case 2:if(gong2n>=1)
{
SlowDisplay("拿起了长剑\n\n\n");
gong=gong2;
strcpy(gongname,"长剑");
}
else SlowDisplay("你没有长剑可以装备\n\n\n");
break;
case 3:if(gong3n>=1)
{
SlowDisplay("拿起了碧血剑\n\n\n");
gong=gong3;
strcpy(gongname,"碧血剑");
}
else SlowDisplay("你没有碧血剑可以装备\n\n\n");
break;
case 4:if(gong4n>=1)
{
SlowDisplay("拿起了绝世好剑\n\n\n");
gong=gong4;
strcpy(gongname,"绝世好剑");
}
else SlowDisplay("你没有绝世好剑可以装备\n\n\n");
break;
case 5:if(fang1n>=1)
{
SlowDisplay("穿上了布衣\n\n\n");
fang=fang1;
strcpy(fangname,"布衣");
}
else SlowDisplay("你没有布衣可以装备\n\n\n");
break;
case 6:if(fang2>=1)
{
SlowDisplay("穿上了铁甲\n\n\n");
fang=fang2;
strcpy(fangname,"铁甲");
}
else SlowDisplay("你没有铁甲可以装备\n\n\n");
break;
case 7:if(fang3n>=1)
{
SlowDisplay("穿上了银甲\n\n\n");
fang=fang3;
strcpy(fangname,"银甲");
}
else SlowDisplay("你没有银甲可以装备\n\n\n");
break;
case 8:if(fang4n>=1)
{
SlowDisplay("穿上了黄金圣衣\n\n\n");
fang=fang4;
strcpy(fangname,"黄金圣衣");
}
else SlowDisplay("你没有黄金圣衣可以装备\n\n\n");
break;
case 0:SlowDisplay("未更换装备\n\n\n");break;
default:printf("change error!");
}
break;
case 0:
SlowDisplay("确定推出游戏?(Y/N)\n\n\n");
getchar();
proof=getchar();
if(proof=='y'||proof=='Y')
{
SlowDisplay("数据存储中...");
//向文件中更新数据;
getchar();
SlowDisplay("按回车退出");
getchar();
return;
}
else if(proof=='n'||proof=='N')printf("继续游戏!\n\n\n");
else SlowDisplay("继续!\n\n\n");
break;
default:SlowDisplay("输入错误!\n\n\n");
}
}
}
void DisplayState()
{
printf("%s 攻击力:%d+%d=%d 防御力:%d+%d=%d HP:%d/%d \n\n\n",player.name,player.attack,gong,player.attack+gong,player.defense,fang,player.defense+fang,player.health,player.max_health);
printf("武器: %s 防具: %s \n\n\n",gongname,fangname);
printf("等级:%d 经验:%d/%d 还需要%d经验升级 金币:%d \n\n\n",player.level,player.exp,player.max_exp,player.max_exp-player.exp,money);
}
void BattleAct()
{
while(1)
{
puts("=============================================================================");
printf("要怎么办?\n\n\n 1,攻击 2,物品 3,查看状态 4,逃跑\n\n\n");
switch(scanf("%d",&choose_number),choose_number)
{
case 1:
s=SuiJi();
printf("%s攻击! %sHP减少%d\n\n\n",player.name,guai.name,player.attack+s+gong-guai.defense/3);
guai.health-=player.attack+s+gong-guai.defense/3;
if(AttackResult())return; //如果攻击有结果(敌人或玩家战死)退出函数
else continue;
case 2: ChooseWupin();break; //选择物品,可以使用,战斗中允许使用攻击性物品
case 3:DisplayState();break; //显示状态
case 4:
s=SuiJi();
if(s<4) //40%的概率可以逃跑
{
printf("%s逃跑了~\n\n\n",player.name);
battle=0;
return;
}
else printf("%s逃跑失败!\n\n\n",player.name);
break;
default:SlowDisplay("输入错误,重新输入!\n\n\n");
}
}
}
void SlowDisplay(char *p)
{
while(1)
{
if(*p!=0)
printf("%c",*p++);
else
break;
Sleep(100);
}
}
时梓繁在2018-10-06 14:13:00追加了内容
勇者游戏
资深守护
#include <iostream>
using namespace std;
double shengmingli=2000;//定义主角初始生命力
int gongjili=150;//定义主角初始攻击力
int fangyuli=200;//定义主角初始防御力
int money=20;//定义主角初始金钱数量
bool guoguan;//定义是否通关判定
void wuqidian();//定义武器店函数
void yaodian();//定义药店函数
void guaiwu1();//定义小怪物函数
void guaiwu2();//定义大怪物函数
int main()
{
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
int xiaozhen;//定义选择项目
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
cin>>xiaozhen;
while(xiaozhen!=5)//输入5时退出游戏
{
if(shengmingli<=0)//主角生命力小于等于0时游戏结束
{
cout<<"你死啦!"<<endl;
break;
}
if(guoguan)
{
cout<<"恭喜通关!"<<endl;
break;
}
if(xiaozhen==6)//输入6可检测自己的状态
{
cout<<"你的生命力:"<<shengmingli<<endl;
cout<<"你的攻击力:"<<gongjili<<endl;
cout<<"你的防御力:"<<fangyuli<<endl;
cout<<"你拥有的钱:"<<money<<endl;
}
else
switch(xiaozhen)
{
case 1 : wuqidian();break;
case 2 : yaodian();break;
case 3 : guaiwu1();break;
case 4 : guaiwu2();break;
default : cout<<"请不要乱选!"<<endl;break;
}
cin>>xiaozhen;
}
if(xiaozhen==5)
{
cout<<"正在退出游戏……"<<endl;
}
cin.get();
cin.get();
return 0;
}
void wuqidian()
{
cout<<"欢迎来到武器店!"<<endl;
cout<<"1、买小刀(1M加2攻击力)"<<endl;
cout<<"2、买短剑(2M加20攻击力)"<<endl;
cout<<"3、买大砍刀(5M加40攻击力)"<<endl;
cout<<"4、买双节棍(7M加60攻击力)"<<endl;
cout<<"5、买盾牌(2M加30防御力)"<<endl;
cout<<"6、买铠甲(5M加60防御力)"<<endl;
cout<<"7、离开武器店"<<endl;
int wuqidian;
cin>>wuqidian;
while(wuqidian!=7)//输入7时结束函数
{
switch(wuqidian)
{
case 1 : if(money<10)
cout<<"你的钱不够"<<endl;//钱不够时返回Flase
else
cout<<"购买成功!"<<endl;//钱足够时返回True
gongjili+=2;
money-=1;
break;
case 2 : if(money<80)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
gongjili+=20;
money-=80;
break;
case 3 : if(money<140)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
gongjili+=40;
money-=140;
break;
case 4 : if(money<200)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
gongjili+=60;
money-=200;
break;
case 5 : if(money<60)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
fangyuli+=30;
money-=60;
break;
fangyuli+=60;
money-=100;
break;
default : cout<<"无"<<endl;
break;
}
cin>>wuqidian;
}
if(wuqidian==7)
{ //返回main()主函数
cout<<"欢迎下次再来!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
}
/*
yaodian()的设置与wuqidian()相同,可参照阅读.
*/
void yaodian()
{
cout<<"欢迎来到药品店!"<<endl;
cout<<"1、买1号补血药(10M加200生命)"<<endl;
cout<<"2、买2号补血药(50M加1000生命力)"<<endl;
cout<<"3、买3号补血药(100M加2200生命力)"<<endl;
cout<<"4、离开武器店"<<endl;
int yaodian;
cin>>yaodian;
while(yaodian!=4)
{
switch(yaodian)
{
case 1 : if(money<10)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
shengmingli+=200;
money-=10;
break;
case 2 : if(money<50)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
shengmingli+=1000;
money-=50;
break;
case 3 : if(money<100)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
shengmingli+=2200;
money-=100;
break;
default : cout<<"无"<<endl;
break;
}
cin>>yaodian;
}
if(yaodian==4)
{
cout<<"欢迎下次再来!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
}
/*这里是两个战斗函数,使用指针来处理.避免造成内存崩溃.*/
void guaiwu1()
{
cout<<"开始与小怪物战斗!!!"<<endl;
double* g_shengmingli=new double;//定义怪物生命
int* g_gongjili=new int;//定义怪物攻击力
int* g_fangyuli=new int;//定义怪物防御力
int* g_money=new int;//定义怪物金钱
*g_shengmingli=100;
*g_gongjili=5;
*g_fangyuli=3;
*g_money=5;
double* tongji1=new double;//用来计算主角对怪物的杀伤
double* tongji2=new double;//用来计算怪物对主角的杀伤
*tongji1=0;
*tongji2=0;
int* huihe=new int;//定义回合数
*huihe=1;
cout<<"你开始对小怪物进行攻击!"<<endl;
int* xuanze=new int;
/*
攻击计算公式
杀伤=攻击力*2-防御力
玩家每回合可以选择攻击与逃跑
*/
while((*g_shengmingli)>0 && shengmingli>0 && (*xuanze)!=2)
{
cout<<"现在是"<<"第"<<*huihe<<"回合!"<<endl;
cout<<"请选择你的动作:\n";
cout<<"1、攻击\n2、逃跑\n";
cin>>*xuanze;
switch((*xuanze))
{
case 1 : cout<<"你对小怪物发动了攻击!"<<endl;
*g_shengmingli-=gongjili*2-(*g_fangyuli);
*tongji1=gongjili*2-(*g_fangyuli);
cout<<"你打掉了小怪物"<<*tongji1<<"的生命!"<<endl;
cout<<"小怪物还剩"<<(*g_shengmingli)-(*tongji1)<<"点生命"<<endl;
shengmingli-=(*g_gongjili)*2-fangyuli;
*tongji2=(*g_gongjili)*2-fangyuli;
cout<<"小怪物对你发动了攻击!"<<endl;
cout<<"小怪物打掉了你"<<*tongji2<<"的生命!"<<endl;
cout<<"你还剩"<<shengmingli-(*tongji2)<<"点生命"<<endl;break;
case 2 : cout<<"你决定逃跑!"<<endl;
cout<<"逃跑成功!"<<endl;continue;
default : cout<<"请不要乱选!"<<endl;
}
(*huihe)++;
}
if((*g_shengmingli)<=0)
{//杀死怪物后的返回
cout<<"小怪物被你杀死了!你真厉害!!!"<<endl;
money+=(*g_money);
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
else
if(shengmingli<=0)
{//被怪物杀死后的返回
cout<<"你被小怪物杀死了!游戏结束!!!"<<endl;
}
else
if((*xuanze)==2)
{//逃跑的返回
cout<<"你逃回了小镇!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
delete g_shengmingli;
delete g_gongjili;
delete g_fangyuli;
delete g_money;
delete tongji1;
delete tongji2;
}
/*
设置均与void函数guaiwu1()相同,可参照上例阅读.
*/
void guaiwu2()
{
cout<<"开始与大怪物战斗!!!"<<endl;
double* g_shengmingli=new double;
int* g_gongjili=new int;
int* g_fangyuli=new int;
*g_shengmingli=3600;
*g_gongjili=500;
*g_fangyuli=500;
double* tongji1=new double;
double* tongji2=new double;
*tongji1=0;
*tongji2=0;
int* huihe=new int;
*huihe=1;
cout<<"你开始对大怪物进行攻击!"<<endl;
int* xuanze=new int;
while((*g_shengmingli)>0 && shengmingli>0 && (*xuanze)!=2)
{
cout<<"现在是"<<"第"<<*huihe<<"回合!"<<endl;
cout<<"请选择你的动作:\n";
cout<<"1、攻击\n2、逃跑\n";
cin>>*xuanze;
switch((*xuanze))
{
case 1 : cout<<"你对大怪物发动了攻击!"<<endl;
*g_shengmingli-=gongjili*2-(*g_fangyuli);
*tongji1=gongjili*2-(*g_fangyuli);
cout<<"你打掉了大怪物"<<*tongji1<<"的生命!"<<endl;
cout<<"大怪物还剩"<<(*g_shengmingli)-(*tongji1)<<"点生命"<<endl;
shengmingli-=(*g_gongjili)*2-fangyuli;
*tongji2=(*g_gongjili)*2-fangyuli;
cout<<"大怪物对你发动了攻击!"<<endl;
cout<<"大怪物打掉了你"<<*tongji2<<"的生命!"<<endl;
cout<<"你还剩"<<shengmingli-(*tongji2)<<"点生命"<<endl;break;
case 2 : cout<<"你决定逃跑!"<<endl;
cout<<"逃跑成功!"<<endl;continue;
default : cout<<"请不要乱选!"<<endl;
}
(*huihe)++;
}
if((*g_shengmingli)<=0)
{
cout<<"大怪物被你杀死了!你真厉害!!!"<<endl;
guoguan=true;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
else
if(shengmingli<=0)
{
cout<<"你被大怪物杀死了!游戏结束!!!"<<endl;
}
else
if((*xuanze)==2)
{
cout<<"你逃回了小镇!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
delete g_shengmingli;
delete g_gongjili;
delete g_fangyuli;
delete tongji1;
delete tongji2;
}
中级天翼
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
int i,n,t,a,b,p,m,l,pp,xx,xxx,xxxx=10;
srand(time(0));
p=0;
cout<<"算术题 "<<'\n';
for(i=1;i<=xxxx;i++)
{
a=rand()%99+1;
b=rand()%99+2;
m=rand()%20+1;
if(m==1)
{
cout<<a<<"+"<<b<<"=";
cin>>n;
if(n==a+b)
{
cout<<"good\n";
p=p+10;
}
else
cout<<"Uh-oh\n";
}
if(m==2)
{
if(a<b)
{
t=a;
a=b;
b=t;
}
cout<<a<<"-"<<b<<"=";
cin>>n;
if(n==a-b)
{
cout<<"good\n";
p=p+10;
}
else
cout<<"Oh no\n";
}
else if(m==3||m>=5)
{
if(a%b==0)
{
cout<<a<<"/"<<b<<"=";
cin>>n;
if(n==a/b)
{
cout<<"good\n";
p=p+10;
}
else
cout<<"Oh no\n";
}
else
xxxx=xxxx+1;
}
if(m==4)
{
cout<<a<<"*"<<b<<"=";
cin>>n;
if(n==a*b)
{
cout<<"good\n";
p=p+10;
}
else
cout<<"Oh no\n";
}
cout<<p<<"分"<<'\n';
if(p<100)
cout<<"再接再厉~"<<'\n'<<'\n'<<'\n'<<'\n';
if(p==100)
cout<<"太牛逼了!!!"<<'\n'<<'\n'<<'\n'<<'\n';
}
return 0;
}
高级光能
#include<iostream>
#include<cstdio>
#include<windows.h>
#include<conio.h>
using namespace std;
int SIZ = 20;
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord;
HANDLE hCon;
enum Color { DARKBLUE = 1, DARKGREEN, DARKTEAL, DARKRED, DARKPINK, DARKYELLOW, GRAY, DARKGRAY, BLUE, GREEN, TEAL, RED, PINK, YELLOW, WHITE };
void SetColor(Color c) {
if(hCon == NULL)
hCon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hCon, c);
}
SYSTEMTIME sys;
//sys.wYear,sys.wMonth,sys.wDay,sys.wHour,sys.wMinute, sys.wSecond,sys.wMilliseconds,sys.wDayOfWeek
struct PLAYER {
int x,y;
int hp;
int gun;
int direct;
} p1,p2;
int map[1005][1005];
int abs(int x) {
if(x < 0) return -x;
return x;
}
void locate(int x,int y) {
coord.X=y - 1;
coord.Y=x - 1;
SetConsoleCursorPosition(hout,coord);
}
void print_map() {
locate(1,1);
SetColor(GRAY);
for(int i = 1; i <= SIZ; i++) cout<<"■";
locate(SIZ,1);
for(int i = 1; i <= SIZ; i++) cout<<"■";
for(int i = 2; i < SIZ; i++) {
locate(i,1);
cout<<"■";
locate(i,SIZ*2-1);
cout<<"■";
}
locate(SIZ+1,1);
SetColor(WHITE);
}
void create_tree(int x,int y) {
map[x][y] = map[x+1][y] = map[x-1][y] = map[x][y+1] = map[x][y-1] = 2;
}
void use_map(int x) {
if(x == 1) {
SIZ = 20;
SetColor(DARKGREEN);
map[16][6]=map[15][6]=map[17][6]=map[16][7]=map[16][5]=map[14][13]=map[13][12]=map[13][13]=2;
for(int i = 2; i < SIZ; i++) {
for(int j = 2; j < SIZ; j++) {
if(map[i][j] == 2) {
locate(i,j*2-1);
cout<<"■";
}
}
}
SetColor(GRAY);
for(int i = 5; i <= 15; i++) {
map[i][i] = 1;
locate(i,i*2-1);
cout<<"■";
}
SetColor(WHITE);
} else if(x == 2) {
SIZ = 30;
SetColor(GRAY);
for(int i = 4; i <= 26; i++) {
if(i == 13 || i == 14 ||i == 15) continue;
map[i][4] = map[4][i] = map[26][i] = map[i][26] = 1;
}
for(int i = 1; i <= SIZ; i++) {
for(int j = 1; j <= SIZ; j++) {
if(map[i][j] == 1) {
locate(i,j*2-1);
cout<<"■";
}
}
}
SetColor(DARKGREEN);
for(int i = 10; i<=20; i++) {
if(i == 13 || i == 17) continue;
map[i][10] = map[10][i] = map[20][i] = map[i][20] = 2;
}
create_tree(5,5);
create_tree(18,18);
for(int i = 1; i <= SIZ; i++) {
for(int j = 1; j <= SIZ; j++) {
if(map[i][j] == 2) {
locate(i,j*2-1);
cout<<"■";
}
}
}
SetColor(WHITE);
}
}
void cleanbody(int x,int y);
void putbody(int x,int y,int z);
void player_init() {
p1.hp = p2.hp = 300;
p1.gun = p2.gun = 1;
p1.direct = 4;
p2.direct = 2;
p1.x = 2;
p1.y = 2;
p2.x = SIZ - 1;
p2.y = SIZ - 1;
putbody(p1.x,p1.y,1);
putbody(p2.x,p2.y,2);
}
void mapinit() {
for(int i = 1; i <= SIZ; i++) {
map[i][1] = map[1][i] = map[SIZ][i] = map[i][SIZ] = 1;
}
}
void init() {
printf("Use Which Map?\n");
int x;
cin>>x;
system("cls");
use_map(x);
mapinit();
print_map();
player_init();
}
void putbody(int x,int y,int z) {
if(z == 1) SetColor(BLUE);
else if(z == 2) SetColor(RED);
locate(x,y*2-1);
cout<<"■";
SetColor(WHITE);
}
void cleanbody(int x,int y) {
locate(x,y*2-1);
cout<<" ";
}
/*
LIST
direct:
w 1
a 2
s 3
d 4
gun:
usp 1
mimigun 2
awp 3
block:
void 0
stone 1
tree 2
player 3
clip 4
*/
bool judge(int x,int y) {
if(map[x][y] == 1) return false;
if(map[x][y] == 2) return false;
if(map[x][y] == 3) return false;
return true;
}
bool judge_gun(int x,int y) {
if(map[x][y] == 1) return 0;
if(map[x][y] == 2) return 0;
if(map[x][y] == 3) {
if(p1.x == x && p1.y == y) p1.hp -= 50;//此处暂时不管威力
else p2.hp -= 50;
return 0;
}
return 1;
}
int cnt;
struct Clip {
int x,y;
int derect;
int force;
int start;
bool flag;
} clip[1000000];
void create_clip(int y,int x,int a,int b) {
int X,Y;
if(y == 1) {
if(!judge_gun(a-1,b)) return;
X = a-1;
Y = b;
} else if(y == 2) {
if(!judge_gun(a,b-1)) return;
X = a;
Y = b-1;
} else if(y == 3) {
if(!judge_gun(a+1,b)) return;
X = a+1;
Y = b;
} else if(y == 4) {
if(!judge_gun(a,b+1)) return;
X = a;
Y = b+1;
}
cnt++;
GetLocalTime( &sys );
clip[cnt].start = sys.wMilliseconds + sys.wSecond * 60 + sys.wHour * 3600;
clip[cnt].x = X;
clip[cnt].y = Y;
if(x == 1) {
clip[cnt].derect = p1.direct;
} else if(x == 2) {
clip[cnt].derect = p2.direct;
}
}
void shoot(int x) {
if(x == 1) {
create_clip(p1.direct,1,p1.x,p1.y);
} else if(x == 2) {
create_clip(p2.direct,2,p2.x,p2.y);
}
}
void clean_clip(int x,int y) {
locate(x,y*2-1);
cout<<" ";
locate(1,1);
}
void print_clip(int x,int y,int i) {
if(clip[i].flag) {
clean_clip(x,y);
return;
}
locate(x,y*2-1);
SetColor(YELLOW);
cout<<"''";
locate(1,1);
// system("pause");
}
void clipmove() {
GetLocalTime( &sys );
int t = sys.wMilliseconds + sys.wSecond * 60 + sys.wHour * 3600;
for(int i = 1; i <= cnt; i++) {
if(clip[i].flag) continue;
if(abs(clip[i].start - t) > 50) {
clip[i].start = t;
int x = clip[i].x;
int y = clip[i].y;
if(clip[i].derect==1) {
if(!judge_gun(clip[i].x-1,clip[i].y)) {
clip[i].flag = 1;
clean_clip(x,y);
continue;
}
clean_clip(clip[i].x,clip[i].y);
clip[i].x--;
print_clip(clip[i].x,clip[i].y,i);
} else if(clip[i].derect==2) {
if(!judge_gun(clip[i].x,clip[i].y-1)) {
clip[i].flag = 1;
clean_clip(x,y);
continue;
}
clean_clip(clip[i].x,clip[i].y);
clip[i].y--;
print_clip(clip[i].x,clip[i].y,i);
} else if(clip[i].derect==3) {
if(!judge_gun(clip[i].x+1,clip[i].y)) {
clip[i].flag = 1;
clean_clip(x,y);
continue;
}
clean_clip(clip[i].x,clip[i].y);
clip[i].x++;
print_clip(clip[i].x,clip[i].y,i);
} else if(clip[i].derect==4) {
if(!judge_gun(clip[i].x,clip[i].y+1)) {
clip[i].flag = 1;
clean_clip(x,y);
continue;
}
clean_clip(clip[i].x,clip[i].y);
clip[i].y++;
print_clip(clip[i].x,clip[i].y,i);
}
}
}
}
void judge_hp() {
int x = p1.hp;
int y = p2.hp;
if(x<0 && y<0 && x > y) swap(x,y);
if(x <= 0) {
locate(1,1);
system("cls");
printf("GAME OVER!\nTHE WINNER IS P2!");
Sleep(5000);
printf("\n-MADE BY Floatiy-");
exit(0);
} else if(y <= 0) {
locate(1,1);
system("cls");
printf("GAME OVER!\nTHE WINNER IS P1!");
Sleep(5000);
printf("\n-MADE BY Floatiy-");
exit(0);
}
}
void prog() {
char ch;
while(true) {
if(kbhit()) {
ch=getch();
if(ch == 'w' && judge(p1.x-1,p1.y)) {
p1.direct = 1;
cleanbody(p1.x,p1.y);
map[p1.x][p1.y] = 0;
putbody(--p1.x,p1.y,1);
map[p1.x][p1.y] = 3;
} else if(ch == '8' && judge(p2.x-1,p2.y)) {
p2.direct = 1;
cleanbody(p2.x,p2.y);
map[p2.x][p2.y] = 0;
putbody(--p2.x,p2.y,2);
map[p2.x][p2.y] = 3;
} else if(ch == 'a' && judge(p1.x,p1.y-1)) {
p1.direct = 2;
cleanbody(p1.x,p1.y);
map[p1.x][p1.y] = 0;
putbody(p1.x,--p1.y,1);
map[p1.x][p1.y] = 3;
} else if(ch == '4' && judge(p2.x,p2.y-1)) {
p2.direct = 2;
cleanbody(p2.x,p2.y);
map[p2.x][p2.y] = 0;
putbody(p2.x,--p2.y,2);
map[p2.x][p2.y] = 3;
} else if(ch == 's' && judge(p1.x+1,p1.y)) {
p1.direct = 3;
cleanbody(p1.x,p1.y);
map[p1.x][p1.y] = 0;
putbody(++p1.x,p1.y,1);
map[p1.x][p1.y] = 3;
} else if(ch == '5' && judge(p2.x+1,p2.y)) {
p2.direct = 3;
cleanbody(p2.x,p2.y);
map[p2.x][p2.y] = 0;
putbody(++p2.x,p2.y,2);
map[p2.x][p2.y] = 3;
} else if(ch == 'd' && judge(p1.x,p1.y+1)) {
p1.direct = 4;
cleanbody(p1.x,p1.y);
map[p1.x][p1.y] = 0;
putbody(p1.x,++p1.y,1);
map[p1.x][p1.y] = 3;
} else if(ch == '6' && judge(p2.x,p2.y+1)) {
p2.direct = 4;
cleanbody(p2.x,p2.y);
map[p2.x][p2.y] = 0;
putbody(p2.x,++p2.y,2);
map[p2.x][p2.y] = 3;
} else if(ch == '0') {
shoot(2);
} else if(ch == ' ') {
shoot(1);
}
Sleep(20);
}
clipmove();
judge_hp();
}
}
void welcome() {
printf("操作方法:\n玩家1 wasd控制移动,空格攻击\n玩家2 数字小键盘4568控制移动,0攻击\n");
Sleep(2000);
}
int main() {
welcome();
GetLocalTime( &sys );
init();
prog();
return 0;
}
普通枪战
中级天翼
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int player[100000001],sf[100000001],buy,computer,score,cishu,win,lose,tili=10,co,a,b,c,d,meichao=1;
int isvip=0,ismvp=0,xingyv=100;
void out();
void judge();
void timu(int);
void zhiliwenda();
void screen();
void screan();
void computer_lose();
void player_lose();
void tin();
void tili_0();
void fight();
void store();
void color();
void waigua();
void meiyuan();
void jianjei();
void chengfa();
int main()
{
srand((int)time(0));
system("color 9F");
cout<<"欢迎来到石头剪刀布大战2.8版本!";
ofstream fout("C:\\Program Files\\石头剪刀布.txt");
Sleep(2000);
cout<<endl;
screen();
return 0;
}
void out(string s)
{
int i;
for(i=0;i<=s.length();i++)
{
cout<<s[i];
Sleep(20);
}
}
void screen()
{
while(1)
{
system("cls");
if(xingyv<=0)
{
out("信誉为0,休息一会,马上回来!");
cout<<endl;
int i,yushu;
for(i=1;i<=rand()%20;i++)
{
yushu=i%8;
switch(yushu)
{
case 0:
{
system("color 0F");
out("吃鸡三级头套装,限购10个哟!");
system("cls");
break;
}
case 1:
{
system("color 3F");
out("我的世界头套100个,现在大促销,快来买哟!");
system("cls");
break;
}
case 2:
{
system("color AF");
out("装逼专用机器,还送10年保修哟!");
system("cls");
break;
}
case 3:
{
system("color BF");
out("吃鸡专用98k,800里外一枪爆头!");
system("cls");
break;
}
case 4:
{
system("color AB");
out("王者10000000份外挂大放送,手快有手慢无!");
system("cls");
break;
}
case 5:
{
system("color 0F");
out("联* x220i笔记本电脑出售,抢购只在1秒间!");
system("cls");
break;
}
case 6:
{
system("color 1F");
out("6666666,6666666,6666666,6666666");
system("cls");
xingyv+=100;
break;
}
}
}
zhiliwenda();
}
system("cls");
if(score<0)
{
chengfa();
system("cls");
break;
}
out("你现在有");
cout<<score;
out("张毛爷爷,");
cout<<meichao;
out("美元,");
cout<<tili;
out("点体力值,");
cout<<win;
out("次胜利,");
cout<<lose;
out("次失败,");
cout<<isvip;
out("张VIP卡,");
cout<<ismvp;
out("张MVP卡,");
cout<<xingyv;
out("信誉积分.");
cout<<endl;
out("现在,你可以有以下选择:");
cout<<endl;
out("1:人机大战");
cout<<endl;
out("2:购买道具");
cout<<endl;
out("3.游戏简介");
cout<<endl;
out("4:外挂");
cout<<endl;
out("5:调整设置");
int in;
cout<<endl;
cin>>in;
switch(in)
{
case 1:
fight();
system("cls");
break;
case 2:
store();
system("cls");
break;
case 3:
jianjei();
system("cls");
break;
case 4:
waigua();
system("cls");
case 5:
color();
system("cls");
default:
out("输错了,请重试。");
}
}
}
void jianjei()
{
int o;
printf("本游戏版权归属为学神,请勿盗版。本版本预计10月12日更新,如有延迟请恕罪。2.8版本跟新了外挂和信誉积分模式,后面可能完善,整体功能提高。请大家散布通缉令通缉李明浩 江月路两人谢谢");
printf("下一个版本可能会有信誉积分的兑换和奖励,请点个赞") ;
printf("点赞打1否则打2");
scanf("%d",&o);
if(o==1)
{
score+=10;
}
else
{
score-=10;
}
}
void fight()
{
if(xingyv>=20)
{
cishu++;
tili--;
xingyv-=(rand()%10);
out("你先出。");
cout<<endl;
out("1:石头");
cout<<endl;
out("2:剪刀");
cout<<endl;
out("3:布");
cout<<endl;
out("你出的是:");
cin>>player[cishu];
if(player[cishu]>=4 || player[cishu]<=0)
{
out("无效输入。");
return;
}
computer=(rand()%3)+1;
switch(computer)
{
case 1:
out("电脑出的是石头。");
break;
case 2:
out("电脑出的是剪刀。");
break;
case 3:
out("电脑出的是布。");
break;
}
judge();
}
else
{
printf("信誉积分不足");
xingyv+=5;
}
}
void computer_lose()
{
out("玩家胜利!");
cout<<endl;
sf[cishu]=1;
score+=((rand()%5)+6);
win++;
}
void player_lose()
{
out("玩家失败!");
cout<<endl;
sf[cishu]=-1;
lose++;
}
void tin()
{
out("平局!");
cout<<endl;
}
void store()
{
system("cls");
out("欢迎来到《石头剪刀布》士多店。您有");
cout<<score;
out("张毛爷爷。");
cout<<isvip;
out("张VIP卡");
cout<<ismvp;
out("张MVP卡");
cout<<endl;
out("请问您要买什么?");
cout<<endl;
out("1:失败记录修改器。可以减少一次失败记录。¥5");
cout<<endl;
out("2:胜利记录修改器。可以增加一次胜利记录。¥8");
cout<<endl;
out("3:冰阔落。可以增加5点体力值。¥5");
cout<<endl;
out("4:兴奋剂。可以增加10点体力值。¥10");
cout<<endl;
out("5:一次性刷钱机。可以增加随机价格的毛爷爷。¥10");
cout<<endl;
out("6:商场VIP会员卡。能给商品降低80%价格。¥50");
cout<<endl;
out("7:战无不胜卡(五次,vip和mvp不降价)。¥25");
cout<<endl;
out("8:商场MVP权限。可降价50%。在VIP的基础上再加多100块。");
cout<<endl;
out("9:退出。");
cout<<endl;
out("10:100信誉积分(只有VIP和MVP才能买) ¥300");
cout<<endl;
out("11:解锁全游戏。胜利10次即可购买。");
cout<<endl;
out("12:管理员权限。战胜500次即可获得。");
cin>>buy;
if(isvip>=1&&ismvp<=0)
{
switch(buy)
{
case 1:
score-=4;
lose--;
break;
case 2:
score-=6;
win++;
break;
case 3:
score-=4;
tili+=5;
break;
case 4:
score-=8;
tili+=10;
break;
case 5:
score-=8;
score+=(rand()%100);
break;
case 6:
isvip=1;
out("VIP权限申请成功。");
score-=40;
break;
case 7:
win+=5;
for(int i=cishu;i<=cishu+5;i++)
{
sf[i]=1;
cishu++;
}
break;
case 8:
ismvp=1;
out("VIP成功升级为MVP。");
isvip-=1;
score-=120;
break;
case 9:
score+=1;
case 10:
score-=300;
xingyv+=100;
if(score<0) out("操你妈的,居然敢不带够钱买东西,给老子滚出去!"),win=0,score=0,lose=1000000;
}
}
if(ismvp>=1)
{
switch(buy)
{
case 1:
score-=3;
lose--;
break;
case 2:
score-=4;
win++;
break;
case 3:
score-=3;
tili+=5;
break;
case 4:
score-=5;
tili+=10;
break;
case 5:
score-=5;
score+=(rand()%100);
break;
case 6:
isvip=1;
out("VIP权限申请成功。");
score-=25;
break;
case 7:
win+=5;
for(int i=cishu;i<=cishu+5;i++)
{
sf[i]=1;
cishu++;
}
break;
case 8:
ismvp=1;
out("VIP成功升级为MVP。");
isvip-=1;
score-=75;
break;
case 9:
score+=1;
break;
case 10:
score-=300;
xingyv+=100;
//ofstream fout("")
if(score<0) out("操你妈的,居然敢不带够钱买东西,给老子滚出去!"),win=0,score=0,lose=1000000;
}
}
if(isvip<=0&&ismvp<=0)
{
switch(buy)
{
case 1:
score-=5;
lose--;
break;
case 2:
score-=8;
win++;
break;
case 3:
score-=5;
tili+=5;
break;
case 4:
score-=10;
tili+=10;
break;
case 5:
score-=10;
score+=(rand()%100);
break;
case 6:
isvip=1;
out("VIP权限申请成功。");
score-=50;
break;
case 7:
win+=5;
for(int i=cishu;i<=cishu+5;i++)
{
sf[i]=1;
cishu++;
}
break;
//ofstream fout("")
if(score<0)
out("操你妈的,居然敢不带够钱买东西,给老子滚出去!"),win=0,score=0,lose=1000000;
}
}
}
void waigua()
{
printf("密码1:");
scanf("%d",&a);
printf("密码2:");
scanf("%d",&b);
c=a+b;
if(c==5201314)
{
score+=200;
printf("谁是学神?");
printf("1.甘子钰");
printf("2.李明浩");
printf("3.李瑜桓");
printf("4.龙立轩");
printf("5.这一题不适合我,退出");
scanf("%d",&d);
if(d==1||d==3)
{
printf("你答对了,真棒");
score+=500;
}
if(d==2||d==4)
{
printf("错了,减100毛爷爷");
score-=100;
}
if(d==5)
{
printf("拜拜,给你1个毛爷爷");
score+=1;
}
if(d>5)
{
printf("调皮蛋,罚50毛爷爷");
score-=50;
}
}
else
{
score=0;
}
}
void chengfa()
{
int cv;
if(score<0)
{
printf("惩罚开始");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("1.....................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("......................................");
printf("刚刚多余的是什么数字");
scanf("%d",&cv);
if(cv==1)
{
score+=50;
}
else
{
chengfa();
system("cls");
}
}
}
void color()
{
out("你要什么字体颜色?");
cout<<endl;
out("黑色:按1");
cout<<endl;
out("蓝色:按2");
cout<<endl;
out("绿色:按3");
cout<<endl;
out("浅绿色:按4");
cout<<endl;
out("红色:按5");
cout<<endl;
out("紫色:按6");
cout<<endl;
out("黄色:按7");
cout<<endl;
out("白色:按8");
cout<<endl;
out("灰色:按9");
cout<<endl;
out("淡蓝色:按A");
cout<<endl;
out("淡绿色:按B");
cout<<endl;
out("淡浅绿色:按C");
cout<<endl;
out("淡红色:按D");
cout<<endl;
out("淡紫色:按E");
cout<<endl;
out("淡黄色:按F");
cout<<endl;
out("亮白色:按G");
cout<<endl;
char c;
cin>>c;
switch(c)
{
case '1':
system("color 0");
break;
case '2':
system("color 1");
break;
case '3':
system("color 2");
break;
case '4':
system("color 3");
break;
case '5':
system("color 4");
break;
case '6':
system("color 5");
break;
case '7':
system("color 6");
break;
case '8':
system("color 7");
break;
case '9':
system("color 8");
break;
case 'A':
system("color 9");
break;
case 'B':
system("color A");
break;
case 'C':
system("color B");
break;
case 'D':
system("color C");
break;
case 'E':
system("color D");
break;
case 'F':
system("color E");
break;
case 'G':
system("color F");
break;
default:
system("color");
break;
}
out("调颜色成功。");
}
void judge()
{
if(player[cishu]==1)
{
if(computer==2)
{
computer_lose();
}
if(computer==3)
{
player_lose();
}
if(computer==1)
{
tin();
}
}
if(player[cishu]==2)
{
if(computer==3)
{
computer_lose();
}
if(computer==1)
{
player_lose();
}
if(computer==2)
{
tin();
}
}
if(player[cishu]==3)
{
if(computer==1)
{
computer_lose();
}
if(computer==2)
{
player_lose();
}
if(computer==3)
{
tin();
}
}
}
void zhiliwenda()
{
system("cls");
system("color 9F");
for(int i=1;i<=10;i++)
timu(rand()%10);
tili+=5;
}
void timu(int in)
{
int input;
switch(in)
{
case 0:
{
out("0~31有几个数?");
cout<<endl;
cin>>input;
if(input==32)
{
out("被你答对了,真是不可思议!");
return;
}
else
{
out("脑子有问题。");
timu(rand()%10);
}
}
break;
case 1:
{
out("0,1,1,2,3,5,8,后面是什么?");
cout<<endl;
cin>>input;
if(input==13)
{
out("被你答对了,真是不可思议!");
return;
}
else
{
out("sb。");
timu(rand()%10);
}
}
break;
case 2:
{
out("9,61,52,63,94,后面是什么?");
cout<<endl;
cin>>input;
if(input==64)
{
out("被你给答对了,真是不可思议!");
return;
}
else
{
out("6666666。");
timu(rand()%10);
}
}
break;
case 3:
{
out("求7分之1的小数点后第1000位是多少。");
cout<<endl;
cin>>input;
if(input==8)
{
out("被你答对了,真是不可思议!");
return;
}
else
{
out("这都不会。");
timu(rand()%10);
}
}
break;
case 4:
{
out("求13分之1的小数点后第1000位是多少。");
cout<<endl;
cin>>input;
if(input==9)
{
out("被你答对了,真是不可思议!");
return;
}
else
{
out("这都不会。");
timu(rand()%10);
}
}
break;
case 5:
{
out("2^16=?");
cout<<endl;
cin>>input;
if(input==65536)
{
out("被你答对了,真是不可思议!");
return;
}
else
{
out("这都不会。。。");
timu(rand()%10);
}
}
break;
case 6:
{
out("一吨水多少钱?");
cout<<endl;
cin>>input;
if(input>=3&&input<=8)
{
out("被你答对了,真是不可思议!");
return;
}
else
{
out("这都不会。666666666。。。");
timu(rand()%10);
}
}
break;
case 7:
{
out("求你一天吃几碗饭。");
cout<<endl;
cin>>input;
if(input<=2)
{
out("被你答对了,真是不可思议!");
return;
}
else
{
out("吃货!");
timu(rand()%10);
}
}
break;
case 8:
{
out("求标准钢琴有几个键。");
cout<<endl;
cin>>input;
if(input==88)
{
out("被你答对了,真是不可思议!");
return;
}
else
{
out("这都不会。。。估计不弹钢琴。。。");
timu(rand()%10);
}
}
break;
case 9:
{
out("本游戏至少有多少行?");
cout<<endl;
cin>>input;
if(input>=600)
{
out("被你答对了,真是不可思议!");
return;
}
else
{
out("这都不会。");
timu(rand()%10);
}
}
break;
}
}
void screan()
{
while(1)
{
system("cls");
if(tili<=0)
{
out("体力为0,休息一会,马上回来!");
cout<<endl;
int i,yushu;
for(i=1;i<=rand()%20;i++)
{
yushu=i%8;
switch(yushu)
{
case 0:
{
system("color 0F");
out("吃鸡三级头套装,限购10个哟!");
system("cls");
break;
}
case 1:
{
system("color 3F");
out("我的世界头套100个,现在大促销,快来买哟!");
system("cls");
break;
}
case 2:
{
system("color AF");
out("装逼专用机器,还送10年保修哟!");
system("cls");
break;
}
case 3:
{
system("color BF");
out("吃鸡专用98k,800里外一枪爆头!");
system("cls");
break;
}
case 4:
{
system("color AB");
out("王者10000000份外挂大放送,手快有手慢无!");
system("cls");
break;
}
case 5:
{
system("color 0F");
out("联* x220i笔记本电脑出售,抢购只在1秒间!");
system("cls");
break;
}
case 6:
{
system("color 1F");
out("6666666,6666666,6666666,6666666");
system("cls");
break;
}
}
}
zhiliwenda();
}
system("cls");
out("你现在有");
cout<<score;
out("张毛爷爷,");
cout<<tili;
out("点体力值,");
cout<<win;
out("次胜利,");
cout<<lose;
out("次失败。");
cout<<isvip;
out("张VIP卡");
cout<<ismvp;
out("张MVP卡");
cout<<xingyv;
out("信誉积分");
cout<<endl;
out("现在,你可以有以下选择:");
cout<<endl;
out("1:人机大战");
cout<<endl;
out("2:购买道具");
cout<<endl;
out("3.游戏简介");
cout<<endl;
out("4:外挂");
cout<<endl;
out("5:调整设置");
int in;
cin>>in;
switch(in)
{
case 1:
fight();
system("cls");
break;
case 2:
store();
system("cls");
break;
case 3:
jianjei();
system("cls");
break;
case 4:
waigua();
system("cls");
case 5:
color();
system("cls");
default:
out("输错了,请重试。");
}
}
}
资深光能
#include<iostream>
#include<windows.h>
#include<time.h>
#include<conio.h>
using namespace std;
// 刷新当前屏幕
inline void Refresh(char q[][22], int grade, int gamespeed){
system("cls"); // 清屏
int i,j;
cout << endl;
for(i=0;i<22;i++){
cout << "\t";
for(j=0;j<22;j++)
cout<<q[i][j]<<' '; // 输出贪吃蛇棋盘
if(i==0) cout << "\t等级为:" << grade;
if(i==4) cout << "\t自动前进时间";
if(i==6) cout << "\t间隔为:" << gamespeed << "ms";
cout<<endl;
}
}
int main(){
char tcsQipan[22][22]; // 贪吃蛇棋盘是一个二维数组(如22*22,包括墙壁)
int i,j;
for(i=1;i<=20;i++)
for(j=1;j<=20;j++)
tcsQipan[i][j]=' '; // 初始化贪吃蛇棋盘中间空白部分
for(i=0;i<=21;i++)
tcsQipan[0][i] = tcsQipan[21][i] = '-'; //初始化贪吃蛇棋盘上下墙壁
for(i=1;i<=20;i++)
tcsQipan[i][0] = tcsQipan[i][21] = '|'; //初始化贪吃蛇棋盘左右墙壁
int tcsZuobiao[2][100]; //蛇的坐标数组
for(i=0; i<4; i++){
tcsZuobiao[0][i] = 1;
tcsZuobiao[1][i] = i + 1;
}
int head = 3,tail = 0;
for(i=1;i<=3;i++)
tcsQipan[1][i]='*'; //蛇身
tcsQipan[1][4]='#'; //蛇头
int x1, y1; // 随机出米
srand(time(0));
do{
x1=rand()%20+1;
y1=rand()%20+1;
}while(tcsQipan[x1][y1]!=' ');
tcsQipan[x1][y1]='*';
cout<<"\n\n\t\t贪吃蛇游戏即将开始 !"<<endl;//准备开始;;
long start;
int grade = 1, length = 4;
int gamespeed = 500; //前进时间间隔
for(i=3;i>=0;i--){
start=clock();
while(clock()-start<=1000);
system("cls");
if(i>0)
cout << "\n\n\t\t进入倒计时:" << i << endl;
else
Refresh(tcsQipan,grade,gamespeed);
}
int timeover;
char direction = 77; // 初始情况下,向右运动
int x,y;
while(1){
timeover = 1;
start = clock();
while((timeover=(clock()-start<=gamespeed))&&!kbhit());
//如果有键按下或时间超过自动前进时间间隔则终止循环
if(timeover){
getch();direction = getch();
}
switch(direction){
case 72: x= tcsZuobiao[0][head]-1; y= tcsZuobiao[1][head];break; // 向上
case 80: x= tcsZuobiao[0][head]+1; y= tcsZuobiao[1][head];break; // 向下
case 75: x= tcsZuobiao[0][head]; y= tcsZuobiao[1][head]-1;break; // 向左
case 77: x= tcsZuobiao[0][head]; y= tcsZuobiao[1][head]+1; // 向右
}
if(!(direction==72||direction==80||direction==75 ||direction==77)){ // 按键非方向键
cout << "\tGame over!" << endl;return 0;
}
if(x==0 || x==21 ||y==0 || y==21){ // 碰到墙壁
cout << "\tGame over!" << endl;return 0;
}
if(tcsQipan[x][y]!=' '&&!(x==x1&&y==y1)){ // 蛇头碰到蛇身
cout << "\tGame over!" << endl;return 0;
}
if(x==x1 && y==y1){ // 吃米,长度加1
length ++;
if(length>=8){
length -= 8;
grade ++;
if(gamespeed>=200)
gamespeed = 550 - grade * 50; // 改变自动前进时间间隔
}
tcsQipan[x][y]= '#';
tcsQipan[tcsZuobiao[0][head]][tcsZuobiao[1][head]] = '*';
head = (head+1)%100;
tcsZuobiao[0][head] = x;
tcsZuobiao[1][head] = y;
do
{
x1=rand()%20+1;
y1=rand()%20+1;
}while(tcsQipan[x1][y1]!=' ');
tcsQipan[x1][y1]='*';
Refresh(tcsQipan,grade,gamespeed);
}
else{ // 不吃米
tcsQipan [tcsZuobiao[0][tail]][tcsZuobiao[1][tail]]=' ';
tail=(tail+1)%100;
tcsQipan [tcsZuobiao[0][head]][tcsZuobiao[1][head]]='*';
head=(head+1)%100;
tcsZuobiao[0][head]=x;
tcsZuobiao[1][head]=y;
tcsQipan[tcsZuobiao[0][head]][tcsZuobiao[1][head]]='#';
Refresh(tcsQipan,grade,gamespeed);
}
}
return 0;
}
可以试试
高级光能
扫雷:
#include<stdio.h>
#include<cmath>
#include<windows.h>
#include<stdlib.h>
#include<time.h>
#include<conio.h>
#include<queue>
#include<ctype.h>
#define A 10 //地图的高
#define B 10 //地图的宽
#define C 25 //雷的总数
using namespace std;
//全局变量
DWORD a,b;
char map[A][B],news,spare;
int BoomTotalNum,floatx,floaty,flag[A][B],flagnum,mode,slect[A][B],game;
//颜色属性
const WORD FORE_BLUE = FOREGROUND_BLUE; //蓝色文本属性
const WORD FORE_GREEN = FOREGROUND_GREEN; //绿色文本属性
const WORD FORE_RED = FOREGROUND_RED; //红色文本属性
//开垦地图结构体
struct node {
int x;
int y;
};
queue <node> dui;
//打印位置
void position(int x,int y) {
COORD pos={x,y};
HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out,pos);
}
//隐藏光标
void Hide() {
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(handle, &CursorInfo);//获取控制台光标信息
CursorInfo.bVisible = false; //隐藏控制台光标
SetConsoleCursorInfo(handle, &CursorInfo);//设置控制台光标状态
}
//初始化
void Beginning() {
while(!dui.empty()) {
dui.pop();
}
game=1;
//BoomTotalNum=C;
floatx=A/2;
floaty=B/2;
flagnum=0;
BoomTotalNum=C;
mode=0;
HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出设备句柄
CONSOLE_SCREEN_BUFFER_INFO csbi; //定义窗口缓冲区信息结构体
GetConsoleScreenBufferInfo(handle_out, &csbi); //获得窗口缓冲区信息
int x,y;
srand((unsigned)time(0));
for(int i=0;i<A;i++) for(int j=0;j<B;j++) {
map[i][j]=' ';
flag[i][j]=0;
slect[i][j]=0;
}
while(BoomTotalNum) {
x=rand()%A;
y=rand()%B;
if(map[x][y]==' ') {
map[x][y]='@';
BoomTotalNum--;
}
}
SetConsoleTextAttribute(handle_out, FORE_GREEN);
for(int i=0;i<A;i++) {
for(int j=0;j<B;j++) printf("█");
printf("\n");
}
position(floaty*2,floatx);
SetConsoleTextAttribute(handle_out, FORE_RED);
printf(""); //光标位置
position(44,9);
printf("扫雷模式");
position(44,5);
printf("剩余雷数:%d ",C-flagnum);
SetConsoleTextAttribute(handle_out, FORE_GREEN);
position(5,22);
printf("按“空格”切换模式");
position(5,23);
printf("按“Enter”确认");
position(5,24);
printf("按“方向键”选择方块");
}
//打印地图的一块儿
void Lump(int xx,int yy) {
switch(map[xx][yy]) {
case '1' : printf("①");break; //周围雷的数量(下同)
case '2' : printf("②");break;
case '3' : printf("③");break;
case '4' : printf("④");break;
case '5' : printf("⑤");break;
case '6' : printf("⑥");break;
case '7' : printf("⑦");break;
case '8' : printf("⑧");break;
case ' ' :
if(xx==floatx&&yy==floaty) {
if(flag[xx][yy]==0) {
if(mode%2==0) printf("");
else printf("");
}
else printf("");
}
else {
if(flag[xx][yy]==0) printf("█");
else printf("");
}
break;
case '@' :
if(xx==floatx&&yy==floaty) {
if(flag[xx][yy]==0) {
if(mode%2==0) printf("");
else printf("");
}
else printf("");
}
else {
if(flag[xx][yy]==0) printf("█");
else printf("");
}
break;
case 'x' : if(floatx==xx&&floaty==yy) printf(""); else printf(" ");break; //已经挖开的空白
}
}
//移动光标
void Move() {
HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出设备句柄
CONSOLE_SCREEN_BUFFER_INFO csbi; //定义窗口缓冲区信息结构体
GetConsoleScreenBufferInfo(handle_out, &csbi); //获得窗口缓冲区信息
int xxx,yyy;
xxx=floatx;
yyy=floaty;
switch(news) {
case 72 : floatx--;break; //上
case 80 : floatx++;break; //下
case 75 : floaty--;break; //左
case 77 : floaty++;break; //右
}
if(floatx==-1) floatx=A-1; floatx%=A; //两端穿模处理
if(floaty==-1) floaty=B-1; floaty%=B;
position(yyy*2,xxx);
SetConsoleTextAttribute(handle_out, FORE_GREEN);
Lump(xxx,yyy); //删除原位置
if(map[floatx][floaty]=='x') {
position(floaty*2,floatx);
printf(" ");
}
position(floaty*2,floatx);
SetConsoleTextAttribute(handle_out, FORE_BLUE);
Lump(floatx,floaty); //更新新位置
}
//插旗和排雷模式切换
void Mode() {
HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出设备句柄
CONSOLE_SCREEN_BUFFER_INFO csbi; //定义窗口缓冲区信息结构体
GetConsoleScreenBufferInfo(handle_out, &csbi); //获得窗口缓冲区信息
mode++;
SetConsoleTextAttribute(handle_out, FORE_BLUE);
position(floaty*2,floatx);
if(mode%2==0) printf("");
else printf("");
position(44,9);
if(mode%2==0) {
SetConsoleTextAttribute(handle_out, FORE_BLUE);
printf("扫雷模式");
}
else {
SetConsoleTextAttribute(handle_out, FORE_RED);
printf("插旗模式");
}
}
//该点周围地雷数
int Boomnum(int xx,int yy) {
int num=0;
if((xx-1>=0)&&(yy-1>=0)&&(map[xx-1][yy-1]=='@')) num++;
if((xx-1>=0)&&(yy+0>=0)&&(map[xx-1][yy]=='@')) num++;
if((xx-1>=0)&&(yy+1<B) &&(map[xx-1][yy+1]=='@')) num++;
if((xx+0>=0)&&(yy-1>=0)&&(map[xx][yy-1]=='@')) num++;
if((xx+0>=0)&&(yy+1<B) &&(map[xx][yy+1]=='@')) num++;
if((xx+1<A)&&(yy-1>=0) &&(map[xx+1][yy-1]=='@')) num++;
if((xx+1<A)&&(yy+0>=0) &&(map[xx+1][yy]=='@')) num++;
if((xx+1<A)&&(yy+1<B) &&(map[xx+1][yy+1]=='@')) num++;
return num;
}
//更新地图
void Open() {
node c;
node d;
while(!dui.empty()) {
dui.pop();
}
c.x=floatx;
c.y=floaty;
dui.push(c);
slect[c.x][c.y]=1;
while(!dui.empty()) {
c=dui.front();
dui.pop();
if(Boomnum(c.x,c.y)!=0) {
map[c.x][c.y]=(Boomnum(c.x,c.y)+48);
continue;
}
else {
map[c.x][c.y]='x';
if((c.x-1>=0)&&(c.y-1>=0)&&(map[c.x-1][c.y-1]==' ')&&(slect[c.x-1][c.y-1]==0)) {
d.x=c.x-1;
d.y=c.y-1;
dui.push(d);
slect[d.x][d.y]=1;
}
if((c.x-1>=0)&&(c.y-0>=0)&&(map[c.x-1][c.y]==' ')&&(slect[c.x-1][c.y]==0)) {
d.x=c.x-1;
d.y=c.y-0;
dui.push(d);
slect[d.x][d.y]=1;
}
if((c.x-1>=0)&&(c.y+1<B)&&(map[c.x-1][c.y+1]==' ')&&(slect[c.x-1][c.y+1]==0)) {
d.x=c.x-1;
d.y=c.y+1;
dui.push(d);
slect[d.x][d.y]=1;
}
if((c.x-0>=0)&&(c.y-1>=0)&&(map[c.x][c.y-1]==' ')&&(slect[c.x][c.y-1]==0)) {
d.x=c.x-0;
d.y=c.y-1;
dui.push(d);
slect[d.x][d.y]=1;
}
if((c.x-0>=0)&&(c.y+1<B)&&(map[c.x][c.y+1]==' ')&&(slect[c.x][c.y+1]==0)) {
d.x=c.x-0;
d.y=c.y+1;
dui.push(d);
slect[d.x][d.y]=1;
}
if((c.x+1<A)&&(c.y-1>=0)&&(map[c.x+1][c.y-1]==' ')&&(slect[c.x+1][c.y-1]==0)) {
d.x=c.x+1;
d.y=c.y-1;
dui.push(d);
slect[d.x][d.y]=1;
}
if((c.x+1<A)&&(c.y-0>=0)&&(map[c.x+1][c.y]==' ')&&(slect[c.x+1][c.y]==0)) {
d.x=c.x+1;
d.y=c.y-0;
dui.push(d);
slect[d.x][d.y]=1;
}
if((c.x+1<A)&&(c.y+1<B)&&(map[c.x+1][c.y+1]==' ')&&(slect[c.x+1][c.y+1]==0)) {
d.x=c.x+1;
d.y=c.y+1;
dui.push(d);
slect[d.x][d.y]=1;
}
}
}
}
int main() {
freopen("排名.txt","r",stdin);
Relife: //重玩处
HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出设备句柄
CONSOLE_SCREEN_BUFFER_INFO csbi; //定义窗口缓冲区信息结构体
GetConsoleScreenBufferInfo(handle_out, &csbi); //获得窗口缓冲区信息
Hide(); //隐藏光标
Beginning();//初始化地图
a=GetTickCount();
while(1) {
if(kbhit()!=0) {
spare=getch();
//按其他
if((spare!=(-32))&&(spare!=13)&&(spare!=' ')) continue;//跳过
//按Enter
if(spare==13) { //确认
//排雷
if(mode%2==0) {
if(map[floatx][floaty]=='@'&&flag[floatx][floaty]==0) {
break; //触雷
game=0;
}
if(flag[floatx][floaty]==1) continue; //有旗跳过
Open();
position(0,0);
SetConsoleTextAttribute(handle_out, FORE_GREEN);
for(int i=0;i<A;i++) {
for(int j=0;j<B;j++) Lump(i,j);
printf("\n");
}
position(floaty*2,floatx);
SetConsoleTextAttribute(handle_out, FORE_BLUE);
Lump(floatx,floaty);
}
//插拔旗
else {
//不能插旗的地方
if(map[floatx][floaty]=='x'||(map[floatx][floaty]>'0'&&map[floatx][floaty]<'9'))
continue; //跳过
//插旗
if(flag[floatx][floaty]==0) {
flagnum++;
flag[floatx][floaty]=1;
position(floaty*2,floatx);
SetConsoleTextAttribute(handle_out, FORE_BLUE);
Lump(floatx,floaty);
}
//拔旗
else {
flagnum--;
flag[floatx][floaty]=0;
position(floaty*2,floatx);
SetConsoleTextAttribute(handle_out, FORE_BLUE);
Lump(floatx,floaty);
}
}
}
//按空格
if(spare==' ') Mode(); //切换模式
//按方向键
if(spare==-32) {
news=getch();
Move(); //移动光标
}
for(int i=0;i<A;i++) for(int j=0;j<B;j++) if(map[i][j]=='x'||(map[i][j]>'0'&&map[i][j]<'9')) game++;
if(game==A*B-C+1) break;
else game=1;
SetConsoleTextAttribute(handle_out, FORE_RED);
position(44,5);
printf("剩余雷数:%d ",C-flagnum);
}
else Sleep(10);
b=GetTickCount();
SetConsoleTextAttribute(handle_out, FORE_RED);
position(44,7);
printf("用时:"); //用时
if((b-a)/60000<10) printf("0");
printf("%d:",(b-a)/60000);
if(((b-a)/1000)%60<10) printf("0");
printf("%d:",((b-a)/1000)%60);
if(((b-a)/10)%100<10) printf("0");
printf("%d",((b-a)/10)%100);
}
SetConsoleTextAttribute(handle_out, FORE_RED);
position(5,5);
if(game==1) printf("游戏结束!");
else printf("恭喜通关!");
position(5,8);
printf("任意键重玩");
scanf("%c%c",&spare,&spare);
system("cls");
position(0,0);
goto Relife;
}
//望采纳!
中级守护
#include <iostream>
using namespace std;
double shengmingli=2000;//定义主角初始生命力
int gongjili=150;//定义主角初始攻击力
int fangyuli=200;//定义主角初始防御力
int money=20;//定义主角初始金钱数量
bool guoguan;//定义是否通关判定
void wuqidian();//定义武器店函数
void yaodian();//定义药店函数
void guaiwu1();//定义小怪物函数
void guaiwu2();//定义大怪物函数
int main()
{
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
int xiaozhen;//定义选择项目
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
cin>>xiaozhen;
while(xiaozhen!=5)//输入5时退出游戏
{
if(shengmingli<=0)//主角生命力小于等于0时游戏结束
{
cout<<"你死啦!"<<endl;
break;
}
if(guoguan)
{
cout<<"恭喜通关!"<<endl;
break;
}
if(xiaozhen==6)//输入6可检测自己的状态
{
cout<<"你的生命力:"<<shengmingli<<endl;
cout<<"你的攻击力:"<<gongjili<<endl;
cout<<"你的防御力:"<<fangyuli<<endl;
cout<<"你拥有的钱:"<<money<<endl;
}
else
switch(xiaozhen)
{
case 1 : wuqidian();break;
case 2 : yaodian();break;
case 3 : guaiwu1();break;
case 4 : guaiwu2();break;
default : cout<<"请不要乱选!"<<endl;break;
}
cin>>xiaozhen;
}
if(xiaozhen==5)
{
cout<<"正在退出游戏……"<<endl;
}
cin.get();
cin.get();
return 0;
}
void wuqidian()
{
cout<<"欢迎来到武器店!"<<endl;
cout<<"1、买小刀(1M加2攻击力)"<<endl;
cout<<"2、买短剑(2M加20攻击力)"<<endl;
cout<<"3、买大砍刀(5M加40攻击力)"<<endl;
cout<<"4、买双节棍(7M加60攻击力)"<<endl;
cout<<"5、买盾牌(2M加30防御力)"<<endl;
cout<<"6、买铠甲(5M加60防御力)"<<endl;
cout<<"7、离开武器店"<<endl;
int wuqidian;
cin>>wuqidian;
while(wuqidian!=7)//输入7时结束函数
{
switch(wuqidian)
{
case 1 : if(money<10)
cout<<"你的钱不够"<<endl;//钱不够时返回Flase
else
cout<<"购买成功!"<<endl;//钱足够时返回True
gongjili+=2;
money-=1;
break;
case 2 : if(money<80)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
gongjili+=20;
money-=80;
break;
case 3 : if(money<140)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
gongjili+=40;
money-=140;
break;
case 4 : if(money<200)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
gongjili+=60;
money-=200;
break;
case 5 : if(money<60)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
fangyuli+=30;
money-=60;
break;
fangyuli+=60;
money-=100;
break;
default : cout<<"无"<<endl;
break;
}
cin>>wuqidian;
}
if(wuqidian==7)
{ //返回main()主函数
cout<<"欢迎下次再来!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
}
/*
yaodian()的设置与wuqidian()相同,可参照阅读.
*/
void yaodian()
{
cout<<"欢迎来到药品店!"<<endl;
cout<<"1、买1号补血药(10M加200生命)"<<endl;
cout<<"2、买2号补血药(50M加1000生命力)"<<endl;
cout<<"3、买3号补血药(100M加2200生命力)"<<endl;
cout<<"4、离开武器店"<<endl;
int yaodian;
cin>>yaodian;
while(yaodian!=4)
{
switch(yaodian)
{
case 1 : if(money<10)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
shengmingli+=200;
money-=10;
break;
case 2 : if(money<50)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
shengmingli+=1000;
money-=50;
break;
case 3 : if(money<100)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
shengmingli+=2200;
money-=100;
break;
default : cout<<"无"<<endl;
break;
}
cin>>yaodian;
}
if(yaodian==4)
{
cout<<"欢迎下次再来!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
}
/*这里是两个战斗函数,使用指针来处理.避免造成内存崩溃.*/
void guaiwu1()
{
cout<<"开始与小怪物战斗!!!"<<endl;
double* g_shengmingli=new double;//定义怪物生命
int* g_gongjili=new int;//定义怪物攻击力
int* g_fangyuli=new int;//定义怪物防御力
int* g_money=new int;//定义怪物金钱
*g_shengmingli=100;
*g_gongjili=5;
*g_fangyuli=3;
*g_money=5;
double* tongji1=new double;//用来计算主角对怪物的杀伤
double* tongji2=new double;//用来计算怪物对主角的杀伤
*tongji1=0;
*tongji2=0;
int* huihe=new int;//定义回合数
*huihe=1;
cout<<"你开始对小怪物进行攻击!"<<endl;
int* xuanze=new int;
/*
攻击计算公式
杀伤=攻击力*2-防御力
玩家每回合可以选择攻击与逃跑
*/
while((*g_shengmingli)>0 && shengmingli>0 && (*xuanze)!=2)
{
cout<<"现在是"<<"第"<<*huihe<<"回合!"<<endl;
cout<<"请选择你的动作:\n";
cout<<"1、攻击\n2、逃跑\n";
cin>>*xuanze;
switch((*xuanze))
{
case 1 : cout<<"你对小怪物发动了攻击!"<<endl;
*g_shengmingli-=gongjili*2-(*g_fangyuli);
*tongji1=gongjili*2-(*g_fangyuli);
cout<<"你打掉了小怪物"<<*tongji1<<"的生命!"<<endl;
cout<<"小怪物还剩"<<(*g_shengmingli)-(*tongji1)<<"点生命"<<endl;
shengmingli-=(*g_gongjili)*2-fangyuli;
*tongji2=(*g_gongjili)*2-fangyuli;
cout<<"小怪物对你发动了攻击!"<<endl;
cout<<"小怪物打掉了你"<<*tongji2<<"的生命!"<<endl;
cout<<"你还剩"<<shengmingli-(*tongji2)<<"点生命"<<endl;break;
case 2 : cout<<"你决定逃跑!"<<endl;
cout<<"逃跑成功!"<<endl;continue;
default : cout<<"请不要乱选!"<<endl;
}
(*huihe)++;
}
if((*g_shengmingli)<=0)
{//杀死怪物后的返回
cout<<"小怪物被你杀死了!你真厉害!!!"<<endl;
money+=(*g_money);
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
else
if(shengmingli<=0)
{//被怪物杀死后的返回
cout<<"你被小怪物杀死了!游戏结束!!!"<<endl;
}
else
if((*xuanze)==2)
{//逃跑的返回
cout<<"你逃回了小镇!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
delete g_shengmingli;
delete g_gongjili;
delete g_fangyuli;
delete g_money;
delete tongji1;
delete tongji2;
}
/*
设置均与void函数guaiwu1()相同,可参照上例阅读.
*/
void guaiwu2()
{
cout<<"开始与大怪物战斗!!!"<<endl;
double* g_shengmingli=new double;
int* g_gongjili=new int;
int* g_fangyuli=new int;
*g_shengmingli=3600;
*g_gongjili=500;
*g_fangyuli=500;
double* tongji1=new double;
double* tongji2=new double;
*tongji1=0;
*tongji2=0;
int* huihe=new int;
*huihe=1;
cout<<"你开始对大怪物进行攻击!"<<endl;
int* xuanze=new int;
while((*g_shengmingli)>0 && shengmingli>0 && (*xuanze)!=2)
{
cout<<"现在是"<<"第"<<*huihe<<"回合!"<<endl;
cout<<"请选择你的动作:\n";
cout<<"1、攻击\n2、逃跑\n";
cin>>*xuanze;
switch((*xuanze))
{
case 1 : cout<<"你对大怪物发动了攻击!"<<endl;
*g_shengmingli-=gongjili*2-(*g_fangyuli);
*tongji1=gongjili*2-(*g_fangyuli);
cout<<"你打掉了大怪物"<<*tongji1<<"的生命!"<<endl;
cout<<"大怪物还剩"<<(*g_shengmingli)-(*tongji1)<<"点生命"<<endl;
shengmingli-=(*g_gongjili)*2-fangyuli;
*tongji2=(*g_gongjili)*2-fangyuli;
cout<<"大怪物对你发动了攻击!"<<endl;
cout<<"大怪物打掉了你"<<*tongji2<<"的生命!"<<endl;
cout<<"你还剩"<<shengmingli-(*tongji2)<<"点生命"<<endl;break;
case 2 : cout<<"你决定逃跑!"<<endl;
cout<<"逃跑成功!"<<endl;continue;
default : cout<<"请不要乱选!"<<endl;
}
(*huihe)++;
}
if((*g_shengmingli)<=0)
{
cout<<"大怪物被你杀死了!你真厉害!!!"<<endl;
guoguan=true;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
else
if(shengmingli<=0)
{
cout<<"你被大怪物杀死了!游戏结束!!!"<<endl;
}
else
if((*xuanze)==2)
{
cout<<"你逃回了小镇!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
delete g_shengmingli;
delete g_gongjili;
delete g_fangyuli;
delete tongji1;
delete tongji2;
}
新手天翼
#include <iostream>
using namespace std;
double shengmingli=2000;//定义主角初始生命力
int gongjili=150;//定义主角初始攻击力
int fangyuli=200;//定义主角初始防御力
int money=20;//定义主角初始金钱数量
bool guoguan;//定义是否通关判定
void wuqidian();//定义武器店函数
void yaodian();//定义药店函数
void guaiwu1();//定义小怪物函数
void guaiwu2();//定义大怪物函数
int main()
{
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
int xiaozhen;//定义选择项目
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
cin>>xiaozhen;
while(xiaozhen!=5)//输入5时退出游戏
{
if(shengmingli<=0)//主角生命力小于等于0时游戏结束
{
cout<<"你死啦!"<<endl;
break;
}
if(guoguan)
{
cout<<"恭喜通关!"<<endl;
break;
}
if(xiaozhen==6)//输入6可检测自己的状态
{
cout<<"你的生命力:"<<shengmingli<<endl;
cout<<"你的攻击力:"<<gongjili<<endl;
cout<<"你的防御力:"<<fangyuli<<endl;
cout<<"你拥有的钱:"<<money<<endl;
}
else
switch(xiaozhen)
{
case 1 : wuqidian();break;
case 2 : yaodian();break;
case 3 : guaiwu1();break;
case 4 : guaiwu2();break;
default : cout<<"请不要乱选!"<<endl;break;
}
cin>>xiaozhen;
}
if(xiaozhen==5)
{
cout<<"正在退出游戏……"<<endl;
}
cin.get();
cin.get();
return 0;
}
void wuqidian()
{
cout<<"欢迎来到武器店!"<<endl;
cout<<"1、买小刀(1M加2攻击力)"<<endl;
cout<<"2、买短剑(2M加20攻击力)"<<endl;
cout<<"3、买大砍刀(5M加40攻击力)"<<endl;
cout<<"4、买双节棍(7M加60攻击力)"<<endl;
cout<<"5、买盾牌(2M加30防御力)"<<endl;
cout<<"6、买铠甲(5M加60防御力)"<<endl;
cout<<"7、离开武器店"<<endl;
int wuqidian;
cin>>wuqidian;
while(wuqidian!=7)//输入7时结束函数
{
switch(wuqidian)
{
case 1 : if(money<10)
cout<<"你的钱不够"<<endl;//钱不够时返回Flase
else
cout<<"购买成功!"<<endl;//钱足够时返回True
gongjili+=2;
money-=1;
break;
case 2 : if(money<80)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
gongjili+=20;
money-=80;
break;
case 3 : if(money<140)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
gongjili+=40;
money-=140;
break;
case 4 : if(money<200)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
gongjili+=60;
money-=200;
break;
case 5 : if(money<60)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
fangyuli+=30;
money-=60;
break;
fangyuli+=60;
money-=100;
break;
default : cout<<"无"<<endl;
break;
}
cin>>wuqidian;
}
if(wuqidian==7)
{ //返回main()主函数
cout<<"欢迎下次再来!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
}
/*
yaodian()的设置与wuqidian()相同,可参照阅读.
*/
void yaodian()
{
cout<<"欢迎来到药品店!"<<endl;
cout<<"1、买1号补血药(10M加200生命)"<<endl;
cout<<"2、买2号补血药(50M加1000生命力)"<<endl;
cout<<"3、买3号补血药(100M加2200生命力)"<<endl;
cout<<"4、离开武器店"<<endl;
int yaodian;
cin>>yaodian;
while(yaodian!=4)
{
switch(yaodian)
{
case 1 : if(money<10)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
shengmingli+=200;
money-=10;
break;
case 2 : if(money<50)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
shengmingli+=1000;
money-=50;
break;
case 3 : if(money<100)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
shengmingli+=2200;
money-=100;
break;
default : cout<<"无"<<endl;
break;
}
cin>>yaodian;
}
if(yaodian==4)
{
cout<<"欢迎下次再来!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
}
/*这里是两个战斗函数,使用指针来处理.避免造成内存崩溃.*/
void guaiwu1()
{
cout<<"开始与小怪物战斗!!!"<<endl;
double* g_shengmingli=new double;//定义怪物生命
int* g_gongjili=new int;//定义怪物攻击力
int* g_fangyuli=new int;//定义怪物防御力
int* g_money=new int;//定义怪物金钱
*g_shengmingli=100;
*g_gongjili=5;
*g_fangyuli=3;
*g_money=5;
double* tongji1=new double;//用来计算主角对怪物的杀伤
double* tongji2=new double;//用来计算怪物对主角的杀伤
*tongji1=0;
*tongji2=0;
int* huihe=new int;//定义回合数
*huihe=1;
cout<<"你开始对小怪物进行攻击!"<<endl;
int* xuanze=new int;
/*
攻击计算公式
杀伤=攻击力*2-防御力
玩家每回合可以选择攻击与逃跑
*/
while((*g_shengmingli)>0 && shengmingli>0 && (*xuanze)!=2)
{
cout<<"现在是"<<"第"<<*huihe<<"回合!"<<endl;
cout<<"请选择你的动作:\n";
cout<<"1、攻击\n2、逃跑\n";
cin>>*xuanze;
switch((*xuanze))
{
case 1 : cout<<"你对小怪物发动了攻击!"<<endl;
*g_shengmingli-=gongjili*2-(*g_fangyuli);
*tongji1=gongjili*2-(*g_fangyuli);
cout<<"你打掉了小怪物"<<*tongji1<<"的生命!"<<endl;
cout<<"小怪物还剩"<<(*g_shengmingli)-(*tongji1)<<"点生命"<<endl;
shengmingli-=(*g_gongjili)*2-fangyuli;
*tongji2=(*g_gongjili)*2-fangyuli;
cout<<"小怪物对你发动了攻击!"<<endl;
cout<<"小怪物打掉了你"<<*tongji2<<"的生命!"<<endl;
cout<<"你还剩"<<shengmingli-(*tongji2)<<"点生命"<<endl;break;
case 2 : cout<<"你决定逃跑!"<<endl;
cout<<"逃跑成功!"<<endl;continue;
default : cout<<"请不要乱选!"<<endl;
}
(*huihe)++;
}
if((*g_shengmingli)<=0)
{//杀死怪物后的返回
cout<<"小怪物被你杀死了!你真厉害!!!"<<endl;
money+=(*g_money);
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
else
if(shengmingli<=0)
{//被怪物杀死后的返回
cout<<"你被小怪物杀死了!游戏结束!!!"<<endl;
}
else
if((*xuanze)==2)
{//逃跑的返回
cout<<"你逃回了小镇!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
delete g_shengmingli;
delete g_gongjili;
delete g_fangyuli;
delete g_money;
delete tongji1;
delete tongji2;
}
/*
设置均与void函数guaiwu1()相同,可参照上例阅读.
*/
void guaiwu2()
{
cout<<"开始与大怪物战斗!!!"<<endl;
double* g_shengmingli=new double;
int* g_gongjili=new int;
int* g_fangyuli=new int;
*g_shengmingli=3600;
*g_gongjili=500;
*g_fangyuli=500;
double* tongji1=new double;
double* tongji2=new double;
*tongji1=0;
*tongji2=0;
int* huihe=new int;
*huihe=1;
cout<<"你开始对大怪物进行攻击!"<<endl;
int* xuanze=new int;
while((*g_shengmingli)>0 && shengmingli>0 && (*xuanze)!=2)
{
cout<<"现在是"<<"第"<<*huihe<<"回合!"<<endl;
cout<<"请选择你的动作:\n";
cout<<"1、攻击\n2、逃跑\n";
cin>>*xuanze;
switch((*xuanze))
{
case 1 : cout<<"你对大怪物发动了攻击!"<<endl;
*g_shengmingli-=gongjili*2-(*g_fangyuli);
*tongji1=gongjili*2-(*g_fangyuli);
cout<<"你打掉了大怪物"<<*tongji1<<"的生命!"<<endl;
cout<<"大怪物还剩"<<(*g_shengmingli)-(*tongji1)<<"点生命"<<endl;
shengmingli-=(*g_gongjili)*2-fangyuli;
*tongji2=(*g_gongjili)*2-fangyuli;
cout<<"大怪物对你发动了攻击!"<<endl;
cout<<"大怪物打掉了你"<<*tongji2<<"的生命!"<<endl;
cout<<"你还剩"<<shengmingli-(*tongji2)<<"点生命"<<endl;break;
case 2 : cout<<"你决定逃跑!"<<endl;
cout<<"逃跑成功!"<<endl;continue;
default : cout<<"请不要乱选!"<<endl;
}
(*huihe)++;
}
if((*g_shengmingli)<=0)
{
cout<<"大怪物被你杀死了!你真厉害!!!"<<endl;
guoguan=true;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
else
if(shengmingli<=0)
{
cout<<"你被大怪物杀死了!游戏结束!!!"<<endl;
}
else
if((*xuanze)==2)
{
cout<<"你逃回了小镇!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
delete g_shengmingli;
delete g_gongjili;
delete g_fangyuli;
delete tongji1;
delete tongji2;
}
资深天翼
#include <iostream>
using namespace std;
double shengmingli=2000;//定义主角初始生命力
int gongjili=150;//定义主角初始攻击力
int fangyuli=200;//定义主角初始防御力
int money=20;//定义主角初始金钱数量
bool guoguan;//定义是否通关判定
void wuqidian();//定义武器店函数
void yaodian();//定义药店函数
void guaiwu1();//定义小怪物函数
void guaiwu2();//定义大怪物函数
int main()
{
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
int xiaozhen;//定义选择项目
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
cin>>xiaozhen;
while(xiaozhen!=5)//输入5时退出游戏
{
if(shengmingli<=0)//主角生命力小于等于0时游戏结束
{
cout<<"你死啦!"<<endl;
break;
}
if(guoguan)
{
cout<<"恭喜通关!"<<endl;
break;
}
if(xiaozhen==6)//输入6可检测自己的状态
{
cout<<"你的生命力:"<<shengmingli<<endl;
cout<<"你的攻击力:"<<gongjili<<endl;
cout<<"你的防御力:"<<fangyuli<<endl;
cout<<"你拥有的钱:"<<money<<endl;
}
else
switch(xiaozhen)
{
case 1 : wuqidian();break;
case 2 : yaodian();break;
case 3 : guaiwu1();break;
case 4 : guaiwu2();break;
default : cout<<"请不要乱选!"<<endl;break;
}
cin>>xiaozhen;
}
if(xiaozhen==5)
{
cout<<"正在退出游戏……"<<endl;
}
cin.get();
cin.get();
return 0;
}
void wuqidian()
{
cout<<"欢迎来到武器店!"<<endl;
cout<<"1、买小刀(1M加2攻击力)"<<endl;
cout<<"2、买短剑(2M加20攻击力)"<<endl;
cout<<"3、买大砍刀(5M加40攻击力)"<<endl;
cout<<"4、买双节棍(7M加60攻击力)"<<endl;
cout<<"5、买盾牌(2M加30防御力)"<<endl;
cout<<"6、买铠甲(5M加60防御力)"<<endl;
cout<<"7、离开武器店"<<endl;
int wuqidian;
cin>>wuqidian;
while(wuqidian!=7)//输入7时结束函数
{
switch(wuqidian)
{
case 1 : if(money<10)
cout<<"你的钱不够"<<endl;//钱不够时返回Flase
else
cout<<"购买成功!"<<endl;//钱足够时返回True
gongjili+=2;
money-=1;
break;
case 2 : if(money<80)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
gongjili+=20;
money-=80;
break;
case 3 : if(money<140)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
gongjili+=40;
money-=140;
break;
case 4 : if(money<200)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
gongjili+=60;
money-=200;
break;
case 5 : if(money<60)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
fangyuli+=30;
money-=60;
break;
fangyuli+=60;
money-=100;
break;
default : cout<<"无"<<endl;
break;
}
cin>>wuqidian;
}
if(wuqidian==7)
{ //返回main()主函数
cout<<"欢迎下次再来!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
}
/*
yaodian()的设置与wuqidian()相同,可参照阅读.
*/
void yaodian()
{
cout<<"欢迎来到药品店!"<<endl;
cout<<"1、买1号补血药(10M加200生命)"<<endl;
cout<<"2、买2号补血药(50M加1000生命力)"<<endl;
cout<<"3、买3号补血药(100M加2200生命力)"<<endl;
cout<<"4、离开武器店"<<endl;
int yaodian;
cin>>yaodian;
while(yaodian!=4)
{
switch(yaodian)
{
case 1 : if(money<10)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
shengmingli+=200;
money-=10;
break;
case 2 : if(money<50)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
shengmingli+=1000;
money-=50;
break;
case 3 : if(money<100)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
shengmingli+=2200;
money-=100;
break;
default : cout<<"无"<<endl;
break;
}
cin>>yaodian;
}
if(yaodian==4)
{
cout<<"欢迎下次再来!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
}
/*这里是两个战斗函数,使用指针来处理.避免造成内存崩溃.*/
void guaiwu1()
{
cout<<"开始与小怪物战斗!!!"<<endl;
double* g_shengmingli=new double;//定义怪物生命
int* g_gongjili=new int;//定义怪物攻击力
int* g_fangyuli=new int;//定义怪物防御力
int* g_money=new int;//定义怪物金钱
*g_shengmingli=100;
*g_gongjili=5;
*g_fangyuli=3;
*g_money=5;
double* tongji1=new double;//用来计算主角对怪物的杀伤
double* tongji2=new double;//用来计算怪物对主角的杀伤
*tongji1=0;
*tongji2=0;
int* huihe=new int;//定义回合数
*huihe=1;
cout<<"你开始对小怪物进行攻击!"<<endl;
int* xuanze=new int;
/*
攻击计算公式
杀伤=攻击力*2-防御力
玩家每回合可以选择攻击与逃跑
*/
while((*g_shengmingli)>0 && shengmingli>0 && (*xuanze)!=2)
{
cout<<"现在是"<<"第"<<*huihe<<"回合!"<<endl;
cout<<"请选择你的动作:\n";
cout<<"1、攻击\n2、逃跑\n";
cin>>*xuanze;
switch((*xuanze))
{
case 1 : cout<<"你对小怪物发动了攻击!"<<endl;
*g_shengmingli-=gongjili*2-(*g_fangyuli);
*tongji1=gongjili*2-(*g_fangyuli);
cout<<"你打掉了小怪物"<<*tongji1<<"的生命!"<<endl;
cout<<"小怪物还剩"<<(*g_shengmingli)-(*tongji1)<<"点生命"<<endl;
shengmingli-=(*g_gongjili)*2-fangyuli;
*tongji2=(*g_gongjili)*2-fangyuli;
cout<<"小怪物对你发动了攻击!"<<endl;
cout<<"小怪物打掉了你"<<*tongji2<<"的生命!"<<endl;
cout<<"你还剩"<<shengmingli-(*tongji2)<<"点生命"<<endl;break;
case 2 : cout<<"你决定逃跑!"<<endl;
cout<<"逃跑成功!"<<endl;continue;
default : cout<<"请不要乱选!"<<endl;
}
(*huihe)++;
}
if((*g_shengmingli)<=0)
{//杀死怪物后的返回
cout<<"小怪物被你杀死了!你真厉害!!!"<<endl;
money+=(*g_money);
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
else
if(shengmingli<=0)
{//被怪物杀死后的返回
cout<<"你被小怪物杀死了!游戏结束!!!"<<endl;
}
else
if((*xuanze)==2)
{//逃跑的返回
cout<<"你逃回了小镇!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
delete g_shengmingli;
delete g_gongjili;
delete g_fangyuli;
delete g_money;
delete tongji1;
delete tongji2;
}
/*
设置均与void函数guaiwu1()相同,可参照上例阅读.
*/
void guaiwu2()
{
cout<<"开始与大怪物战斗!!!"<<endl;
double* g_shengmingli=new double;
int* g_gongjili=new int;
int* g_fangyuli=new int;
*g_shengmingli=3600;
*g_gongjili=500;
*g_fangyuli=500;
double* tongji1=new double;
double* tongji2=new double;
*tongji1=0;
*tongji2=0;
int* huihe=new int;
*huihe=1;
cout<<"你开始对大怪物进行攻击!"<<endl;
int* xuanze=new int;
while((*g_shengmingli)>0 && shengmingli>0 && (*xuanze)!=2)
{
cout<<"现在是"<<"第"<<*huihe<<"回合!"<<endl;
cout<<"请选择你的动作:\n";
cout<<"1、攻击\n2、逃跑\n";
cin>>*xuanze;
switch((*xuanze))
{
case 1 : cout<<"你对大怪物发动了攻击!"<<endl;
*g_shengmingli-=gongjili*2-(*g_fangyuli);
*tongji1=gongjili*2-(*g_fangyuli);
cout<<"你打掉了大怪物"<<*tongji1<<"的生命!"<<endl;
cout<<"大怪物还剩"<<(*g_shengmingli)-(*tongji1)<<"点生命"<<endl;
shengmingli-=(*g_gongjili)*2-fangyuli;
*tongji2=(*g_gongjili)*2-fangyuli;
cout<<"大怪物对你发动了攻击!"<<endl;
cout<<"大怪物打掉了你"<<*tongji2<<"的生命!"<<endl;
cout<<"你还剩"<<shengmingli-(*tongji2)<<"点生命"<<endl;break;
case 2 : cout<<"你决定逃跑!"<<endl;
cout<<"逃跑成功!"<<endl;continue;
default : cout<<"请不要乱选!"<<endl;
}
(*huihe)++;
}
if((*g_shengmingli)<=0)
{
cout<<"大怪物被你杀死了!你真厉害!!!"<<endl;
guoguan=true;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
else
if(shengmingli<=0)
{
cout<<"你被大怪物杀死了!游戏结束!!!"<<endl;
}
else
if((*xuanze)==2)
{
cout<<"你逃回了小镇!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏!\n";
cout<<"小镇\n";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"<<endl;
cout<<"和一家武器店。\n";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
delete g_shengmingli;
delete g_gongjili;
delete g_fangyuli;
delete tongji1;
delete tongji2;
}