话不多说,上干货
1.苍穹世界
#include<stdio.h>
#include<ctime>
#include<time.h> //suiji
#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,200*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;
int jingyancao=0,jingyanbao=0,jingyanshi=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];
Sleep(1000);
printf("--------------------------欢迎来到 [苍穹世界] 2.2 测试版-----------------------\n\n\n");
//如果想使用外挂,名字请输入:“圣战斗士 ”。
Sleep(1000);
printf("这里是苍穹世界! 雅莉萨斯国的罗茜公主被陌生人绑架了!\n\n\n 伟大的勇者啊~拿起你们的武器,营救公主!\n\n\n输入你的名字: (20个字符)\n\n\n");
scanf("%s",player_name);
strncpy(player.name,player_name,20);
if(strcmp(player.name,"杨子誉")==0)
{
printf("\n\n\n封印多年的杨子誉血统啊!你终于觉醒了!\n\n\n杨子誉,你成为了天选之人,请你救出公主吧!\n\n\n");
player.attack=9999;
player.defense=99999;
player.health=99999;
player.max_health=99999;
}
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个 8,经验草%d个 9,经验包%d个 10,经验石%d个 11,巨人晶石%d个 0,返回\n\n\n",cao,jijiubao,baiyao,superbaiyao,boom,dubiao,atom_boom,jingyancao,jingyanbao,jingyanshi,strongman_arm);
switch(scanf("%d",&choose_number),choose_number)
{
case 1:
if(cao>0)
{
printf("使用止血草,HP增加60\n\n\n");
cao--;
if(player.health+60>player.max_health)player.health=player.max_health;
else player.health+=60;
}
else printf("没有止血草了\n\n\n");
break;
case 2:
if(jijiubao>0)
{
printf("使用急救包,HP增加80\n\n\n");
jijiubao--;
if(player.health+80>player.max_health)player.health=player.max_health;
else player.health+=80;
}
else printf("没有急救包了\n\n\n");
break;
case 3:
if(baiyao>0)
{
printf("使用云南白药,HP增加120\nz\n\n");
baiyao--;
if(player.health+120>player.max_health)player.health=player.max_health;
else player.health+=120;
}
else printf("没有云南白药了\n\n\n");
break;
case 4:
if(superbaiyao>0)
{
printf("使用超级云南白药,HP增加200\n\n\n");
superbaiyao--;
if(player.health+200>player.max_health)player.health=player.max_health;
else player.health+=200;
}
else printf("没有超级云南白药了\n\n\n");
break;
case 5:
if(battle) //在战斗中(battle=1),否则(battle=0)不能使用攻击性物品
{
if(boom>0)
{
printf("使用手雷,敌人HP减少100\n\n\n");
boom--;
guai.health-=100;
AttackResult();
}
}
else printf("非战斗状态,不能使用手雷!\n\n\n");
break;
case 6:
if(battle) //在战斗中(battle=1),否则(battle=0)不能使用攻击性物品
{
if(dubiao>0)
{
printf("使用毒标,敌人HP减少200\n\n\n");
dubiao--;
guai.health-=200;
AttackResult();
}
}
else printf("非战斗状态,不能使用毒标!\n\n\n");
break;
case 7:
if(battle) //在战斗中(battle=1),否则(battle=0)不能使用攻击性物品
{
if(atom_boom>0)
{
printf("使用手抛式原子弹,敌人HP减少666666666\n\n\n");
atom_boom--;
guai.health-=666666666;
AttackResult();
}
}
else printf("非战斗状态,不能使用手抛式原子弹!\n\n\n");
break;
case 8:
if(jingyancao>0 && player.level<1000)
{
printf("使用经验草,等级增加10级\n\n\n");
jingyancao--;
player.level+=10;
printf("等级:%d\n",player.level);
}
else if(jingyancao<1)
{
printf("没有经验草了\n\n\n");
}
else printf("等级超过45级,修为太高,无法使用。\n\n\n");
break;
case 9:
if(jingyanbao>0 && player.level<1000)
{
if(player.level>44&&player.level<1000)
{
int sheng;
sheng=45-player.level;
player.level+=sheng;
printf("使用经验包,等级增加%d级",sheng);
printf("等级:%d\n",player.level);
}
else
{
printf("使用经验包,等级增加2级\n\n\n");
jingyanbao--;
player.level+=2;
printf("等级:%d\n",player.level);
}
}
else if(jingyanbao<1)
{
printf("没有经验包了");
}
else printf("等级超过45级,修为太高,无法使用。\n\n\n");
break;
case 10:
if(jingyanshi>0 && player.level<1000)
{
if(player.level>42&&player.level<1000)
{
int sheng;
sheng=45-player.level;
player.level+=sheng;
printf("使用经验石,等级增加%d级\n",sheng);
printf("等级:%d\n",player.level);
}
else
{
printf("使用经验石,等级增加10级\n");
jingyanshi--;
player.level+=10;
}
}
else if(jingyanshi<1)
{
printf("没有经验石了\n\n\n");
}
else printf("等级超过45级,修为太高,无法使用。\n\n\n");
break;
case 11:
if(strongman_arm>0 && player.level<10000)
{
if(player.level>29&&player.level<10000)
{
int sheng;
sheng=45-player.level;
player.level+=sheng;
printf("使用巨人晶石,等级增加%d级",sheng);
printf("等级:%d\n",player.level);
}
else
{
printf("使用巨人晶石,等级增加16级\n\n\n");
strongman_arm--;
player.level+=16;
printf("等级:%d\n",player.level);
}
}
else if(strongman_arm<1)
{
printf("没有巨人晶石了。\n\n\n");
}
else printf("等级超过45级,修为太高,无法使用。\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)
{
printf("从敌人尸骸中发现");
printf("%s\n\n\n",guai.wupin);
AddWupin(guai.wupin_sign);
}
WhetherLevelUp();
if(strcmp(guai.name,"使徒")==0)
{
printf("战斗胜利,救出公主!!!");
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);
printf(" 升级!\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-((player.exp+guai.exp) || player.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);
printf(" 升级!\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);
printf(" 升级!\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,装备 6,关于游戏 0,退出游戏\n\n\n");
puts("=============================================================================");
switch(scanf("%d",&choose_number),choose_number)
{
case 1: //显示移动菜单
printf("要去哪里?\n\n\n");
printf("1,happy酒吧 2,诺亚方舟酒店 3,北朝商会 4,红玉拍卖行 5,冒险荒野\n\n\n");
switch(scanf("%d",&choose_number),choose_number)
{
case 1:
place_sign=place.bar; //记录目前位置-酒吧
// OrdinaryAct();
break;
case 2:
place_sign=place.hotel; //进入旅店
printf("金币:%d",money);
printf("要开房吗? 200个金币 1,是 0,否\n\n\n");
choose_number=1;
switch(scanf("%d",&choose_number),choose_number)
{
case 1:
if(money-200<0) //判断钱是否够
{
printf("Sorry,你的钱不够~\n\n\n");
printf("金币:%d",money);
}
else
{
printf("好好休息\nHP满\n第二天了\n\n");
printf("金币:%d\n",money);
money-=200; //花费200住店费
player.health=player.max_health; //体力满
}
break;
case 0:
printf("下次再来!\n\n\n");
break;
default:
printf("hotel talk error!\n\n\n");
}
place_sign=0;
break;
case 3:
int yongju,gong,fang;
printf("请问您要购买什么类型的物品?\n\n\n 1,攻击装备 2,防御装备 3,一次性伤害武器\n\n\n");
scanf("%d",&yongju);
switch(yongju)
{
case 1:
printf("请问您要购买什么武器?\n\n\n 1,匕首¥300 2,长剑¥500 3,碧血剑¥1000\n\n\n");
scanf("%d",&gong);
switch(gong)
{
case 1:
if(money>=300)
{
gong1n++;
money=money-300;
printf ("匕首+1\n");
printf("匕首:%d个\n",gong1n);
printf("金币:%d\n",money);
break;
}
else
{
printf("钱不够!\n");
printf("金币:%d\n",money);
break;
}
case 2:
if(money>=500)
{
gong2n++;
money=money-500;
printf ("长剑+1\n");
printf("长剑:%d个\n",gong2n);
printf("金币:%d\n",money);
break;
}
else
{
printf("钱不够!\n");
printf("金币:%d\n",money);
break;
}
case 3:
if(money>=1000)
{
gong3n++;
money=money-1000;
printf ("碧血剑+1\n");
printf("碧血剑:%d个\n",gong3n);
printf("金币:%d\n",money);
break;
}
else
{
printf("钱不够!\n");
printf("金币:%d\n",money);
break;
}
default:
printf("对不起,我们只会打造以上武器。");
break;
}
break;
case 2:
int fang;
printf("请问您要购买什么防具?\n\n\n 1,布衣¥300 2,铁甲¥500 3,银甲¥1000\n\n\n");
scanf("%d",&fang);
switch(fang)
{
case 1:
if(money>=300)
{
fang1n++;
money=money-300;
printf ("布衣+1\n");
printf("布衣:%d个\n",fang1n);
printf("金币:%d\n",money);
}
else
{
printf("钱不够!\n");
printf("金币:%d\n",money);
}
break;
case 2:
if(money>=500)
{
fang2n++;
money=money-500;
printf ("铁甲+1\n");
printf("铁甲:%d个\n",fang2n);
printf("金币:%d\n",money);
}
else
{
printf("钱不够!\n");
printf("金币:%d",money);
}
break;
case 3:
if(money>=1000)
{
fang3n++;
money=money-1000;
printf ("银甲+1\n");
printf("银甲:%d个\n",fang3n);
printf("金币:%d\n",money);
}
else
{
printf("钱不够!\n");
printf("金币:%d\n",money);
}
default:
printf("对不起,我们只会打造以上防具。");
break;
}
printf("金币:%d\n",money);
break;
case 3:
printf("请问您要购买什么一次性伤害武器?\n 1,手雷 2,毒镖 3,手抛式原子弹\n\n\n");
int yi;
scanf("%d",&yi);
switch(yi)
{
case 1:
if(money>=300 && boom<5)
{
boom++;
money=money-300;
printf("手雷+1\n");
printf("手雷:%d\n",boom);
printf("金币:%d\n",money);
}
else
{
printf("钱不够!\n");
printf("金币:%d",money);
}
break;
case 2:
if(money>=600 && dubiao<4)
{
dubiao++;
money=money-600;
printf("毒镖+1\n");
printf("毒镖:%d\n",dubiao);
printf("金币:%d\n",money);
}
else
{
printf("钱不够!\n");
printf("金币:%d\n",money);
}
break;
case 3:
if(money>=0 && atom_boom<23333333333)
{
atom_boom=atom_boom+233;
money=money+1500;
printf("手抛式原子弹+2\n");
printf("手抛式原子弹:%d\n",atom_boom);
printf("金币:%d\n",money);
}
else
{
printf("钱不够!\n\n\n");
printf("金币:%d\n",money);
}
break;
}
}
break;
case 4:
printf ("欢迎您光临本拍卖行,请问您要卖什么东西?\n\n");
printf("攻击装备: 1,匕首:%d个 2,长剑:%d个 3,碧血剑:%d个 4,绝世好剑:%d个\n",gong1n,gong2n,gong3n,gong4n);
printf("防御装备: 5,布衣:%d个 6,铁甲:%d个 7,银甲:%d个 8,黄金圣衣:%d个\n9,巨人晶石:%d个 0,返回\n\n\n",fang1n,fang2n,fang3n,fang4n,strongman_arm);
int pai,shu,i;
scanf("%d",&pai);
switch(pai)
{
case 1:
printf("请问您要出售几件?");
scanf("%d",&shu);
if(gong1n>=shu)
{
gong1n=gong1n-shu;
money=money+shu*240;
printf("匕首:%d\n",gong1n);
printf("金币:%d\n",money);
break;
}
else
{
printf("装备数不够,无法出售!\n");
break;
}
break;
case 2:
printf("请问您要出售几件?\n");
scanf("%d",&shu);
if(gong2n>=shu)
{
gong2n=gong2n-shu;
money=money+shu*400;
printf("长剑:%d\n",gong2n);
printf("金币:%d\n",money);
break;
}
else
{
printf("装备数不够,无法出售!\n");
break;
}
case 3:
printf("请问您要出售几件?\n");
scanf("%d",&shu);
if(gong3n>=shu)
{
gong3n=gong3n-shu;
money=money+shu*800;
printf("碧血剑:%d\n",gong3n);
printf("金币:%d\n",money);
break;
}
else
{
printf("装备数不够,无法出售!\n");
break;
}
case 4:
printf("请问您要出售几件?\n");
scanf("%d",&shu);
if(gong4n>=shu)
{
gong4n=gong4n-shu;
money=money+shu*1500;
printf("绝世好剑:%d\n",gong4n);
printf("金币:%d\n",money);
break;
}
else
{
printf("装备数不够,无法出售!\n");
break;
}
case 5:
printf("请问您要出售几件?\n");
scanf("%d",&shu);
if(fang1n>=shu)
{
fang1n=fang1n-shu;
money=money+shu*240;
printf("布衣:%d\n",fang1n);
printf("金币:%d\n",money);
break;
}
else
{
printf("装备数不够,无法出售!\n");
break;
}
case 6:
printf("请问您要出售几件?\n");
scanf("%d",&shu);
if(fang2n>=shu)
{
fang2n=fang2n-shu;
money=money+shu*500;
printf("铁甲:%d\n",fang2n);
printf("金币:%d\n",money);
break;
}
else
{
printf("装备数不够,无法出售!\n");
break;
}
case 7:
printf("请问您要出售几件?\n");
scanf("%d",&shu);
if(fang3n>=shu)
{
fang3n=fang3n-shu;
money=money+shu*800;
printf("银甲:%d\n",fang3n);
printf("金币:%d\n",money);
break;
}
else
{
printf("装备数不够,无法出售!\n");
break;
}
break;
case 8:
printf("请问您要出售几件?\n");
scanf("%d",&shu);
if(fang1n>=shu)
{
fang4n=fang4n-shu;
money=money+shu*1500;
printf("黄金圣衣:%d\n",fang4n);
printf("金币:%d\n",money);
break;
}
else
{
printf("装备数不够,无法出售!\n");
break;
}
case 9:
printf("请问您要出售几颗?");
scanf("%d",&shu);
if(strongman_arm>=shu)
{
strongman_arm=strongman_arm-shu;
money=money+shu*2000;
printf("巨人晶石:%d\n",strongman_arm);
printf("金币:%d\n",money);
}
else
{
printf("晶石数不够,无法出售!\n");
break;
}
break;
case 0:
break;
break;
default:
printf("没有该装备,无法出售!\n");
break;
}
break;
case 5:
int yewai;
while(1)
{
puts("=============================================================================");
printf("要去哪冒险呢?");
printf("\n\n 1,神秘沼泽 危险程度:★\n\n 2,星耀草原 危险程度:★\n\n 3,诡异森林 危险程度:★★★\n\n 4,荒漠矿场 危险程度:★★★\n\n 5,炽热炎洞 危险程度:★★★★\n\n 6,花朵宫殿 危险程度:★★★★★\n\n 0,离开\n");
puts("=============================================================================");
scanf("%d",&yewai);
switch(yewai)
{
case 1:
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
{
printf("这里安全\n\n\n");
//不用调用OAct函数,会自动执行OAct函数;
}
break;
case 3:
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
{
printf("这里安全\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
{
printf("这里安全\n\n\n");
}
break;
case 2:
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
{
printf("这里安全\n\n\n");
}
break;
case 4:
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
{
printf("这里安全\n\n\n");
}
break;
case 6:
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)
{
printf("神秘老人:\n\n\n 哈哈,年轻人,做的不错,不过...嘿嘿,你上当啦!巨人晶石我要了,公主你也别想带走!\n\n\n");
guai=shitu;
printf("%s扑了过来!\n\n\n",guai.name);
BattleAct();
}
else printf("神秘老人:\n\n\n 年轻人,你好啊.如果你有巨人晶石,我可以告诉你公主的下落哦~\n\n\n");
}
else
{
printf("这里安全\n\n\n");
}
break;
if(yewai!=0)
{
printf("该区域为未知区域,无法进入。\n\n\n");
break;
}
}
if(yewai==0)
{
break;
printf("已离开荒野。");
}
}
}
break;
case 2:
ChooseWupin();
break; //显示道具,并可以使用.
case 3: //对话选项
if(place_sign==place.bar)
{
printf("要和谁说话?\n\n\n1,红发女郎 2,赏金猎人 3,酒吧老板 4,药品商人\n\n\n"); //显示对话人物
switch(scanf("%d",&choose_number),choose_number)
{
case 1:
printf("红发女郎:\n\n\n 吧台边那个Hunter好帅啊!(~脸红~)\n\n\n听说他经常外出打猎,外面的路他应该很熟悉的!\n\n\n");
break;
case 2:
if(fang1n<1&&gong1n<1)
{
printf("赏金猎人:\n\n\n 你要救公主啊!好胆量!\n\n\n 不过外面的世界很险恶,而且越深越危险,这是匕首和布衣,对你会有些帮助的,拿去吧!\n\n\n");
printf("%s心想:哇,这位大叔人真好啊!\n\n\n)",player.name);
gong1n++;
fang1n++;
}
else printf("赏金猎人:\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)
{
printf("钱不够!");
}
else
{
if(player.health+20<=player.max_health)
{
printf("HP+20.");
money-=25;
player.health+=20;
}
else
{
printf("HP满了");
player.health=player.max_health;
}
}
break;
case 2:
if(money<80)
{
printf("钱不够!");
}
else
{
if(player.health+50<=player.max_health)
{
printf("HP+50.");
money-=80;
player.health+=50;
}
else
{
printf("HP满了");
player.health=player.max_health;
}
}
break;
case 3:
if(money<150)
{
printf("钱不够!");
}
else
{
if(player.health+100<=player.max_health)
{
printf("HP+100.");
money-=150;
player.health+=100;
}
else
{
printf("HP满了");
player.health=player.max_health;
}
}
break;
case 0:
printf("下次再来!\n");
break;
default:
printf("输入错误\n\n\n");
break;
}
break;
}
break;
case 4:
printf("你要干什么?\n\n\n 1,买东西 2,聊天 \n\n\n");
int mai;
scanf("%d",&mai);
if(mai==1)
{
printf("买点什么呢?\n1,止血草¥100 HP+60\n2,急救包¥150 HP+80 \n3,云南白药¥250 HP+120\n4,超级云南白药¥400 HP+200 \n5,经验草¥150 经验+300 \n6,经验包¥600 经验+600\n7,经验石¥500 经验+1000 \n0,拜拜\n");
int dongxi;
scanf("%d",&dongxi);
switch(dongxi)
{
case 1:
if(money>=100&&cao<6)
{
cao++;
money=money-100;
printf ("止血草+1\n");
}
else
{
printf("钱不够!\n");
}
break;
case 2:
if(money>=150&&jijiubao<5)
{
jijiubao++;
money=money-150;
printf ("急救包+1\n");
}
else
{
printf("钱不够!\n");
}
break;
case 3:
if(money>=250&&baiyao<4)
{
baiyao++;
money=money-250;
printf ("云南白药+1\n");
}
else
{
printf("钱不够!\n");
}
break;
case 4:
if(money>=400&&superbaiyao<3)
{
superbaiyao++;
money=money-400;
printf ("超级云南白药+1\n");
}
else
{
printf("钱不够!\n");
}
break;
case 5:
if(money>=150)
{
jingyancao++;
money=money-150;
printf ("经验草+1\n");
}
else
{
printf("钱不够!\n");
}
break;
case 6:
if(money>=300)
{
jingyanbao++;
money=money-300;
printf ("经验包+1\n");
}
else
{
printf("钱不够!\n");
}
break;
case 7:
if(money>=500)
{
jingyanshi++;
money=money+500;
printf ("经验石+1\n");
}
else
{
printf("钱不够!\n");
}
break;
}
case 0:
printf("金币:%d\n",money);
printf("再见,欢迎下次再来!\n");
break;
}
if(mai==2)
{
printf("药品商人:去去去,老子没时间陪你聊。\n");
}
}
}
else if(place_sign==place.hotel)
printf("“老板娘!我...”\n\n\n“我忙着呢,没空理你~”\n\n\n");
else printf("这里好像没人可以聊天\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);
printf("选择要装备的武器或防具:\n\n\n");
switch(scanf("%d",&choose_number),choose_number)
{
case 1:
if(gong1n>=1)
{
printf("拿起了匕首\n\n\n");
gong=gong1;
strcpy(gongname,"匕首");
}
else printf("你没有匕首可以装备\n\n\n");
break;
case 2:
if(gong2n>=1)
{
printf("拿起了长剑\n\n\n");
gong=gong2;
strcpy(gongname,"长剑");
}
else printf("你没有长剑可以装备\n\n\n");
break;
case 3:
if(gong3n>=1)
{
printf("拿起了碧血剑\n\n\n");
gong=gong3;
strcpy(gongname,"碧血剑");
}
else printf("你没有碧血剑可以装备\n\n\n");
break;
case 4:
if(gong4n>=1)
{
printf("拿起了绝世好剑\n\n\n");
gong=gong4;
strcpy(gongname,"绝世好剑");
}
else printf("你没有绝世好剑可以装备\n\n\n");
break;
case 5:
if(fang1n>=1)
{
printf("穿上了布衣\n\n\n");
fang=fang1;
strcpy(fangname,"布衣");
}
else printf("你没有布衣可以装备\n\n\n");
break;
case 6:
if(fang2>=1)
{
printf("穿上了铁甲\n\n\n");
fang=fang2;
strcpy(fangname,"铁甲");
}
else printf("你没有铁甲可以装备\n\n\n");
break;
case 7:
if(fang3n>=1)
{
printf("穿上了银甲\n\n\n");
fang=fang3;
strcpy(fangname,"银甲");
}
else printf("你没有银甲可以装备\n\n\n");
break;
case 8:
if(fang4n>=1)
{
printf("穿上了黄金圣衣\n\n\n");
fang=fang4;
strcpy(fangname,"黄金圣衣");
}
else printf("你没有黄金圣衣可以装备\n\n\n");
break;
case 0:
printf("未更换装备\n\n\n");
break;
default:
printf("change error!");
}
break;
case 6:
printf(" 您好,欢迎您玩苍穹世界。为了给您更好的游戏体验,本团队时不时会优化本游戏,优化后会尽快发布在网上。关于外挂方面,开启外挂的方式是设定勇者姓名时,输入“圣战斗士 ”(不包括双引号)。由于2.0版本的buy,我们在2.0的基础上进行修改,已修复该buy。并且新增了经验草等有助于升级的道具,希望大家喜欢。在这里要感谢离陌同学,他给了我们许多宝贵的建议,谢谢。\n");
break;
case 0:
printf("确定退出游戏?(Y/N)\n\n\n");
getchar();
proof=getchar();
if(proof=='y'||proof=='Y')
{
printf("数据存储中...");
//向文件中更新数据;
getchar();
printf("按回车退出");
getchar();
return;
}
else if(proof=='n'||proof=='N')printf("继续游戏!\n\n\n");
else printf("继续!\n\n\n");
break;
default:
printf("输入错误!\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:
printf("输入错误,重新输入!\n\n\n");
}
}
}
void printf(char *p)
{
while(1)
{
if(*p!=0)
printf("%c",*p++);
else
break;
Sleep(100);
}
}
2.斗地主
#include<bits/stdc++.h>//打方块 Windows10
#include<windows.h>
using namespace std;
int fen,mb[10][18],leaf;
void kg(int a) {
for(int i=0; i<a; i++)
cout<<' ';
}
void go(int x, int y) {
COORD p;
p.X=(x-1)*2;
p.Y=y-1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),p);
}
void printtu(int x,int y,bool a) {
go(x,y);
cout<<"■";
if(x>2&&x<11) {
go(x-1,y+1);
cout<<"■■■";
} else if(x==2) {
go(x,y+1);
cout<<"■■";
} else if(x==11) {
go(x-1,y+1);
cout<<"■■";
} else;
if(a)
for(int i=0; i<18; i++) {
go(2,i+2);
kg(20);
}
Sleep(100);
go(x,y);
kg(2);
if(x>2&&x<11) {
go(x-1,y+1);
kg(6);
} else if(x==2) {
go(x,y+1);
kg(4);
} else if(x==11) {
go(x-1,y+1);
kg(4);
} else;
go(14,5);
kg(4);
cout<<"\b\b\b\b"<<fen;
if(a)
for(int i=0; i<18; i++) {
go(2,i+2);
for(int o=0; o<10; o++) {
if(mb[o][i])
cout<<"■";
else kg(2);
}
}
}
void sj(int x) {
int i;
for(i=19;; i--) {
go(x,i);
cout<<"■";
Sleep(10);
cout<<"\b\b";
kg(2);
if(i<3)break;
if(mb[x-2][i-3]==1)break;
}
mb[x-2][i-2]=1;
go(x,i);
cout<<"■";
fen-=10;
for(int o=0; o<10; o++)
if(mb[o][i-2]==0)return;
for(int o=0; o<10; o++)
mb[o][i-2]=0;
for(int o=i-2; o<17; o++)
for(int j=0; j<10; j++)
mb[j][o]=mb[j][o+1];
for(int o=0; o<10; o++)
mb[o][17]=0;
printtu(x,20,1);
fen+=100;
}
void mouse(int &x,int &y) {
POINT p;
HWND h=GetForegroundWindow();
GetCursorPos(&p);
ScreenToClient(h,&p);
x=p.x;
y=p.y;
}
void m(int wt) {
lkr:
;
fen=-500;
leaf=8;
srand(time(0));
system("mode con cols=33 lines=24");
system("cls");
cout<<"┌ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┐"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆ 分数"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆ 生命"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆ ";
printf("%c %c %c %c\n",3,3,3,3);
cout<<"┆ ";
kg(20);
cout<<"┆ ";
printf("%c %c %c %c\n",3,3,3,3);
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"└ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┘"<<endl;
lk:
;
for(int i=0; i<10; i++)
for(int o=0; o<18; o++)
mb[i][o]=0;
int x=6;
for(int i=wt*10;;) {
if(i<wt*10)goto asd;
for(int i=0; i<10; i++)
for(int o=0; o<18; o++)
if(mb[i][o]!=0)goto qwe;
fen+=500;
qwe:
;
for(int o=0; o<10; o++)
if(mb[o][17]==1)goto as;
for(int o=17; o>0; o--)
for(int j=0; j<10; j++)
mb[j][o]=mb[j][o-1];
for(int o=0; o<10; o++)
mb[o][0]=rand()%2;
asd:
;
if(GetAsyncKeyState(VK_RIGHT)!=0&&x<11)x++;
if(GetAsyncKeyState(VK_LEFT)!=0&&x>2)x--;
if(GetAsyncKeyState(VK_UP)!=0)sj(x);
printtu(x,20,i>=wt*10);
if(i<wt*10)i++;
else i=1;
}
as:
;
for(int i=2; i<22; i++) {
go(2,i);
kg(20);
}
fen-=600;
switch(leaf) {
case 1:
go(13,8);
cout<<' '<<' ';
break;
case 2:
leaf--;
go(14,8);
cout<<' '<<' ';
goto lk;
case 3:
leaf--;
go(15,8);
cout<<' '<<' ';
goto lk;
case 4:
leaf--;
go(16,8);
cout<<' '<<' ';
goto lk;
case 5:
leaf--;
go(13,9);
cout<<' '<<' ';
goto lk;
case 6:
leaf--;
go(14,9);
cout<<' '<<' ';
goto lk;
case 7:
leaf--;
go(15,9);
cout<<' '<<' ';
goto lk;
case 8:
leaf--;
go(16,9);
cout<<' '<<' ';
goto lk;
}
go(5,7);
cout<<"你输了!";
go(3,8);
cout<<" ┆ 再来[R]┆ ┆ 返回[E]┆";
for(;;) {
if(GetAsyncKeyState('R')!=0||GetAsyncKeyState('r')!=0)goto lkr;
if(GetAsyncKeyState('E')!=0||GetAsyncKeyState('e')!=0)return;
}
}
void dafangkuai() {}
int main() {
SetConsoleTitle("打方块Windows10");
int q=3;
a:
;
system("mode con cols=80 lines=25");
system("cls");
bool jh[8][27]= {0,0,1,0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,1,0,0,1,0,0,1,1,1,1,1,1,1,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,1,1,1,1,1,0,0,0,1,1,1,0,0,1,0,0,0,0,1,1,1,1,0,1,1,1,0,0,0,1,0,1,0,1,1,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,1,0,1,1,1,1,1,1,1,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,1,1,0,0,0,1,0,0,0,0,1,1,0,0,0,1,1,0,0,0,1,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0};
for(int i=2; i<10; i++) {
go(7,i);
for(int o=0; o<27; o++) {
if(jh[i-2][o])
cout<<"■";
else cout<<' '<<' ';
}
}
go(17,11);
cout<<"|开始游戏|";
go(17,13);
cout<<"|设置游戏|";
go(17,15);
cout<<"|游戏规则|";
go(17,17);
cout<<"|退出游戏|";
go(1,23);
cout<<"[L]确定";
int y=1;
for(;;) {
if(GetAsyncKeyState(VK_DOWN)!=0)y+=((y==4)?-3:1);
if(GetAsyncKeyState(VK_UP)!=0)y-=((y==1)?-3:1);
if(GetAsyncKeyState('l')!=0||GetAsyncKeyState('L')!=0)
switch(y) {
case 1:
system("cls");
m(q);
goto a;
case 2:
system("cls");
go(16,11);
cout<<' '<<q<<"秒增加一行";
go(16,10);
printf("[%c]",30);
go(16,12);
printf("[%c]",31);
go(1,23);
cout<<"[K]确定";
for(;;) {
if(GetAsyncKeyState(VK_UP)!=0&&q<9) {
q++;
go(16,11);
cout<<' '<<q;
}
if(GetAsyncKeyState(VK_DOWN)!=0&&q>1) {
q--;
go(16,11);
cout<<' '<<q;
}
if(GetAsyncKeyState('k')!=0||GetAsyncKeyState('K')!=0)goto a;
Sleep(100);
}
case 3:
MessageBox(0,"点确定浏览规则" ,"规则",MB_OK);
MessageBox(0,"←→控制炮台","规则",MB_OK);
MessageBox(0,"满一行即消除","规则",MB_OK);
MessageBox(0,"每消除一行+100","规则",MB_OK);
MessageBox(0,"少一条命-100","规则",MB_OK);
MessageBox(0,"全部消除+500","规则",MB_OK);
MessageBox(0,"发射一炮-10","规则",MB_OK);
case 4:
return 0;
}
go(16,11);
cout<<' '<<' ';
go(22,11);
cout<<' ';
go(16,13);
cout<<' '<<' ';
go(22,13);
cout<<' ';
go(16,15);
cout<<' '<<' ';
go(22,15);
cout<<' ';
go(16,17);
cout<<' '<<' ';
go(22,17);
cout<<' ';
go(16,9+2*y);
cout<<' '<<'>';
go(22,9+2*y);
cout<<'<';
Sleep(100);
}
}
3.俄罗斯方块
#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#define ROW 29 //游戏区行数
#define COL 20 //游戏区列数
#define DOWN 80 //方向键:下
#define LEFT 75 //方向键:左
#define RIGHT 77 //方向键:右
#define SPACE 32 //空格键
#define ESC 27 //Esc键
struct Face
{
int data[ROW][COL + 10]; //用于标记指定位置是否有方块(1为有,0为无)
int color[ROW][COL + 10]; //用于记录指定位置的方块颜色编码
}face;
struct Block
{
int space[4][4];
}block[7][4]; //用于存储7种基本形状方块的各自的4种形态的信息,共28种
//隐藏光标
void HideCursor();
//光标跳转
void CursorJump(int x, int y);
//初始化界面
void InitInterface();
//初始化方块信息
void InitBlockInfo();
//颜色设置
void color(int num);
//画出方块
void DrawBlock(int shape, int form, int x, int y);
//空格覆盖
void DrawSpace(int shape, int form, int x, int y);
//合法性判断
int IsLegal(int shape, int form, int x, int y);
//判断得分与结束
int JudeFunc();
//游戏主体逻辑函数
void StartGame();
//从文件读取最高分
void ReadGrade();
//更新最高分到文件
void WriteGrade();
int max, grade; //全局变量
int main()
{
#pragma warning (disable:4996) //消除警告
max = 0, grade = 0; //初始化变量
system("title 俄罗斯方块"); //设置cmd窗口的名字
system("mode con lines=29 cols=60"); //设置cmd窗口的大小
HideCursor(); //隐藏光标
ReadGrade(); //从文件读取最高分到max变量
InitInterface(); //初始化界面
InitBlockInfo(); //初始化方块信息
srand((unsigned int)time(NULL)); //设置随机数生成的起点
StartGame(); //开始游戏
return 0;
}
//隐藏光标
void HideCursor()
{
CONSOLE_CURSOR_INFO curInfo; //定义光标信息的结构体变量
curInfo.dwSize = 1; //如果没赋值的话,隐藏光标无效
curInfo.bVisible = FALSE; //将光标设置为不可见
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); //获取控制台句柄
SetConsoleCursorInfo(handle, &curInfo); //设置光标信息
}
//光标跳转
void CursorJump(int x, int y)
{
COORD pos; //定义光标位置的结构体变量
pos.X = x; //横坐标设置
pos.Y = y; //纵坐标设置
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); //获取控制台句柄
SetConsoleCursorPosition(handle, pos); //设置光标位置
}
//初始化界面
void InitInterface()
{
color(7); //颜色设置为白色
for (int i = 0; i < ROW; i++)
{
for (int j = 0; j < COL + 10; j++)
{
if (j == 0 || j == COL - 1 || j == COL + 9)
{
face.data[i][j] = 1; //标记该位置有方块
CursorJump(2 * j, i);
printf("■");
}
else if (i == ROW - 1)
{
face.data[i][j] = 1; //标记该位置有方块
printf("■");
}
else
face.data[i][j] = 0; //标记该位置无方块
}
}
for (int i = COL; i < COL + 10; i++)
{
face.data[8][i] = 1; //标记该位置有方块
CursorJump(2 * i, 8);
printf("■");
}
CursorJump(2 * COL, 1);
printf("下一个方块:");
CursorJump(2 * COL + 4, ROW - 19);
printf("左移:←");
CursorJump(2 * COL + 4, ROW - 17);
printf("右移:→");
CursorJump(2 * COL + 4, ROW - 15);
printf("加速:↓");
CursorJump(2 * COL + 4, ROW - 13);
printf("旋转:空格");
CursorJump(2 * COL + 4, ROW - 11);
printf("暂停: S");
CursorJump(2 * COL + 4, ROW - 9);
printf("退出: Esc");
CursorJump(2 * COL + 4, ROW - 7);
printf("重新开始:R");
CursorJump(2 * COL + 4, ROW - 5);
printf("最高纪录:%d", max);
CursorJump(2 * COL + 4, ROW - 3);
printf("当前分数:%d", grade);
}
//初始化方块信息
void InitBlockInfo()
{
//“T”形
for (int i = 0; i <= 2; i++)
block[0][0].space[1][i] = 1;
block[0][0].space[2][1] = 1;
//“L”形
for (int i = 1; i <= 3; i++)
block[1][0].space[i][1] = 1;
block[1][0].space[3][2] = 1;
//“J”形
for (int i = 1; i <= 3; i++)
block[2][0].space[i][2] = 1;
block[2][0].space[3][1] = 1;
for (int i = 0; i <= 1; i++)
{
//“Z”形
block[3][0].space[1][i] = 1;
block[3][0].space[2][i + 1] = 1;
//“S”形
block[4][0].space[1][i + 1] = 1;
block[4][0].space[2][i] = 1;
//“O”形
block[5][0].space[1][i + 1] = 1;
block[5][0].space[2][i + 1] = 1;
}
//“I”形
for (int i = 0; i <= 3; i++)
block[6][0].space[i][1] = 1;
int temp[4][4];
for (int shape = 0; shape < 7; shape++) //7种形状
{
for (int form = 0; form < 3; form++) //4种形态(已经有了一种,这里每个还需增加3种)
{
//获取第form种形态
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
temp[i][j] = block[shape][form].space[i][j];
}
}
//将第form种形态顺时针旋转,得到第form+1种形态
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
block[shape][form + 1].space[i][j] = temp[3 - j][i];
}
}
}
}
}
//颜色设置
void color(int c)
{
switch (c)
{
case 0:
c = 13; //“T”形方块设置为紫色
break;
case 1:
case 2:
c = 12; //“L”形和“J”形方块设置为红色
break;
case 3:
case 4:
c = 10; //“Z”形和“S”形方块设置为绿色
break;
case 5:
c = 14; //“O”形方块设置为黄色
break;
case 6:
c = 11; //“I”形方块设置为浅蓝色
break;
default:
c = 7; //其他默认设置为白色
break;
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c); //颜色设置
//注:SetConsoleTextAttribute是一个API(应用程序编程接口)
}
//画出方块
void DrawBlock(int shape, int form, int x, int y)
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if (block[shape][form].space[i][j] == 1) //如果该位置有方块
{
CursorJump(2 * (x + j), y + i); //光标跳转到指定位置
printf("■"); //输出方块
}
}
}
}
//空格覆盖
void DrawSpace(int shape, int form, int x, int y)
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if (block[shape][form].space[i][j] == 1) //如果该位置有方块
{
CursorJump(2 * (x + j), y + i); //光标跳转到指定位置
printf(" "); //打印空格覆盖(两个空格)
}
}
}
}
//合法性判断
int IsLegal(int shape, int form, int x, int y)
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
//如果方块落下的位置本来就已经有方块了,则不合法
if ((block[shape][form].space[i][j] == 1) && (face.data[y + i][x + j] == 1))
return 0; //不合法
}
}
return 1; //合法
}
//判断得分与结束
int JudeFunc()
{
//判断是否得分
for (int i = ROW - 2; i > 4; i--)
{
int sum = 0; //记录第i行的方块个数
for (int j = 1; j < COL - 1; j++)
{
sum += face.data[i][j]; //统计第i行的方块个数
}
if (sum == 0) //该行没有方块,无需再判断其上的层次(无需再继续判断是否得分)
break; //跳出循环
if (sum == COL - 2) //该行全是方块,可得分
{
grade += 10; //满一行加10分
color(7); //颜色设置为白色
CursorJump(2 * COL + 4, ROW - 3); //光标跳转到显示当前分数的位置
printf("当前分数:%d", grade); //更新当前分数
for (int j = 1; j < COL - 1; j++) //清除得分行的方块信息
{
face.data[i][j] = 0; //该位置得分后被清除,标记为无方块
CursorJump(2 * j, i); //光标跳转到该位置
printf(" "); //打印空格覆盖(两个空格)
}
//把被清除行上面的行整体向下挪一格
for (int m = i; m >1; m--)
{
sum = 0; //记录上一行的方块个数
for (int n = 1; n < COL - 1; n++)
{
sum += face.data[m - 1][n]; //统计上一行的方块个数
face.data[m][n] = face.data[m - 1][n]; //将上一行方块的标识移到下一行
face.color[m][n] = face.color[m - 1][n]; //将上一行方块的颜色编号移到下一行
if (face.data[m][n] == 1) //上一行移下来的是方块,打印方块
{
CursorJump(2 * n, m); //光标跳转到该位置
color(face.color[m][n]); //颜色设置为还方块的颜色
printf("■"); //打印方块
}
else //上一行移下来的是空格,打印空格
{
CursorJump(2 * n, m); //光标跳转到该位置
printf(" "); //打印空格(两个空格)
}
}
if (sum == 0) //上一行移下来的全是空格,无需再将上层的方块向下移动(移动结束)
return 1; //返回1,表示还需调用该函数进行判断(移动下来的可能还有满行)
}
}
}
//判断游戏是否结束
for (int j = 1; j < COL - 1; j++)
{
if (face.data[1][j] == 1) //顶层有方块存在(以第1行为顶层,不是第0行)
{
Sleep(1000); //留给玩家反应时间
system("cls"); //清空屏幕
color(7); //颜色设置为白色
CursorJump(2 * (COL / 3), ROW / 2 - 3);
if (grade>max)
{
printf("恭喜你打破最高记录,最高记录更新为%d", grade);
WriteGrade();
}
else if (grade == max)
{
printf("与最高记录持平,加油再创佳绩", grade);
}
else
{
printf("请继续加油,当前与最高记录相差%d", max - grade);
}
CursorJump(2 * (COL / 3), ROW / 2);
printf("GAME OVER");
while (1)
{
char ch;
CursorJump(2 * (COL / 3), ROW / 2 + 3);
printf("再来一局?(y/n):");
scanf("%c", &ch);
if (ch == 'y' || ch == 'Y')
{
system("cls");
main();
}
else if (ch == 'n' || ch == 'N')
{
CursorJump(2 * (COL / 3), ROW / 2 + 5);
exit(0);
}
else
{
CursorJump(2 * (COL / 3), ROW / 2 + 4);
printf("选择错误,请再次选择");
}
}
}
}
return 0; //判断结束,无需再调用该函数进行判断
}
//游戏主体逻辑函数
void StartGame()
{
int shape = rand() % 7, form = rand() % 4; //随机获取方块的形状和形态
while (1)
{
int t = 0;
int nextShape = rand() % 7, nextForm = rand() % 4; //随机获取下一个方块的形状和形态
int x = COL / 2 - 2, y = 0; //方块初始下落位置的横纵坐标
color(nextShape); //颜色设置为下一个方块的颜色
DrawBlock(nextShape, nextForm, COL + 3, 3); //将下一个方块显示在右上角
while (1)
{
color(shape); //颜色设置为当前正在下落的方块
DrawBlock(shape, form, x, y); //将该方块显示在初始下落位置
if (t == 0)
{
t = 15000; //这里t越小,方块下落越快(可以根据此设置游戏难度)
}
while (--t)
{
if (kbhit() != 0) //若键盘被敲击,则退出循环
break;
}
if (t == 0) //键盘未被敲击
{
if (IsLegal(shape, form, x, y + 1) == 0) //方块再下落就不合法了(已经到达底部)
{
//将当前方块的信息录入face当中
//face:记录界面的每个位置是否有方块,若有方块还需记录该位置方块的颜色。
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if (block[shape][form].space[i][j] == 1)
{
face.data[y + i][x + j] = 1; //将该位置标记为有方块
face.color[y + i][x + j] = shape; //记录该方块的颜色数值
}
}
}
while (JudeFunc()); //判断此次方块下落是否得分以及游戏是否结束
break; //跳出当前死循环,准备进行下一个方块的下落
}
else //未到底部
{
DrawSpace(shape, form, x, y); //用空格覆盖当前方块所在位置
y++; //纵坐标自增(下一次显示方块时就相当于下落了一格了)
}
}
else //键盘被敲击
{
char ch = getch(); //读取keycode
switch (ch)
{
case DOWN: //方向键:下
if (IsLegal(shape, form, x, y + 1) == 1) //判断方块向下移动一位后是否合法
{
//方块下落后合法才进行以下操作
DrawSpace(shape, form, x, y); //用空格覆盖当前方块所在位置
y++; //纵坐标自增(下一次显示方块时就相当于下落了一格了)
}
break;
case LEFT: //方向键:左
if (IsLegal(shape, form, x - 1, y) == 1) //判断方块向左移动一位后是否合法
{
//方块左移后合法才进行以下操作
DrawSpace(shape, form, x, y); //用空格覆盖当前方块所在位置
x--; //横坐标自减(下一次显示方块时就相当于左移了一格了)
}
break;
case RIGHT: //方向键:右
if (IsLegal(shape, form, x + 1, y) == 1) //判断方块向右移动一位后是否合法
{
//方块右移后合法才进行以下操作
DrawSpace(shape, form, x, y); //用空格覆盖当前方块所在位置
x++; //横坐标自增(下一次显示方块时就相当于右移了一格了)
}
break;
case SPACE: //空格键
if (IsLegal(shape, (form + 1) % 4, x, y + 1) == 1) //判断方块旋转后是否合法
{
//方块旋转后合法才进行以下操作
DrawSpace(shape, form, x, y); //用空格覆盖当前方块所在位置
y++; //纵坐标自增(总不能原地旋转吧)
form = (form + 1) % 4; //方块的形态自增(下一次显示方块时就相当于旋转了)
}
break;
case ESC: //Esc键
system("cls"); //清空屏幕
color(7);
CursorJump(COL, ROW / 2);
printf(" 游戏结束 ");
CursorJump(COL, ROW / 2 + 2);
exit(0); //结束程序
case 's':
case 'S': //暂停
system("pause>nul"); //暂停(按任意键继续)
break;
case 'r':
case 'R': //重新开始
system("cls"); //清空屏幕
main(); //重新执行主函数
}
}
}
shape = nextShape, form = nextForm; //获取下一个方块的信息
DrawSpace(nextShape, nextForm, COL + 3, 3); //将右上角的方块信息用空格覆盖
}
}
//从文件读取最高分
void ReadGrade()
{
FILE* pf = fopen("俄罗斯方块最高得分记录.txt", "r"); //以只读方式打开文件
if (pf == NULL) //打开文件失败
{
pf = fopen("俄罗斯方块最高得分记录.txt", "w"); //以只写方式打开文件(文件不存在可以自动创建该文件)
fwrite(&grade, sizeof(int), 1, pf); //将max写入文件(此时max为0),即将最高历史得分初始化为0
}
fseek(pf, 0, SEEK_SET); //使文件指针pf指向文件开头
fread(&max, sizeof(int), 1, pf); //读取文件中的最高历史得分到max当中
fclose(pf); //关闭文件
pf = NULL; //文件指针及时置空
}
//更新最高分到文件
void WriteGrade()
{
FILE* pf = fopen("俄罗斯方块最高得分记录.txt", "w"); //以只写方式打开文件
if (pf == NULL) //打开文件失败
{
printf("保存最高得分记录失败\n");
exit(0);
}
fwrite(&grade, sizeof(int), 1, pf); //将本局游戏得分写入文件当中(更新最高历史得分)
fclose(pf); //关闭文件
pf = NULL; //文件指针及时置空
}
4.愤怒的小鸟
#include <bits/stdc++.h>
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
using namespace std;
const double pi = 3.1415926536;
int toint (float a) {
return ((int) (a * 10 + 5)) / 10;
}
void Color (int a) {
if (a == 0 || a == 14 || a == 20) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
} else if (a == 1 || a == 12) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
} else if (a == 2) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_GREEN);
} else if (a == 3) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);
} else if (a == 4 || a == 11) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_RED);
} else if (a == 5 || a == 13) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
} else if (a == 7) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_GREEN|FOREGROUND_BLUE);
} else if (a == 15) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
} else if (a == 16) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_GREEN);
} else if (a == 17) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_RED);
} else if (a == 8) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
} else if (a == 6) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_BLUE);
} else if (a == 9) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_RED|BACKGROUND_RED|BACKGROUND_GREEN);
}
}
void SetPos (float x, float y) {
int xx = toint (x), yy = toint (y);
COORD pos;
pos.X = yy * 2;
pos.Y = xx;
SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), pos);
}
struct node {
int W, W2, S, mS;
float X, Y;
float vx, vy;
float ax, ay;
bool go, boom;
} blt[100001], pig[100001], boo[100001];
int T, yX, yY, Xy, put, K, K2, Sle, What;
int Bot, Pit, Blt, Pig, Sco, pigk, scok;
int m[41][41];
void Cout (int a, int x, int y) {
if (a == 1) {
SetPos (x, y);
Color (5);
cout << put << ' ';
}
if (y == 202) {
SetPos (pig[a].X, pig[a].Y);
cout << ". ";
if ((pig[a].W == 2 || pig[a].W == 3) && pig[a].X >= 2) {
SetPos (pig[a].X - 2, pig[a].Y);
cout << ". ";
SetPos (pig[a].X - 1, pig[a].Y);
cout << ". ";
} else if (pig[a].W == 4) {
SetPos (pig[a].X, pig[a].Y - 1);
cout << ". ";
} else if(pig[a].W == 5) {
SetPos (pig[a].X - 1, pig[a].Y);
cout << ". ";
SetPos (pig[a].X - 1, pig[a].Y - 1);
cout << ". ";
}
}
if (a == 2) {
for (int i = 0; i <= 40; i++) {
for (int j = 0; j <= 40; j++) {
if (i <= 18 && m[i][j] == 1) {
SetPos (i, j);
Color (7);
cout << "■";
}
if (m[i][j] >= 2 && m[i][j] <= 19) {
SetPos (i, j);
Color (5);
cout << "█";
m[i][j]++;
}
if (m[i][j] > 19 && m[i][j] <= 29) {
SetPos (i, j);
Color (0);
cout << "█";
m[i][j]++;
if (m[i][j] == 30) {
SetPos (i, j);
Color (0);
cout << " ";
m[i][j] = 0;
}
if (m[i][j] >= 31 && m[i][j] <= 49) {
SetPos (i, j);
Color (0);
cout << "■";
m[i][j]++;
}
if (m[i][j] == 50) {
SetPos (i, j);
Color (7);
cout << "■";
m[i][j] = 1;
}
}
}
}
}
if (y == 666) {
SetPos (blt[a].X, blt[a].Y);
Color (10 + blt[a].W);
cout<<"●";
}
Color (0);
}
void Go (int a) {
SetPos (blt[a].X, blt[a].Y);
cout << "..";
blt[a].X += blt[a].vx / 2;
blt[a].Y += blt[a].vy / 2;
blt[a].vx += blt[a].ax / 2;
blt[a].vy += blt[a].ay / 2;
if (blt[a].X >= 20) {
blt[a].X = 19;
}
if (blt[a].X > 20 || blt[a].Y > 38 || blt[a].X < 0 || blt[a].Y <= 0) {
blt[a].go = 1;
}
if (blt[a].W2 == 1 && blt[a].Y >= Xy) {
blt[a].go = 1;
Sle = 0;//地跑鸟
}
if (blt[a].W2 == 0) {
for (int i = 0; i <= blt[a].vx / 2 + 1; i++) {
if (blt[a].vx > 0 && m[toint (blt[a].X) + i][toint (blt[a].Y)] == 1) {
if (blt[a].W != 5) {
blt[a].boom = 1;
}
blt[a].X = toint (blt[a].X) + i - 1;
blt[a].Y += blt[a].vy / 2;
blt[a].vx = -blt[a].vx * 0.4;
blt[a].vy = blt[a].vy * 0.8;
if (blt[a].W == 3) {
blt[a].ax = 0.5;
}
if (blt[a].W == 7) {
blt[a].vx *= 2;
}
if (blt[a].W == 10) {
blt[a].go = 1;
Bot++;
boo[Bot].X = blt[a].X;
boo[Bot].Y = blt[a].Y;
boo[Bot].S = 1;
boo[Bot].mS = 4;
}
}
if (blt[a].vx < 0 && m[toint (blt[a].X) - i][toint(blt[a].Y)] == 1) {
if (blt[a].W != 5) {
blt[a].boom = 1;
}
blt[a].X = toint (blt[a].X) + i + 1;
blt[a].Y += blt[a].vy / 2;
blt[a].vx = -blt[a].vx;
blt[a].vy=blt[a].vy * 0.8;
if (blt[a].W == 3) {
blt[a].ax = 0.5;
}
if (blt[a].W == 7) {
blt[a].vx *= 2;
}
if (blt[a].W == 10) {
blt[a].go = 1;
Bot++;
boo[Bot].X = blt[a].X;
boo[Bot].Y = blt[a].Y;
boo[Bot].S = 1;
boo[Bot].mS = 4;
}
}
}
if (abs (blt[a].vx) <= 0.1 && abs (blt[a].vy) <= 0.1 && abs (blt[a].ay) <= 0.1) {
blt[a].go = 1;
if (blt[a].W == 5) {
Bot++;
boo[Bot].X = blt[a].X;
boo[Bot].Y = blt[a].Y;
boo[Bot].S = 1;
boo[Bot].mS = 4;
blt[a].go = 1;
}
}
}
if (blt[a].go == 0) {
Cout (a, 0, 666);
}
}
void Kill (int a) {
if (pig[a].go == 0 && pig[a].W != 2 && pig[a].W != 3 && pig[a].Y < 16) {
Cout (a, 202, 202);
pig[a].Y = 16;
}
if (pig[a].go == 0 && pig[a].W == 4 && pig[a].Y < 20) {
pig[a].W = 1;
}
int R = rand () % 50;
Cout (a, 202, 202);
//清除猪猪
pig[a].X += pig[a].vx / 2;
pig[a].Y += pig[a].vy / 2;
pig[a].vx += pig[a].ax / 2;
pig[a].vy += pig[a].ay / 2;
for (int i = -2; i <= pig[a].vx / 2 + 1; i++) {
if (m[toint (pig[a].X) + i][toint (pig[a].Y)] == 1) {
pig[a].X = toint (pig[a].X) + i - 1;
pig[a].Y += pig[a].vy / 2;
pig[a].vx = -pig[a].vx * 0.5;
pig[a].vy = pig[a].vy * 0.8;
}
}
for (int i = Blt - 10; i <= Blt; i++) {
if (pig[a].W == 5 && blt[i].go == 0 && abs (pig[a].X - blt[i].X) <= 1
&& abs (pig[a].Y - blt[i].Y) <= 1) {
m[toint (pig[a].X) - 1][toint (pig[a].Y)] = 2;
pig[a].W2++;
Sco += 2;
break;
}
if (pig[a].W == 5 && m[toint (pig[a].X)][toint (pig[a].Y)] >= 2 &&
m[toint (pig[a].X)][toint (pig[a].Y)] < 30) {
m[toint (pig[a].X) - 1][toint (pig[a].Y)] = 2;
pig[a].W2++;
Sco += 2;
break;
}
if (blt[i].go == 0 && abs (pig[a].X - blt[i].X) <= 1 && abs (pig[a].Y - blt[i].Y) <= 1) {
if (pig[a].W == 6) {
Bot++;
boo[Bot].X = pig[a].X;
boo[Bot].Y = pig[a].Y;
boo[Bot].S = 1;
boo[Bot].mS = 4;
blt[i].go = 1;
}
m[toint (pig[a].X)][toint (pig[a].Y)] = 2;
pig[a].go = 1;
Pig--;
Sco+=10;
break;
}
if (m[toint (pig[a].X)][toint (pig[a].Y)] >= 2 &&
m[toint (pig[a].X)][toint (pig[a].Y)] < 30) {
if (pig[a].W == 6) {
Bot++;
boo[Bot].X = pig[a].X;
boo[Bot].Y = pig[a].Y;
boo[Bot].S = 1;
boo[Bot].mS = 4;
}
pig[a].go = 1;
Pig--;
Sco += 10;
break;
}
if ((pig[a].W == 2 || pig[a].W == 3) && blt[i].go == 0 &&
abs (pig[a].X - 2 - blt[i].X) <= 1 && abs (pig[a].Y - blt[i].Y) <= 1) {
m[toint (pig[a].X)][toint (pig[a].Y)] = 2;
pig[a].go = 1;
Pig--;
Sco += 10;
break;
}
if ((pig[a].W == 2 || pig[a].W == 3) &&
m[toint (pig[a].X - 2)][toint (pig[a].Y)] >= 2
&& m[toint (pig[a].X - 2)][toint (pig[a].Y)] < 30) {
pig[a].go = 1;
Pig--;
Sco += 10;
break;
}
}
//弄死猪猪
if (pig[a].go == 0) {
if (pig[a].go == 0 && pig[a].W != 2 && pig[a].W != 3 && pig[a].Y < 16) {
Cout (a, 202, 202);
pig[a].Y = 16;
}
if (pig[a].go == 0 && pig[a].W == 4 &&pig[a].Y < 20) {
pig[a].W = 1;
}
int Xx = toint (pig[a].X), Xy = toint (pig[a].Y);
if (pig[a].W == 6) {
SetPos (pig[a].X, pig[a].Y);
Color (9);
cout << "TN";
Color (0);
} else {
SetPos (pig[a].X, pig[a].Y);
Color (2);
cout << "●";
if ((pig[a].W == 2 || pig[a].W == 3) && pig[a].X >= 2) {
SetPos (pig[a].X - 2, pig[a].Y);
Color (0);
cout << "○";
SetPos (pig[a].X - 1, pig[a].Y);
cout << "|";
} else if (pig[a].W == 4) {
SetPos (pig[a].X, pig[a].Y - 1);
Color (2);
cout << "﹃";
} else if (pig[a].W == 5) {
SetPos (pig[a].X - 1, pig[a].Y);
Color (8);
SetPos (pig[a].X - 1, pig[a].Y - 1);
cout << "▁";
if (pig[a].W2 == 0) {
cout << "▅";
} else if (pig[a].W2 == 1) {
cout << "▃";
} else if (pig[a].W2 == 2) {
cout << "▂";
} else if (pig[a].W2 == 3) {
pig[a].W = 1;
pig[a].W2 = 0;
SetPos (pig[a].X - 1, pig[a].Y - 1);
cout << " ";
}
}
}
//输出猪猪
if (pig[a].W == 2 && pig[a].X > pig[a].S) {
pig[a].W = 3;
pig[a].ax = -0.4;
pig[a].vx = 1.5;
} else if (pig[a].W == 3 && pig[a].X <= pig[a].S) {
pig[a].W = 2;
pig[a].ax = 0.4;
pig[a].vx = -1.5;
}
if ((pig[a].W == 2 || pig[a].W == 3) && (pig[a].Y <= 10 || pig[a].Y >= 38)) {
pig[a].vy *= -1;
}
if (pig[a].W == 4 && R == 0 && pig[a].X == 20) {
pig[a].vx = -((rand () % 40) / 10);
}
if(pig[a].W == 4) {
int r = rand () % 20;
for (int i = Blt - 10; i <= Blt; i++) {
if (r <= 5 && blt[i].go == 0 && pig[a].Y - blt[i].Y <= 5 &&
abs (blt[i].X - pig[a].X) <= 1.5 && r < 5) {
r = 0;
break;
}
}
if (r == 0) {
m[toint (pig[a].X)][toint (pig[a].Y) - 2] = 10;
m[toint (pig[a].X)][toint (pig[a].Y) - 3] = 2;
for (int j = toint (pig[a].Y) - 1; j >= toint (pig[a].Y) - 5; j--) {
for (int i = Blt - 10; i <= Blt; i++) {
if (blt[i].go == 0 && !(blt[i].W == 3 && blt[i].boom == 1)
&& blt[i].W2 == 0 && toint (blt[i].Y) == j
&& abs (blt[i].X - pig[a].X) <= 2) {
blt[i].vy = -2;
}
}
for (int i = Pit - 50; i <= Pit; i++) {
if (pig[i].go == 0 && toint (pig[i].Y) == j && abs (pig[i].X - pig[a].X) <= 2) {
pig[i].vy = -1;
}
}
}
}
}
//移动猪猪
if (pig[a].go == 0 && pig[a].W != 2 && pig[a].W != 3 && pig[a].Y < 16) {
Cout (a, 202, 202);
pig[a].Y = 16;
}
if (pig[a].go == 0 && pig[a].W == 4 && pig[a].Y < 20) {
pig[a].W = 1;
}
if (pig[a].X > 20 || pig[a].Y > 38 || pig[a].X < 0 || pig[a].Y <= 0) {
pig[a].go = 1;
Pig--;
Cout (a, 202, 202);
}
//清除猪猪
}
}
void Creat (int a, int p) {
if (a == -1 && p == -1) {
Blt++;
blt[Blt].W = What;
blt[Blt].W2 = 1;
blt[Blt].vy = 1;
blt[Blt].X = 19;
blt[Blt].Y = 0;
blt[Blt].boom = 1;
} else if (a == 0 && p == -1) {
int u = rand () % 7 + 1, U = rand() % 30;
if (u >= 5) {
Pit++;
pig[Pit].Y = rand () % 15 + 20;
pig[Pit].X = 2;
pig[Pit].ax = 0.5;
pig[Pit].W = 1;
} else if (u == 1) {
Pit++;
pig[Pit].Y = rand () % 15 + 20;
pig[Pit].X = 2;
pig[Pit].vy = 0.5;
pig[Pit].ax = 0.5;
pig[Pit].S = rand () % 5 + 7;
pig[Pit].W = 2;
} else if (u == 2) {
Pit++;
pig[Pit].Y = rand () % 15 + 20;
pig[Pit].X = 2;
pig[Pit].ax = 0.5;
pig[Pit].W = 4;
} else if (u == 3) {
Pit++;
pig[Pit].Y = rand () % 15 + 20;
pig[Pit].X = 2;
pig[Pit].ax = 0.5;
pig[Pit].W = 5;
} else if (u == 4) {
Pit++;
pig[Pit].Y = rand () % 15 + 20;
pig[Pit].X = 2;
pig[Pit].ax = 0.5;
pig[Pit].W = 6;
}
if (U == 1) {
Bot++;
boo[Bot].Y = rand () % 13 + 15;
boo[Bot].X = (rand () % 4) * 3 + 8;
boo[Bot].S = 0;
boo[Bot].mS = rand () % 2 + 2;
boo[Bot].W2 = 1;
}
} else {
Blt++;
blt[Blt].W = What;
if (a == 1) {
blt[Blt].X = yX;
blt[Blt].Y = yY;
blt[Blt].ax = 0.5; //抛物线
}
blt[Blt].vx = -3.5 * sin (p * pi / 180);
blt[Blt].vy = 3 * cos (p * pi / 180);
if (p <= 45) {
blt[Blt].vy *= 1 + (0.33 - 0.01 * (45 - p));
}
if (p >= 45) {
blt[Blt].vy *= 1 + (0.33 - 0.01 * (p - 45));
}
if (blt[Blt].W == 6) {
blt[Blt].vy *= 1.2;
blt[Blt].ax = 0.4;
}
}
}
void Boom (int a) {
if (boo[a].W2 == 0) {
int ms = boo[a].mS, s = boo[a].S, x = boo[a].X, y = boo[a].Y;
if (s == ms) {
return ;
}
for (int i = x - s; i <= x + s; i++) {
for (int j = y - s; j <= y + s; j++) {
float k = (i - x) * (i - x) + (j - y) * (j - y) - s * s;
if (k <= s && k >= -s && i <= 20 && j <= 38 && i >= 0 && j > 0 && m[i][j] != 1) {
m[i][j] = 2;
}
}
}
boo[a].S++;
}
if (boo[a].W2 == 1) {
int ms = boo[a].mS, s = boo[a].S, x = boo[a].X, y = boo[a].Y;
if (s == ms) {
return ;
}
if (y - s > 10) {
m[x][y-s] = 31 - 31 * (boo[a].W2 - 1);
}
if (y + s < 40) {
m[x][y+s] = 31 - 31 * (boo[a].W2 - 1);
}
boo[a].S++;
}
}
void Move (int a) {
Color (5);
if (a == -2) {
SetPos (17, Xy);
cout << " ";
SetPos (18, Xy);
cout << " ";
SetPos (19, Xy);
cout << " ";
SetPos (20, Xy);
cout << " ";
}
if (a == -1) {
SetPos (17, Xy);
cout << " ";
SetPos (18, Xy);
cout << " ┃ ┃";
SetPos (19, Xy);
cout << " ╰┳╯";
SetPos (20, Xy);
cout << " ▏";
}
if (a == 0) {
SetPos (18, Xy);
cout << " ┃";
Color (What + 10);
cout << "●";
Color (5);
cout << "┃";
SetPos (19, Xy);
cout << " ╰┳╯";
SetPos (20, Xy);
cout << " ▏";
}
if (a == 1) {
SetPos (18, Xy);
cout << " ";
Color (What + 10);
cout << "●";
Color (5);
cout << " ┃";
SetPos (19, Xy);
cout << " ╰┳╯";
SetPos (20, Xy);
cout << " ▏";
}
if (a == 2) {
SetPos (18, Xy);
Color (What + 10);
cout << "●";
Color (5);
cout << "┃ ┃";
SetPos (19, Xy);
cout << " ╰┳╯";
SetPos (20, Xy);
cout << " ▏";
}
if (a == 3) {
SetPos (18, Xy);
cout << " ┃ ┃";
SetPos (19, Xy);
Color (What + 10);
cout << "●";
Color (5);
cout << "╰┳╯";
SetPos (20, Xy);
cout << " ▏";
}
if (a == 4) {
SetPos (18, Xy);
cout << " ┃ ┃";
SetPos (19, Xy);
cout << " ╰┳╯";
SetPos (20, Xy);
Color (What + 10);
cout << "●";
Color (5);
cout << " ▏";
}
if (a == 5) {
SetPos (18, Xy);
cout << " ┃ ┃";
SetPos (19, Xy);
cout << " ╰┳╯";
SetPos (20, Xy);
cout << " ";
Color (What + 10);
cout << "●";
Color (5);
cout << " ▏";
}
if (a == 6) {
SetPos (18, Xy);
cout << " ┃ ┃";
SetPos (19, Xy);
cout << " ╰┳╯";
SetPos (20, Xy);
cout << " ";
Color (What + 10);
cout << "●";
Color (5);
cout << " ";
}
Color (0);
}
void Start () {
char g;
Color (5);
system ("cls");
SetPos (1, 1);
cout << "------- 愤 怒 的 小 鸟 -------";
Color (0);
SetPos (3, 1);
cout << "空格瞄准,按X触发小鸟技能,←→移动弹弓";
SetPos (5, 1);
cout << "猪猪技能自动触发,空中会有墙出现。";
SetPos (7, 1);
cout << "危险值由命中率,猪的存活时间计算!";
SetPos (9, 1);
cout << "危险值点满后失败!1500分通关!";
SetPos (1, 20);
cout << "-------- 小 鸟 技 能 --------";
SetPos (3, 20);
Color (11);
cout << "●";
Color (0);
cout << ":无技能";
SetPos (5, 20);
Color (12);
cout << "●";
Color (0);
cout << ":分身!不同分身初速度大小相同,";
SetPos(6,20);cout<<" 方向不同。";
SetPos (7, 20);
Color (13);
cout << "●";
Color (0);
cout << ":加速!以当前速度做匀速直线运动,";
SetPos (8, 20);
cout << " 且免疫狙击猪的冲击。";
SetPos (9, 20);
Color (14);
cout << "●";
Color (0);
cout << ":投蛋!并获得向上速度做匀速直线";
SetPos (10, 20);
cout << " 运动,快达可以穿墙。";
SetPos (11, 20);
Color (15);
cout << "●";
Color (0);
cout << ":爆炸!";
SetPos (13, 20);
Color (16);
cout << "●";
Color (0);
cout << ":回旋!开始做向左加速运动!发射";
SetPos (14, 20);
cout << " 时获得双倍水平速度。";
SetPos (15, 20);
Color (17);
cout << "●";
Color (0);
cout << ":[被动] 弹跳力为普通鸟三倍。发射";
SetPos (16, 20);
cout << " 时获得1.5倍水平、竖直速度。";
SetPos (11, 1);
cout << "-------- 猪 猪 技 能 --------";
SetPos (13, 2);
Color (2);
cout << "●";
Color (0);
cout << ":无技能";
SetPos (14, 1);
Color (8);
cout << "▁▅";
SetPos (15, 2);
Color (2);
cout << "●";
Color (0);
cout << ":防御力为普通猪三倍";
SetPos (16, 2);
cout << "○";
SetPos (17, 2);
cout << "│:做空中简谐运动,受死范围";
SetPos (18, 2);
Color (2);
cout << "●";
Color (0);
cout << " 为普通猪两倍。";
SetPos (19, 2);
cout << " 有几率跳起或发射冲击波,冲";
SetPos (20, 1);
Color (2);
cout << "﹃●";
Color (0);
cout << ":开小鸟与同类,可以引爆TNT!";
SetPos (18, 20);
Color (5);
cout << "按 y 开始游戏!";
A:
if (kbhit ()) {
g = _getch ();
}
if(g != 'y') {
goto A;
}
}
int main () {
system ("mode con cols=79 lines=22");
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &cursor_info);
srand ((unsigned)time(NULL));
St:Start ();
system ("cls");
memset (blt, 0, sizeof (blt));
memset (pig, 0, sizeof (pig));
memset (boo, 0, sizeof (boo));
memset (m, 0, sizeof (m));
T = put = K = K2 = Sle = What = Pig = Sco = 0;
pigk = scok = -1;
Xy = 4;
yX = 18;
yY = 6;
Blt = 20;
Bot = 20;
Pit = 60;
Color (7);
SetPos (19, 14);
cout << "■";
SetPos (20, 13);
cout << " █▍";
m[19][14] = m[20][13] = m[20][14] = 1;
SetPos (21, 0);
for (int i = 0; i < 39; i++) {
cout << "■";
m[21][i] = 1;
}
Color (0);
What = rand () % 5 + 1;
while (1) {
if (Sco >= 1500) {
break;
}
T++;
K = 0;
Color (0);
if (Sco != scok) {
SetPos (1, 1);
cout << "分数:" << Sco << ' ';
}
if (Pig != pigk) {
SetPos (3, 1);
cout << "危险值:";
int aa = min (Sco / 100, 10);
Pig += aa;
SetPos (3, 5);
if (Pig <= 2) {
Color (2);
} else if (Pig <= 4) {
Color (16);
} else if (Pig <= 6) {
Color (7);
} else if (Pig <= 9) {
Color (6);
} else if (Pig <= 12) {
Color (3);
} else if (Pig <= 15) {
Color (17);
} else {
Color (11);
}
for (int i = 1; i <= Pig; i++) {
cout << "■";
}
Color (0);
cout << ' ' << Pig;
for (int i = 1; i <= 5; i++) {
cout << " ";
}
if (Pig > 18) {
break;
}
Pig -= aa;
}
scok = Sco;
pigk = Pig;
if (GetAsyncKeyState (VK_LEFT)&0x8000 && Xy > 0) {
Move (-2);
Xy--;
K = 1;
}
if (GetAsyncKeyState (VK_RIGHT)&0x8000 && Xy < 10) {
Move (-2);
Xy++;
K = 1;
}
if (K == 1) {
if (put == 0 && Sle == 0) {
Move (0);
} else {
Move (-1);
}
}
if (kbhit ()) {
char g = _getch ();
if (g == 'x' || g == 'X') {
for (int i = Blt - 10; i <= Blt; i++) {
if (blt[i].go == 0 && blt[i].boom == 0 && blt[i].W != 1 && blt[i].W != 7) {
blt[i].boom = 1;
if (blt[i].W == 2) {
Blt++;
blt[Blt].W = 2;
blt[Blt].vy = blt[i].vy * 1.2;
blt[Blt].vx = blt[i].vx + 1;
blt[Blt].ax = blt[i].ax;
blt[Blt].X = blt[i].X;
blt[Blt].Y = blt[i].Y;
blt[Blt].boom = 1;
Blt++;
blt[Blt].W = 2;
blt[Blt].vy = blt[i].vy * 0.7;
blt[Blt].vx = blt[i].vx - 1;
blt[Blt].ax = blt[i].ax;
blt[Blt].X = blt[i].X;
blt[Blt].Y = blt[i].Y;
blt[Blt].boom = 1;
}
if (blt[i].W == 3) {
blt[i].vy = fmax (blt[i].vy * 1.5, 2.5);
blt[Blt].vx++;
blt[i].ax = 0;
}
if (blt[i].W == 4) {
blt[i].vx = -3;
blt[i].ax = 0.1;
Blt++;
blt[Blt].boom = 1;
blt[Blt].W = 10;
blt[Blt].X = blt[i].X;
blt[Blt].Y = blt[i].Y;
blt[Blt].ax = blt[i].ax;
blt[Blt].vx = 1;
}
if (blt[i].W == 5) {
Bot++;
boo[Bot].X = blt[i].X;
boo[Bot].Y = blt[i].Y;
boo[Bot].S = 1;
boo[Bot].mS = 5;
blt[i].go = 1;
}
if (blt[i].W == 6) {
blt[i].ay = -1;
blt[i].ax = 0.3;
blt[i].vx = min (blt[i].vx / 2, (float)0);
}
break;
}
}
}
}
if (GetAsyncKeyState (' ')&0x8000 && K == 0 && Sle == 0) {
if (put <= 5) {
Move (1);
yX = 18;
yY = Xy + 1;
} else if (put <= 20) {
Move (2);
yX = 18;
yY = Xy;
} else if (put <= 40) {
Move (3);
yX = 19;
yY = Xy;
} else if (put <= 60) {
Move (4);
yX = 20;
yY = Xy;
} else if (put <= 80) {
Move (5);
yX = 20;
yY = Xy + 1;
} else {
Move (6);
yX = 20;
yY = Xy + 2;
}
if (put == 0) {
K2 = 1;
}
if (put == 90) {
K2 = -1;
}
if (K2 == 1) {
put += min (rand () % 7 + 1, 90 - put);
}
if (K2 == -1) {
put-=min(rand()%7+1,put);
}
Cout (1, 17, Xy + 2);
}
if ((!(GetAsyncKeyState (' ')&0x8000) && (put != 0)) || (put != 0 && K == 1)) {
Move (-1);
Creat (1, put);
put = 0;
yX = 18;
yY = 5;
Sle = 1;
What = rand () % 7 + 1;
Creat (-1, -1);
Sco = max (Sco - 5, 0);
}
for (int i = Blt - 10; i <= Blt; i++) {
if (blt[i].go == 0) {
Go (i);
}
}
for (int i = Bot - 10; i <= Bot; i++) {
if (boo[i].go == 0) {
Boom (i);
Cout (2, 0, 0);
}
}
for (int i = Pit - 50; i <= Pit; i++) {
if (pig[i].go == 0) {
Kill (i);
}
}
if (Sle != 0) {
Move (-1);
} else if (put == 0) {
Move (0);
}
if (T % 300 == 0) {
system ("cls");
pigk = scok = -1;
}
if (T % 100 == 0) {
Color (7);
for (int i = 0; i <= 18; i++) {
for (int j = 0; j <= 40; j++) {
if (m[i][j] == 1 && T % 100 == 0) {
SetPos (i, j);
cout << "■";
}
}
}
SetPos (19, 14);
cout << "■";
SetPos (20, 13);
cout <<" █▍";
SetPos (21, 0);
for (int i = 0; i < 39; i++) {
cout << "■";
Color (0);
}
}
if (T % min (50, (2000 - Sco) / 30) == 0) {
Pig++;
Creat (0, -1);
}
Sleep (15);
}
if (Sco < 500) {
if (MessageBox (NULL, "很遗憾,您输了,您还想再来一次吗?", "温馨提示", MB_YESNO) == IDYES) {
goto St;
} else {
return 0;
}
} else {
if (MessageBox (NULL, "恭喜您赢了!您还想再来一次吗?", "温馨提示", MB_YESNO) == IDYES) {
goto St;
} else {
return 0;
}
}
return 0;
}
5.狼人杀
#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<windows.h>
using namespace std;
struct IDname
{
int geshu;
string NAME;
};
IDname jue_se[100];
struct ID
{
int num;
bool life;
string name;
int know;
int how;
};
ID player[21];
int n, MY, kill1, kill2;
char a;
bool jieyao = 1, duyao = 1;
int lieren, shouwei = 0;
void init1()
{
jue_se[1].NAME = "村民 ";
jue_se[2].NAME = "狼人 ";
jue_se[3].NAME = "女巫 ";
jue_se[4].NAME = "预言家 ";
jue_se[5].NAME = "猎人 ";
jue_se[6].NAME = "守卫 ";
}
void init2(int nn)
{
switch (nn)
{
case 6:
jue_se[1].geshu = 3;
jue_se[2].geshu = 2;
jue_se[3].geshu = 1;
jue_se[4].geshu = 0;
jue_se[5].geshu = 0;
jue_se[6].geshu = 0;
break;
case 7:
jue_se[1].geshu = 3;
jue_se[2].geshu = 2;
jue_se[3].geshu = 1;
jue_se[4].geshu = 1;
jue_se[5].geshu = 0;
jue_se[6].geshu = 0;
break;
case 8:
jue_se[1].geshu = 3;
jue_se[2].geshu = 3;
jue_se[3].geshu = 1;
jue_se[4].geshu = 1;
jue_se[5].geshu = 0;
jue_se[6].geshu = 0;
break;
case 9:
jue_se[1].geshu = 3;
jue_se[2].geshu = 3;
jue_se[3].geshu = 1;
jue_se[4].geshu = 1;
jue_se[5].geshu = 1;
jue_se[6].geshu = 0;
break;
case 10:
jue_se[1].geshu = 4;
jue_se[2].geshu = 3;
jue_se[3].geshu = 1;
jue_se[4].geshu = 1;
jue_se[5].geshu = 1;
jue_se[6].geshu = 0;
break;
case 11:
jue_se[1].geshu = 4;
jue_se[2].geshu = 4;
jue_se[3].geshu = 1;
jue_se[4].geshu = 1;
jue_se[5].geshu = 1;
jue_se[6].geshu = 0;
break;
case 12:
jue_se[1].geshu = 4;
jue_se[2].geshu = 4;
jue_se[3].geshu = 1;
jue_se[4].geshu = 1;
jue_se[5].geshu = 1;
jue_se[6].geshu = 1;
break;
default:
cout << "输入错误,再见" << endl;
exit(0);
break;
}
}
int van[10] = { 7,4,6,43,35,1,2,8,20,19 };
void init3(int nn)
{
srand(time(0));
Sleep(rand() % 44);
int x = 10000;
int t = rand();
srand(time(NULL));
int y = van[(rand() % 100 * van[rand() % 10] + t) % 10];
if (nn <= 6)
x = abs(x * 6 / y) % 3 + 1;
else if (nn <= 8)
x = abs(x * 7 / y) % 4 + 1;
else if (nn <= 11)
x = abs(x * 8 / y) % 5 + 1;
else if (nn <= 14)
x = abs(x * 9 / y) % 6 + 1;
do
{
if (nn <= 6)
x = x % 3 + 1;
else if (nn <= 8)
x = x % 4 + 1;
else if (nn <= 11)
x = x % 5 + 1;
else if (nn <= 14)
x = x % 6 + 1;
if (jue_se[x].geshu > 0)
{
player[nn].name = jue_se[x].NAME;
if (player[nn].name == "猎人 ")
lieren = nn;
if (player[nn].name == "守卫 ")
shouwei = nn;
player[nn].life = 1;
player[nn].num = nn;
player[nn].know = 0;
jue_se[x].geshu--;
player[nn].how = 0;
break;
}
} while (jue_se[x].geshu == 0);
}
void printhhh()
{
int cm = 0;
int sz = 0;
for (int i = 1; i <= n; i++)
{
if (player[i].life == 0)
continue;
else if (player[i].name == "村民 ")
cm++;
else if (player[i].name == "女巫 " || player[i].name == "预言家 " || player[i].name == "猎人 " || player[i].name == "守卫 ")
sz++;
}
if (sz == 0 || cm == 0)
cout << "狼人阵营胜利" << endl;
else
cout << "好人阵营胜利" << endl;
for (int i = 1; i <= n; i++)
{
cout << left << setw(3) << player[i].num << ": " << player[i].name << " ";
if (player[i].life == 0)
cout << "死亡" << "\t";
else
cout << "存活" << "\t";
if (player[i].how == 0)
cout << "最终存活 " << endl;
else if (player[i].how == 1)
cout << "最终被狼人杀死" << endl;
else if (player[i].how == 2)
cout << "最终被投票投死" << endl;
else if (player[i].how == 3)
cout << "最终被女巫毒死" << endl;
else if (player[i].how == 4)
cout << "最终被猎人射杀" << endl;
}
system("pause");
system("pause");
system("pause");
}
void print(int day, int ti)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
if (ti == 0)
SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
else
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
cout << "\t\t\t\t第" << day << "天 ";
if (ti == 0)
cout << "白天" << endl;
else
cout << "夜晚" << endl;
cout << "我的位置:" << MY << "号" << endl;
for (int i = 1; i <= 6; i++)
{
cout << player[i].num << "号位 ";
}
cout << endl;
for (int i = 1; i <= 6; i++)
{
if (player[i].life == 1)
{
if (ti == 0)
SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_GREEN);
else
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
cout << "存活 ";
}
else
{
if (ti == 0)
SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_RED);
else
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
cout << "已死亡 ";
}
}
if (ti == 0)
SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
else
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
cout << endl;
for (int i = 1; i <= 6; i++)
{
if (player[i].know == 0)
cout << "未知 ";
else if (player[i].know == 1)
{
if (player[i].name == "狼人 ")
cout << "狼人 ";
else
cout << "好人 ";
}
else if (player[i].know == 2)
cout << player[i].name << " ";
}
cout << endl << endl;
for (int i = 7; i <= n; i++)
{
if (i < 10)
cout << player[i].num << "号位 ";
else
cout << player[i].num << "号位 ";
}
cout << endl;
for (int i = 7; i <= n; i++)
{
if (player[i].life == 1)
{
if (ti == 0)
SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_GREEN);
else
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
cout << "存活 ";
}
else
{
if (ti == 0)
SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_RED);
else
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
cout << "已死亡 ";
}
}
if (ti == 0)
SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
else
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
cout << endl;
for (int i = 7; i <= n; i++)
{
if (player[i].know == 0)
cout << "未知 ";
else if (player[i].know == 1)
{
if (player[i].name == "狼人 ")
cout << "狼人 ";
else
cout << "好人 ";
}
else if (player[i].know == 2)
cout << player[i].name << " ";
}
cout << endl << endl;
}
int shou = 0;
void shoushui(int hhh, int hhhh)
{
int x;
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "守~卫~请~睁~眼~~~" << endl;
Sleep(3000);
system("cls");
print(hhh, hhhh);
if (MY == shouwei && player[MY].life == 1)
{
cout << "请问你要守护谁?" << endl << "输入:";
cin >> x;
while (x == shou || x<1 || x>n || player[x].life == 0)
{
cout << "输入错误,请重新输入" << endl << "输入:";
cin >> x;
}
shou = x;
}
else if (player[shouwei].life == 1)
{
cout << "请问你要守护谁?" << endl;
Sleep(rand() % 98);
srand(time(0));
x = rand() % n + 1;
while (x == shou || player[x].life == 0)
{
Sleep(rand() % 98);
srand(time(0));
x = rand() % n + 1;
}
shou = x;
}
else
{
cout << "请问你要守护谁?" << endl;
Sleep(3000);
shou = -1;
}
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "守~卫~请~闭~眼~~~" << endl;
}
struct tou
{
int xxx;
int num;
int toupiaoquan;
};
tou TOU[13];
bool cmp(tou x, tou y)
{
if (x.xxx == y.xxx)
return x.num < y.num;
return x.xxx > y.xxx;
}
bool cmp1(tou x, tou y)
{
return x.num < y.num;
}
void toupiao(int ddd, int nnn)
{
//--------1--------
int x;
Sleep(2000);
system("cls");
print(ddd, nnn);
cout << "现在大家请投票";
for (int i = 1; i <= 3; i++)
{
cout << ".";
Sleep(500);
}
cout << endl;
for (int i = 1; i <= n; i++)
{
TOU[i].num = i;
TOU[i].toupiaoquan = 1;
TOU[i].xxx = 0;
}
for (int i = 1; i <= n; i++)
{
if (player[i].life == 1)
{
Sleep(3000);
if (i == MY)
{
cout << "请投票...(0弃权)" << endl;
cin >> x;
while (player[x].life == 0 && x != 0)
{
cin >> x;
}
if (x == 0)
cout << MY << "号玩家弃权" << endl;
else
cout << MY << "号玩家投给了" << x << "号玩家" << endl;
}
else
{
srand(time(0));
if (player[i].name == "狼人 ")
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || player[x].name == "狼人 " || x == i))
{
Sleep(rand() % 98);
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
else if (player[i].name == "预言家 ")
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || player[x].name != "狼人 " || x == i))
{
Sleep(rand() % 98);
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
else
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || x == i))
{
Sleep(rand() % 98);
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
}
if (x != 0)
TOU[x].xxx++;
}
}
Sleep(3000);
sort(TOU + 1, TOU + n + 1, cmp);
if (TOU[2].xxx != TOU[1].xxx)
{
cout << "投票结束," << TOU[1].num << "号投票出局" << endl;
player[TOU[1].num].life = 0;
player[TOU[1].num].how = 2;
Sleep(3000);
return;
}
else
{
TOU[1].toupiaoquan = 0;
TOU[2].toupiaoquan = 0;
system("cls");
print(ddd, nnn);
cout << TOU[1].num << "号," << TOU[2].num << "号";
int i;
for (i = 3; i <= n; i++)
{
if (TOU[i].xxx == TOU[1].xxx)
{
TOU[i].toupiaoquan = 0;
cout << "," << TOU[i].num << "号";
}
else
break;
}
if (i == n + 1)
{
for (int i = 1; i <= n; i++)
TOU[i].toupiaoquan = 1;
}
cout << "平票" << endl;
}
//--------2--------
sort(TOU + 1, TOU + n + 1, cmp1);
cout << "请再次投票";
for (int i = 1; i <= 3; i++)
{
cout << ".";
Sleep(500);
}
cout << endl;
for (int i = 1; i <= n; i++)
{
if (player[i].life == 1 && TOU[i].toupiaoquan == 1)
{
Sleep(3000);
if (i == MY)
{
cout << "请投票...(0弃权)" << endl;
cin >> x;
while ((player[x].life == 0 || TOU[x].toupiaoquan == 1) && x != 0)
{
cin >> x;
}
if (x == 0)
cout << MY << "号玩家弃权" << endl;
else
cout << MY << "号玩家投给了" << x << "号玩家" << endl;
}
else
{
srand(time(0));
if (player[i].name == "狼人 ")
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || player[x].name == "狼人 " || x == i || TOU[x].toupiaoquan == 1))
{
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
else if (player[i].name == "预言家 ")
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || player[x].name != "狼人 " || x == i || TOU[x].toupiaoquan == 1))
{
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
else
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || x == i || TOU[x].toupiaoquan == 1))
{
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
}
if (x != 0 && TOU[i].toupiaoquan == 1)
TOU[x].xxx++;
}
}
Sleep(3000);
sort(TOU + 1, TOU + n + 1, cmp);
if (TOU[2].xxx != TOU[1].xxx)
{
cout << "投票结束," << TOU[1].num << "号投票出局" << endl;
player[TOU[1].num].life = 0;
player[TOU[1].num].how = 2;
Sleep(3000);
return;
}
else
{
TOU[1].toupiaoquan = 0;
TOU[2].toupiaoquan = 0;
system("cls");
print(ddd, nnn);
cout << TOU[1].num << "号," << TOU[2].num << "号";
int i;
for (i = 3; i <= n; i++)
{
if (TOU[i].xxx == TOU[1].xxx)
{
TOU[i].toupiaoquan = 0;
cout << "," << TOU[i].num << "号";
}
else
break;
}
if (i == n + 1)
{
for (int i = 1; i <= n; i++)
TOU[i].toupiaoquan = 1;
}
cout << "平票" << endl;
}
//--------3--------
sort(TOU + 1, TOU + n + 1, cmp1);
cout << "请再次投票";
for (int i = 1; i <= 3; i++)
{
cout << ".";
Sleep(500);
}
cout << endl;
for (int i = 1; i <= n; i++)
{
if (player[i].life == 1 && TOU[i].toupiaoquan == 1)
{
Sleep(3000);
if (i == MY)
{
cout << "请投票...(0弃权)" << endl;
cin >> x;
while ((player[x].life == 0 || TOU[x].toupiaoquan == 1) && x != 0)
{
cin >> x;
}
if (x == 0)
cout << MY << "号玩家弃权" << endl;
else
cout << MY << "号玩家投给了" << x << "号玩家" << endl;
}
else
{
srand(time(0));
if (player[i].name == "狼人 ")
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || player[x].name == "狼人 " || x == i || TOU[x].toupiaoquan == 1))
{
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
else if (player[i].name == "预言家 " || player[i].name == "猎人 ")
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || player[x].name != "狼人 " || x == i || TOU[x].toupiaoquan == 1))
{
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
else
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || x == i || TOU[x].toupiaoquan == 1))
{
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
}
if (x != 0 && TOU[i].toupiaoquan == 1)
TOU[x].xxx++;
}
}
Sleep(3000);
sort(TOU + 1, TOU + n + 1, cmp);
if (TOU[2].xxx != TOU[1].xxx)
{
cout << "投票结束," << TOU[1].num << "号投票出局" << endl;
player[TOU[1].num].life = 0;
player[TOU[1].num].how = 2;
}
else
{
cout << "投票结束,无人出局" << endl;
}
Sleep(5000);
}
bool game_over()
{
int pingmin = 0;
int langren = 0;
int shenzhi = 0;
for (int i = 1; i <= n; i++)
{
if (player[i].life == 0)
continue;
if (player[i].name == "狼人 ")
langren++;
else if (player[i].name == "村民 ")
pingmin++;
else if (player[i].name == "女巫 " || player[i].name == "预言家 " || player[i].name == "猎人 ")
shenzhi++;
}
if (shenzhi == 0 || langren == 0 || pingmin == 0)
return 1;
return 0;
}
void night()
{
system("cls");
system("color 0f");
print(1, 1);
cout << "天~黑~请~闭~眼~~~" << endl;
if (n >= 12)
shoushui(1, 1);
Sleep(3000);
system("cls");
print(1, 1);
cout << "狼~人~请~睁~眼~~~" << endl;
if (player[MY].name == "狼人 ")
{
Sleep(1000);
cout << "你的同伴有:";
for (int i = 1; i <= n; i++)
{
if (i == MY)
continue;
if (player[i].name == "狼人 ")
{
cout << player[i].num << "号 ";
player[i].know = 2;
}
}
Sleep(3000);
cout << endl << "请问你们要杀谁:" << endl << "输入:";
cin >> kill1;
Sleep(1500);
system("cls");
print(1, 1);
cout << "今晚你们要杀的是" << kill1 << "号玩家" << endl;
}
else
{
Sleep(4000);
system("cls");
print(1, 1);
cout << "请问你们要杀谁?" << endl;
do
{
Sleep(rand() % 18);
srand(time(0));
int x = rand() % n + 1;
if (player[x].name != "狼人 " && player[x].life == 1)
{
kill1 = x;
break;
}
} while (1);
Sleep(5000);
}
Sleep(3000);
system("cls");
print(1, 1);
cout << "狼~人~请~闭~眼~~~" << endl;
Sleep(2000);
system("cls");
print(1, 1);
cout << "女~巫~请~睁~眼~~~" << endl;
Sleep(2000);
system("cls");
print(1, 1);
if (player[MY].name == "女巫 " && player[MY].life == 1)
{
Sleep(1000);
if (jieyao == 1)
{
cout << "今晚" << kill1 << "号玩家被杀" << endl;
Sleep(500);
cout << "请问你要救吗???" << endl << "A. 救 B.不救" << endl << "输入:";
cin >> a;
if (a == 'A')
{
system("cls");
print(1, 1);
cout << "请问你要毒吗???" << endl;
Sleep(2000);
system("cls");
print(1, 1);
cout << "今晚" << kill1 << "号玩家被你解救" << endl;
jieyao = 0;
if (shou != kill1)
kill1 = 0;
}
else
{
if (shou == kill1)
kill1 = 0;
Sleep(2000);
system("cls");
print(1, 1);
cout << "请问你要毒吗???" << endl << "A. 毒 B.不毒" << endl << "输入:";
cin >> a;
if (a == 'A')
{
cout << "请问你要毒谁???" << endl << "输入:";
cin >> kill2;
while (player[kill2].life != 1)
{
cout << "输入错误,请重新输入:" << endl;
cin >> kill2;
}
duyao = 0;
}
}
}
else
{
if (shou == kill1)
kill1 = 0;
Sleep(2000);
system("cls");
print(1, 1);
cout << "请问你要毒吗???" << endl << "A. 毒 B.不毒" << endl << "输入:";
cin >> a;
if (a == 'A')
{
cout << "请问你要毒谁???" << endl << "输入:";
cin >> kill2;
while (player[kill2].life != 1)
{
cout << "输入错误,请重新输入:" << endl;
cin >> kill2;
}
duyao = 0;
}
}
}
else
{
bool b = 0;
cout << "请问你是否要用解药???" << endl;
int FFF = 0, kkkk;
for (int i = 1; i <= n; i++)
{
if (player[i].life == 1 && player[i].name == "村民 ")
FFF++;
if (player[i].name == "女巫 ")
kkkk = i;
}
if (jieyao == 1 && player[kkkk].life == 1)
{
if (FFF == 1)
{
if (shou == kill1)
jieyao = 1;
else
jieyao = 0;
kill1 = 0;
b = 1;
}
else
for (int i = 1; i <= n; i++)
{
if (player[i].name == "女巫 " && kill1 == i)
{
kill1 = 0;
if (shou == kill1)
jieyao = 1;
else
jieyao = 0;
b = 1;
break;
}
else if (player[i].name == "预言家 " && kill1 == i)
{
kill1 = 0;
if (shou == kill1)
jieyao = 1;
else
jieyao = 0;
b = 1;
break;
}
}
}
Sleep(3000);
if (b == 0 && duyao == 1 && player[kkkk].life == 1)
{
system("cls");
print(1, 1);
cout << "请问你是否要用毒药???" << endl;
srand(time(0));
int x = rand() % 2;
Sleep(1500);
cout << "请问你要毒谁???" << endl;
if (x == 1)
{
duyao = 0;
int y = rand() % n + 1;
while ((player[y].name == "女巫 " || player[y].name == "预言家 " || y == kill1) || player[y].life == 0)
y = rand() % n + 1;
kill2 = y;
}
}
else
{
Sleep(3000);
system("cls");
print(1, 1);
cout << "请问你是否要用毒药???" << endl;
Sleep(3000);
cout << "请问你要毒谁???" << endl;
Sleep(3000);
}
}
Sleep(3000);
system("cls");
print(1, 1);
cout << "女~巫~请~闭~眼~~~" << endl;
if (n > 6)
{
Sleep(3000);
system("cls");
print(1, 1);
cout << "预~言~家~请~睁~眼~~~" << endl;
if (player[MY].name == "预言家 ")
{
Sleep(3000);
cout << "请问你想查验谁???" << endl << "输入:";
int x;
cin >> x;
player[x].know = 1;
Sleep(2000);
system("cls");
print(1, 1);
cout << "他的身份是:";
if (player[x].name == "狼人 ")
cout << "狼人" << endl;
else
cout << "好人" << endl;
Sleep(3000);
}
else
{
Sleep(3000);
cout << "请问你想查验谁???" << endl;
Sleep(3000);
system("cls");
print(1, 1);
cout << "他的身份是:......";
Sleep(3000);
}
Sleep(3000);
system("cls");
print(1, 1);
cout << "预~言~家~请~闭~眼~~~" << endl;
}
Sleep(3000);
if (kill1 != 0)
player[kill1].life = 0;
if (kill2 != 0)
player[kill2].life = 0;
player[kill1].how = 1;
player[kill2].how = 3;
system("cls");
system("color F0");
print(2, 0);
}
void night2(int hhh, int hhhh)
{
system("cls");
system("color 0f");
print(hhh, hhhh);
cout << "天~黑~请~闭~眼~~~" << endl;
if (n >= 12)
shoushui(hhh, hhhh);
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "狼~人~请~睁~眼~~~" << endl;
if (player[MY].name == "狼人 " && player[MY].life == 1)
{
Sleep(3000);
cout << endl << "请问你们要杀谁:" << endl << "输入:";
cin >> kill1;
Sleep(1500);
system("cls");
print(hhh, hhhh);
cout << "今晚你们要杀的是" << kill1 << "号玩家" << endl;
}
else
{
Sleep(4000);
system("cls");
print(hhh, hhhh);
cout << "请问你们要杀谁?" << endl;
do
{
srand(time(0));
int x = rand() % n + 1;
if (player[x].name != "狼人 " && player[x].life == 1)
{
kill1 = x;
break;
}
} while (1);
Sleep(5000);
}
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "狼~人~请~闭~眼~~~" << endl;
Sleep(2000);
system("cls");
print(hhh, hhhh);
cout << "女~巫~请~睁~眼~~~" << endl;
Sleep(2000);
system("cls");
print(hhh, hhhh);
if (player[MY].name == "女巫 " && player[MY].life == 1)
{
Sleep(1000);
if (jieyao == 1)
{
cout << "今晚" << kill1 << "号玩家被杀" << endl;
Sleep(500);
cout << "请问你要救吗???" << endl << "A. 救 B.不救" << endl << "输入:";
cin >> a;
if (a == 'A')
{
system("cls");
print(hhh, hhhh);
cout << "请问你要毒吗???" << endl;
Sleep(2000);
system("cls");
print(hhh, hhhh);
cout << "今晚" << kill1 << "号玩家被你解救" << endl;
jieyao = 0;
if (shou != kill1)
kill1 = 0;
}
else
{
if (shou == kill1)
kill1 = 0;
Sleep(2000);
system("cls");
print(hhh, hhhh);
cout << "请问你要毒吗???" << endl << "A. 毒 B.不毒" << endl << "输入:";
cin >> a;
if (a == 'A')
{
cout << "请问你要毒谁???" << endl << "输入:";
cin >> kill2;
while (player[kill2].life != 1)
{
cout << "输入错误,请重新输入:" << endl;
cin >> kill2;
}
duyao = 0;
}
}
}
else if (duyao == 1)
{
if (shou == kill1)
kill1 = 0;
Sleep(2000);
system("cls");
print(hhh, hhhh);
cout << "请问你要毒吗???" << endl << "A. 毒 B.不毒" << endl << "输入:";
cin >> a;
if (a == 'A')
{
cout << "请问你要毒谁???" << endl << "输入:";
cin >> kill2;
while (player[kill2].life != 1)
{
cout << "输入错误,请重新输入:" << endl;
cin >> kill2;
}
duyao = 0;
}
}
else
{
Sleep(2000);
system("cls");
print(hhh, hhhh);
cout << "请问你要毒吗???" << endl;
}
}
else
{
bool b = 0;
cout << "请问你是否要用解药???" << endl;
int FFF = 0, kkkk;
for (int i = 1; i <= n; i++)
{
if (player[i].life == 1 && player[i].name == "村民 ")
FFF++;
if (player[i].name == "女巫 ")
kkkk = i;
}
if (jieyao == 1 && player[kkkk].life == 1)
{
if (FFF == 1)
{
if (shou == kill1)
jieyao = 1;
else
jieyao = 0;
kill1 = 0;
b = 1;
}
else
for (int i = 1; i <= n; i++)
{
if (player[i].name == "女巫 " && kill1 == i)
{
kill1 = 0;
if (shou == kill1)
jieyao = 1;
else
jieyao = 0;
b = 1;
break;
}
else if (player[i].name == "预言家 " && kill1 == i)
{
kill1 = 0;
if (shou == kill1)
jieyao = 1;
else
jieyao = 0;
b = 1;
break;
}
}
}
Sleep(3000);
if (b == 0 && duyao == 1 && player[kkkk].life == 1)
{
system("cls");
print(hhh, hhhh);
cout << "请问你是否要用毒药???" << endl;
srand(time(0));
int x = rand() % 2;
Sleep(1500);
cout << "请问你要毒谁???" << endl;
if (x == 1)
{
duyao = 0;
int y = rand() % n + 1;
while ((player[y].name == "女巫 " || player[y].name == "预言家 " || y == kill1) || player[y].life == 0)
y = rand() % n + 1;
kill2 = y;
}
}
else
{
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "请问你是否要用毒药???" << endl;
Sleep(3000);
cout << "请问你要毒谁???" << endl;
Sleep(3000);
}
}
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "女~巫~请~闭~眼~~~" << endl;
if (n > 6)
{
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "预~言~家~请~睁~眼~~~" << endl;
if (player[MY].name == "预言家 " && player[MY].life == 1)
{
Sleep(3000);
cout << "请问你想查验谁???" << endl << "输入:";
int x;
cin >> x;
player[x].know = 1;
Sleep(2000);
system("cls");
print(hhh, hhhh);
cout << "他的身份是:";
if (player[x].name == "狼人 ")
cout << "狼人" << endl;
else
cout << "好人" << endl;
Sleep(3000);
}
else
{
Sleep(3000);
cout << "请问你想查验谁???" << endl;
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "他的身份是:......";
Sleep(3000);
}
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "预~言~家~请~闭~眼~~~" << endl;
}
Sleep(3000);
if (kill1 != 0)
player[kill1].life = 0;
if (kill2 != 0)
player[kill2].life = 0;
player[kill1].how = 1;
player[kill2].how = 3;
system("cls");
system("color F0");
print(hhh + 1, 0);
}
bool lr = 0;
void panduanlieren()
{
if (lr == 1)
return;
if (MY == lieren)
{
cout << "请射杀一名玩家" << endl;
int x;
cin >> x;
while (player[x].life != 1)
{
cout << "输入错误,请重新输入" << endl;
cin >> x;
}
Sleep(1000);
cout << lieren << "号猎人发动技能,开枪带走了" << x << "号" << endl;
player[x].life = 0;
player[x].how = 4;
}
else if (n >= 9)
{
srand(time(0));
int x = rand() % n + 1;
while (player[x].life != 1)
{
x = rand() % n + 1;
}
Sleep(1000);
cout << lieren << "号猎人发动技能,开枪带走了" << x << "号" << endl;
player[x].life = 0;
player[x].how = 4;
}
lr = 1;
}
void print1()
{
cout << "天亮了,昨晚";
if (kill1 != 0 || kill2 != 0)
{
cout << kill1 << "号";
if (kill2 != 0)
{
cout << "," << kill2 << "号";
kill2 = 0;
}
cout << "被杀" << endl;
}
else
cout << "是平安夜" << endl;
}
int main()
{
system("cls");
cout << " " << "狼人杀online" << endl;
cout << "请输入人数个数:" << endl;
scanf("%d", &n);
cout << "加载时间长,请耐心等待";
init1();
init2(n);
int k = 1;
do
{
srand(time(0));
init3(k);
cout << ".";
Sleep(17);
k++;
} while (k <= n);
system("cls");
system("color F0");
cout << "游戏即将开始";
for (int i = 1; i <= 6; i++)
{
cout << ".";
Sleep(500);
}
Sleep(1500);
cout << endl << endl << "请大家查看身份牌......" << endl;
Sleep(45);
srand(time(0));
MY = rand() % n + 1;
cout << "您的身份是:" << player[MY].name << endl;
Sleep(500);
cout << "在" << player[MY].num << "号位上" << endl;
system("pause");
system("cls");
player[MY].know = 2;
print(1, 0);
cout << "即将进入夜晚";
for (int i = 1; i <= 6; i++)
{
cout << ".";
Sleep(500);
}
night();
print1();
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
if (player[lieren].life == 0 && lr == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
toupiao(2, 0);
system("cls");
print(2, 0);
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
else if (player[lieren].life == 0 && lr == 0)
{
panduanlieren();
}
cout << "即将进入夜晚";
for (int i = 1; i <= 6; i++)
{
cout << ".";
Sleep(500);
}
night2(2, 1);
print1();
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
if (player[lieren].life == 0 && lr == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
toupiao(3, 0);
system("cls");
print(3, 0);
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
else if (player[lieren].life == 0 && lr == 0)
{
panduanlieren();
}
cout << "即将进入夜晚";
for (int i = 1; i <= 6; i++)
{
cout << ".";
Sleep(500);
}
night2(3, 1);
print1();
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
if (player[lieren].life == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
toupiao(4, 0);
system("cls");
print(4, 0);
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
else if (player[lieren].life == 0 && lr == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
cout << "即将进入夜晚";
for (int i = 1; i <= 6; i++)
{
cout << ".";
Sleep(500);
}
night2(4, 1);
print1();
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
if (player[lieren].life == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
toupiao(5, 0);
system("cls");
print(5, 0);
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
else if (player[lieren].life == 0 && lr == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
cout << "即将进入夜晚";
for (int i = 1; i <= 6; i++)
{
cout << ".";
Sleep(500);
}
night2(5, 1);
print1();
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
if (player[lieren].life == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
toupiao(6, 0);
system("cls");
print(6, 0);
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
else if (player[lieren].life == 0 && lr == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
cout << "即将进入夜晚";
for (int i = 1; i <= 6; i++)
{
cout << ".";
Sleep(500);
}
night2(6, 1);
print1();
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
if (player[lieren].life == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
toupiao(7, 0);
system("cls");
print(7, 0);
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
else if (player[lieren].life == 0 && lr == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
while (1)
system("pause");
return 0;
}