机房小游戏
Posted herobrine-life
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了机房小游戏相关的知识,希望对你有一定的参考价值。
众所周知,在机房里是不能玩游戏的,但某些人仍然胆大包天,想在老师们的火眼金睛下偷偷地“爽”一把,这里我就用我以往的经验给大家推荐一些小游戏。
@(qwq)
网页小游戏
这些是作者收录的一些有趣的网页小游戏,可以用来打发无聊的信息学生活。
slay.one
这款游戏,许多OIer都非常地熟悉,是一款2D的枪战小游戏,正版在steam上面有,可是贵的出奇,对于我们这种穷人,只能在网页上玩玩盗版了。
网址
名字大作战
这款游戏,真的好像不算游戏,我也不再介绍了。
网址
一些乱七八糟的小游戏
丛林大作战
网址
这是一款类似于球球大作战的小游戏,比较有趣,但有些卡,不是特别推荐,但也可以试一试。
C++小游戏
这是作者收录的一些C++编的小游戏,值得一玩。
猜数字:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
cout << "我这里有一个数,现在请你猜猜它"<<endl;
srand(time(NULL));
int x = rand() % 50;
for (int i =1;i <= 7;i++)
int y;
cin >> y;
if (y<x)
cout << "不好意思,你猜小了" << endl;
else if (y>x)
cout << "对不起,你猜大了" <<endl;
else
cout << "恭喜恭喜,猜对了!!!" << endl;
return 0;
cout << "你的次数用完了,你失败了"<<endl<<"那个数是"<<x;
return 0;
冒险小游戏:
#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("这是一个勇者的世界! 雅莉萨斯国的XXX公主被陌生人绑架了!\n\n 伟大的勇者啊~拿起你们的武器,营救XXX公主!\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,"PQH")==0)
SlowDisplay("封印多年的 PQH 啊!你终于可以重见天日了!\n\n\n PQH 重新启动... 随即... 暴走!!!\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);
俄罗斯方块:
#include<cstdio>
#include<windows.h>
#include<ctime>
int a[4][4],i,j,xc,yc,mouse=0,ok=0,record[2][9],foot=9,winner,first=0,who=0;
void Place(const int x, const int y)
COORD PlaceCursorHere;PlaceCursorHere.X = y;PlaceCursorHere.Y = x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), PlaceCursorHere);
return;
void color(int x)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x);
int search(int x0,int y0,int x,int y)
mouse=GetAsyncKeyState(VK_LBUTTON);
POINT pt; HWND h=GetForegroundWindow(); GetCursorPos(&pt); ScreenToClient(h,&pt);
if(pt.x>=x0&&pt.y>=y0&&pt.x<=x&&pt.y<=y)
if(mouse!=0) Sleep(100); return 2; else return 1;
else return 0;
bool check(int x)
int b=0,c=0,d=0,e=0;
for(i=1;i<=3;i++)
for(j=1;j<=3;j++) b+=a[i][j]; c+=a[j][i]; d+=a[i][i]; e+=a[i][4-i];
if(b==x||c==x||d==x||e==x) return true; b=0; c=0;
return false;
void pcmove()
int x=10,b=0,c=0,d=0,e=0; xc=0; yc=0;
while(x>0)
for(i=1;i<=3;i++)
b=0; c=0; for(j=1;j<=3;j++) b+=a[i][j]; c+=a[j][i]; d+=a[i][i]; e+=a[i][4-i];
if(b==x) for(j=1;j<=3;j++) if(a[i][j]==0) xc=i; yc=j; return; if(c==x) for(j=1;j<=3;j++) if(a[j][i]==0) xc=j; yc=i; return;
if(d==x) for(j=1;j<=3;j++) if(a[j][j]==0) xc=yc=j; return; if(e==x) for(j=1;j<=3;j++) if(a[j][4-j]==0) xc=j; yc=4-j; return;
x-=8;
if(a[2][2]==0) xc=yc=2; return; x=2;
while(x>0) for(i=1;i<=3;i+=x) for(j=1;j<=3;j+=x) if(a[i][j]==0) xc=i; yc=j; return; x--;
void show()
int x=foot;
for(i=1;i<=3;i++) for(j=1;j<=3;j++) if(a[i][j]!=0) if(a[i][j]==1) color(15); else color(11); Place(2*i-1,4*j-2); printf("●");
color(15); Place(7,0);
if(who==0) if(foot%2==1) printf("1号"); else printf("2号"); else printf("电脑");
if(who==0||first==1) x--;
printf("下子:(%d,%d)",record[0][8-x],record[1][8-x]);
void button(int x)
if(x<3)
Place(x*3,15); printf("┌┄┄┐");
Place(x*3+1,17); if(x==0)if(ok==0) printf("开始"); else printf("悔棋"); if(x==1) printf("重来"); if(x==2) printf("退出");
Place(x*3+2,15); printf("└┄┄┘");
if(x>2&&x<6)
Place(10,(x-4)*7); printf("┌┄┐");
Place(11,(x-4)*7+2); if(x==4) printf("是"); else printf("否");
Place(12,(x-4)*7); printf("└┄┘");
if(x>5&&x<8)
Place(10,(x-6)*12); printf("┌┄┄┄┄┐");
Place(11,(x-6)*12+2); if(x==6) printf("人机对战"); else printf("人人对战");
Place(12,(x-6)*12); printf("└┄┄┄┄┘");
if(x>7)
Place(10,(x-8)*12); printf("┌┄┄┄┄┐");
Place(11,(x-8)*12+2); if(x==8) printf(" 我先手 "); else printf("电脑先手");
Place(12,(x-8)*12); printf("└┄┄┄┄┘");
void menu(int x)
int k,l;
if(x==0)
if(ok==0) ok=1; return;
else if(9-foot>1)
foot+=2; for(i=9-foot;i<=11-foot;i++) a[record[0][i]][record[1][i]]=0; record[0][i]=record[1][i]=0;
for(i=1;i<=3;i++) for(j=1;j<=3;j++) Place(2*i-1,4*j-2); printf(" "); show();
if(x>0&&x<3)
for(l=10;l<=12;l++) for(j=1;j<=22;j++) Place(l,j); printf(" ");
Place(9,1); printf("你想"); if(x==1) printf("重来吗?"); if(x==2) printf("退出吗?");
button(4); button(5);
while(1)
mouse=GetAsyncKeyState(VK_LBUTTON);
for(i=0;i<=1;i++)
k=search(7+i*55,165,40+i*55,200);
if(k!=2) if(k==1) color(15); else color(7); button(i+4);
else
for(l=9;l<=12;l++) for(j=1;j<=12;j++) Place(l,j); printf(" ");
if(i==0) if(x==1) ok=2; else exit(0); return;
Sleep(50);
if(x>2&&x<5) if(x==3) who=1; return; else who=0; return;
if(x>4) if(x==5) first=0; return; else first=1; return;
void click()
for(i=0;i<=2;i++)
mouse=GetAsyncKeyState(VK_LBUTTON);
int k=search(125,i*50+5,175,i*50+40);
if(k!=2) if(k==1) color(15); else color(7); button(i); color(7);
elsemenu(i); return;
Sleep(50);
void humove()
while(1)
for(i=1;i<=3;i++) for(j=1;j<=3;j++) if(search(7+(i-1)*32,7+(j-1)*32,7+i*32,7+j*32)==2&&a[j][i]==0)
if(who==0&&foot%2!=1) a[j][i]=5; else a[j][i]=1; record[0][9-foot]=j; record[1][9-foot]=i; return; click(); if(ok==2) return;
void replace()
int k,l,p,q;
Place(7,0); for(i=1;i<=15;i++) printf(" "); for(i=1;i<=3;i++) for(j=1;j<=3;j++) Place(2*i-1,4*j-2); printf(" "); a[i][j]=0;
for(i=0;i<2;i++) for(j=0;j<9;j++) record[i][j]=0; foot=9; winner=0; first=0; who=0; ok=1; button(6); button(7);
while(1)
for(i=0;i<=1;i++)
mouse=GetAsyncKeyState(VK_LBUTTON); k=search(i*80+7,165,i*80+103,200); q=search(125,105,175,140);
if(k!=2) if(k==1) color(15); else color(7); button(i+6); color(7);
else
menu(i+3); for(l=10;l<=12;l++) for(j=1;j<=22;j++) Place(l,j); printf(" ");
if(who==1)
button(7); button(8);
while(1)
for(j=0;j<=1;j++)
mouse=GetAsyncKeyState(VK_LBUTTON); k=search(j*80+7,165,j*80+103,200); q=search(125,105,175,140);
if(k!=2) if(k==1) color(15); else color(7); button(j+8); color(7);
elsemenu(j+5); for(l=10;l<=12;l++) for(p=1;p<=22;p++) Place(l,p); printf(" "); return;
if(q!=2) if(q==1) color(15); else color(7); button(2); color(7); else menu(2);
Sleep(50);
return;
if(q!=2) if(q==1) color(15); else color(7); button(2); color(7); else menu(2);
Sleep(50);
int main()
printf("┌─┬─┬─┐\n\n├─┼─┼─┤\n\n├─┼─┼─┤\n\n└─┴─┴─┘\n\n");
for(i=0;i<3;i++) button(i);
while(ok==0) click();
while(1)
replace();
while(foot>0&&ok!=0)
if(first!=1) humove(); show(); if(check(3)) winner=1; ok=0; break; foot--; if(foot<=0||ok==0||ok==2) break;
if(who==0&&check(15)) winner=2;ok=0;break;
if(who!=0) pcmove(); record[0][9-foot]=xc; record[1][9-foot]=yc; a[xc][yc]=5; show(); if(check(15)) winner=2;ok=0; foot--; first=0;
if(ok==2) ok=1; continue; Place(7,0); for(i=1;i<=15;i++) printf(" ");
Place(7,4); color(15); if(winner==0) printf("平局!");
if(who!=0) if(winner==1) printf("你赢了!"); if(winner==2) printf("你输了!"); Sleep(50);
else if(winner==1) printf("1号赢了!"); if(winner==2) printf("2号赢了!"); Sleep(50);
ok=0; while(ok==0) click();
#include<cstdio>
#include<windows.h>
#include<ctime>
void Place(const int x, const int y)
COORD PlaceCursorHere;PlaceCursorHere.X = y;PlaceCursorHere.Y = x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), PlaceCursorHere);
return;
void color(int x)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x);
void appear()
for(i=3;i<=22;i++) for(j=1;j<=15;j++) if(a[i][j]!=0) Place(i-2,2*j); printf("■");
void disappear()
for(i=3;i<=22;i++) for(j=1;j<=15;j++) if(a[i][j]==2) Place(i-2,2*j); printf(" ");
int search(int x0,int y0,int x,int y)
POINT pt; HWND h=GetForegroundWindow(); GetCursorPos(&pt); ScreenToClient(h,&pt);
if(pt.x>=x0&&pt.y>=y0&&pt.x<=x&&pt.y<=y)
if(mouse!=0) Sleep(100); return 2; else return 1;
else return 0;
void button(int x)
int m=x*10;
if(x<3)
Place(22,m); printf("┌┄┄┄┐");
Place(23,m);
if(x==0) if(ok!=0) printf("┆start ┆"); else printf("┆pause ┆");
if(x==1) printf("┆reset ┆"); if(x==2) printf("┆ exit ┆");
Place(24,m); printf("└┄┄┄┘");
else
Place(9,m-33); printf("┌┄┄┐");
Place(10,m-33);
if(x==4) printf("┆yes ┆"); else printf("┆ no ┆");
Place(11,m-33); printf("└┄┄┘");
void menu(int x)
int k,l;
if(x==0)
if(ok!=0) ok=0; return;
else while(1)
mouse=GetAsyncKeyState(VK_LBUTTON);
Place(9,13); printf("pause");
if(search(7,360,71,390)==2) break; Sleep(50);
Place(9,12); for(j=1;j<=6;j++) printf(" "); //appear();
else
for(i=1;i<=20;i++) for(j=2;j<=30;j++) Place(i,j); printf(" ");
Place(7,2); for(i=1;i<=15;i++) printf("┄"); Place(12,2); for(i=1;i<=15;i++) printf("┄");
Place(8,6); printf("Do you want to "); if(x==1) printf("reset?"); if(x==2) printf("exit?");
button(4); button(5);
while(1)
mouse=GetAsyncKeyState(VK_LBUTTON);
for(i=0;i<=1;i++)
k=search(63+i*80,150,110+i*80,180);
if(k!=2) if(k==1) color(15); else color(7); button(i+4);
else
for(l=7;l<=12;l++) for(j=2;j<=30;j++) Place(l,j); printf(" ");
if(i==0) if(x==1) ok=2; else exit(0); return;
Sleep(50);
void click()
for(i=0;i<=2;i++)
mouse=GetAsyncKeyState(VK_LBUTTON);
int k=search(i*80+7,360,i*80+71,390);
if(k!=2) if(k==1) color(15); else color(7); button(i); color(7);
elsemenu(i); return;
Sleep(50);
void ss()
Place(9,39); printf("%d",score);
if(score>=speed*100)
speed++; ti=ti-200;
if(ti<0) ti=0;
else
for(i=1;i<=4;i++)
Place(9,12); printf("speed up!"); Sleep(70);
Place(9,12); for(j=1;j<=9;j++) printf(" "); Sleep(70);
Sleep(200);
if(best<score) best=score;
appear(); Place(12,39); printf("%d",speed); Place(15,39); printf("%d",best);
void replace()
for(i=1;i<=20;i++) for(j=2;j<=30;j++) Place(i,j); printf(" ");
for(i=0;i<=22;i++) for(j=1;j<=15;j++) a[i][j]=0; for(i=1;i<=15;i++) a[23][i]=1; for(i=1;i<=23;i++) a[i][0]=1; a[i][16]=1; ss();
tim=800;ti=800;shape=0;add=0;score=0;speed=1;
void change(int x)
int q=0,l;
for(l=1;l<=x;l++)
for(j=0;j<=2+add;j++)
for(i=2+add;i>=0;i--)
turn[j][q]=ta[i][j];
q++;
if(q>2+add) q=0;
for(i=0;i<=3;i++) for(j=0;j<=3;j++) ta[i][j]=turn[i][j];
void born()
int x,q=0; srand(time(NULL)); bn=b; shape=nextshape; x=rand()%12+1; if(b==5&&x>1) x--; add=1;
for(i=0;i<=2+add;i++) for(j=x;j<=x+2+add;j++) a[i][j]=nex[i][q]; q++; if(q>2+add) q=0;add=0;
void next()
srand(time(NULL)); b=rand()%7; nextshape=rand()%4; add=0;
for(i=3;i<=6;i++) for(j=37;j<=45;j++) Place(i,j); printf(" ");
for(i=0;i<=3;i++) for(j=0;j<=3;j++) nex[i][j]=turn[i][j]=ta[i][j]=0; ta[1][1]=2;
if(b==0) ta[1][2]=ta[1][0]=ta[0][1]=2; if(b==1) ta[1][2]=ta[1][0]=ta[0][0]=2; if(b==2) ta[1][2]=ta[1][0]=ta[0][2]=2; if(b==3) ta[1][0]=ta[0][1]=ta[0][2]=2;
if(b==4) ta[0][0]=ta[0][1]=ta[1][2]=2; if(b==5) ta[1][0]=ta[1][2]=ta[1][3]=2; add=1; if(b==6) ta[0][0]=ta[0][1]=ta[1][0]=2;
if(nextshape>0&&b!=6)
change(nextshape); for(i=0;i<=3;i++) for(j=0;j<=3;j++) nex[i][j]=turn[i][j]; if(nex[i][j]==2) Place(i+3,j*2+37); printf("■");
else for(i=0;i<=3;i++) for(j=0;j<=3;j++) nex[i][j]=ta[i][j]; if(nex[i][j]==2) Place(i+3,j*2+37); printf("■");
void clear()
int c=0,f=0,l[23],s=0,k;
for(i=3;i<=22;i++)
l[i]=0;
for(j=1;j<=15;j++) c=a[i][j]+c;
if(c==15)
for(j=1;j<=15;j++) a[i][j]=0;
for(k=i-1;k>=2;k--) for(j=1;j<=15;j++) a[k+1][j]=a[k][j];
f++; l[i]=1; s=5;
c=0;
score=score+f*10; while(f>1) score=score+f*5; f--; f=0;
while(s>0)
for(i=22;i>=3;i--) if(l[i]==1) Place(i-2,2); for(j=1;j<=15;j++) printf("■");Sleep(70);
for(i=22;i>=3;i--) if(l[i]==1) Place(i-2,2); for(j=1;j<=30;j++) printf(" ");Sleep(70);s--;
for(i=3;i<=22;i++) for(j=1;j<=15;j++) Place(i-2,2*j); printf(" "); appear();
void control()
int up,down,right,left,c=0,d=0,x,y,no=0,k,l=0,q=0; k=shape; add=0;
up=GetAsyncKeyState(VK_UP); down=GetAsyncKeyState(VK_DOWN); right=GetAsyncKeyState(VK_RIGHT); left=GetAsyncKeyState(VK_LEFT);
if(down!=0) tim=0;
if(left!=0||right!=0)
Sleep(100);disappear();
for(i=0;i<=22;i++) for(j=1;j<=15;j++)
if(a[i][j]==2&&a[i][j-1]!=1) c++; if(a[i][j]==2&&a[i][j+1]!=1) d++;
for(i=0;i<=22;i++) for(j=1;j<=15;j++) if(left!=0&&c==4&&a[i][j]==2) a[i][j-1]=a[i][j]; a[i][j]=0;
for(i=0;i<=22;i++) for(j=15;j>=1;j--) if(right!=0&&d==4&&a[i][j]==2) a[i][j+1]=a[i][j];a[i][j]=0; appear();
if(up!=0&&bn!=6)
Sleep(150); disappear();
for(i=0;i<=22;i++)
for(j=1;j<=15;j++) if(a[i][j]==2) x=i; no=1; break;
if(no==1) break;
no=0;
for(j=1;j<=15;j++)
for(i=0;i<=22;i++) if(a[i][j]==2) y=j; no=1; break;
if(no==1) break;
no=0;
if(k==1) y--; if(k==2) x--; add=0;
if(bn==5) add=1; if(k==0||k==2) x--; if(k==1||k==3) y--;
for(i=0;i<=3;i++) for(j=0;j<=3;j++) ta[i][j]=a[x+i][y+j];
if(bn>=0&&bn<5)
if(k==0) ta[2][0]=0; if(k==1) ta[0][0]=0; if(k==2) ta[0][2]=0; if(k==3) ta[2][2]=0;
if(bn==5)
if(k==0) ta[0][3]=ta[2][0]=ta[2][1]=ta[3][1]=ta[3][0]=0;
if(k==1) ta[0][0]=ta[1][0]=ta[0][1]=ta[1][1]=ta[3][3]=0;
if(k==2) ta[3][0]=ta[0][2]=ta[0][3]=ta[1][2]=ta[1][3]=0;
if(k==3) ta[0][0]=ta[2][2]=ta[2][3]=ta[3][2]=ta[3][3]=0;
for(i=0;i<=2+add;i++) for(j=0;j<=2+add;j++) if(ta[i][j]!=1) l++;
if(l==9+add*7)
change(1);
for(i=0;i<=22;i++) for(j=1;j<=15;j++) if(a[i][j]==2) a[i][j]=0;
for(i=0;i<=2+add;i++) for(j=0;j<=2+add;j++) if(turn[i][j]==2) a[x+i][y+j]=turn[i][j]; shape++;
if(shape>3) shape=0; appear();
int main()
int k,start,finish,d; printf("┌"); for(i=1;i<=15;i++) printf("┄"); printf("┐\n");
for(i=1;i<=20;i++) printf("┆\n"); printf("└");
for(i=1;i<=15;i++) printf("┄"); printf("┘"); for(i=1;i<=20;i++) Place(i,32); printf("┆\n");
Place(2,37); printf("NEXT"); Place(8,37); printf("SCORE"); Place(14,37); printf("BEST"); Place(11,37); printf("SPEED");
for(i=0;i<=2;i++) button(i);
while(ok==1) click();
while(ok!=1)
replace(); next();
while(1)
born();
next();
while(1)
appear();
k=0;
start=clock();
while(1)
finish=clock(); d=finish-start;
if(d>=tim) break;
control(); click(); if(ok==2) break;
if(ok==2) break; disappear();
for(i=22;i>=0;i--) for(j=1;j<=15;j++) if(a[i][j]==2&&a[i+1][j]!=1) k++;
if(k==4)
for(i=22;i>=0;i--) for(j=1;j<=15;j++) if(a[i][j]==2)
a[i+1][j]=2;a[i][j]=0;
else
for(i=22;i>=0;i--) for(j=1;j<=15;j++) if(a[i][j]==2) a[i][j]=1;
break;
tim=ti; appear();
if(ok==2) break;
appear();clear();ss();
for(i=1;i<=15;i++) if(a[2][i]==1) ok=1; break;
if(ok==2) ok=0; continue;
for(i=1;i<=20;i++) for(j=2;j<=30;j++) Place(i,j); printf(" ");
Place(9,12); printf("GAME OVER!");
while(ok==1) click();
return 0;
买彩票
#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <string>
#include <stack>
#include <ctime>
using namespace std;
int money=100;
int t=0;
int tt=-1;
int v;
int d;
void borrow()
if(tt!=-1)
cout<<"你现在不能借钱"<<endl;
return;
cout<<"你要借多少钱?"<<endl;
cin>>v;
if (d==1||d==2)
if (v>1000) cout<<"你不能借这么多钱!"<<endl,cout<<"你要借多少钱?"<<endl,cin>>v;
if (v<=1000) money+=v,cout<<"10天以后你要还"<<2*v<<"美元"<<endl;
return;
else
if (v>100) cout<<"你不能借这么多钱!"<<endl,cout<<"你要借多少钱?"<<endl,cin>>v;
if (v<=100) money+=v,cout<<"10天以后你要还"<<2*v<<"美元"<<endl;
return;
bool pay()
cout<<"你现在要还 "<<2*v<<endl;
money-=2*v;
tt=-1;
v=0;
if(money<=0) return false;
else return true;
int main(int argc, char *argv[])
cout<<"欢迎来到彩票游戏!"<<endl<<endl<<"温馨提示:在游戏内请勿使用小数、负数、英文字母、特殊字符(游戏中另说明除外),"<<endl<<"否则后果自负。"<<endl<<endl;
cout<<"请选择难度(输入序号即可):"<<endl<<"1:入门"<<" "<<"2:简单"<<" "<<"3:普通"<<" "<<"4:中等"<<" "<<"5:困难"<<endl;
cin>>d;
if (d==1) cout<<"已选择难度:入门"<<endl<<endl;
if (d==2) cout<<"已选择难度:简单"<<endl<<endl;
if (d==3) cout<<"已选择难度:普通"<<endl<<endl;
if (d==4) cout<<"已选择难度:中等"<<endl<<endl;
if (d==5) cout<<"已选择难度:困难"<<endl<<endl;
while(1)
if (d<1) cout<<"没有这个选项"<<endl<<"请选择难度(输入序号即可):"<<endl<<"1:入门"<<" "<<"2:简单"<<" "<<"3:普通"<<" "<<"4:中等"<<" "<<"5:困难"<<endl,cin>>d;
if (d>5) cout<<"没有这个选项"<<endl<<"请选择难度(输入序号即可):"<<endl<<"1:入门"<<" "<<"2:简单"<<" "<<"3:普通"<<" "<<"4:中等"<<" "<<"5:困难"<<endl,cin>>d;
if (d==1 || d==2 || d==3 || d==4 || d==5) break;
bool flag=true;
srand(time(0));
int a[10000];
int n,p;
char c[4];
if (d==1)
cout<<"每张彩票 购入价为1美元,出售价为5美元,有五个奖项"<<endl<<"小奖:10美元"<<endl<<"中奖:20美元"<<endl<<"大奖:100美元"<<endl<<"巨额奖金:1,000美元"<<endl<<"杰克壶:10,000美元"<<endl;
cout<<"你有100美元,当你赚了超过10,000美元,你就发财了。"<<endl<<"但如果你失去了所有的钱,你破产了。"<<endl;
cout<<"你可能想借钱(最多1,000美元),如果你想,按0。"<<endl<<"请记住,当你借了十天以后。你必须偿还两倍,"<<endl;
cout<<"你想买彩票还是卖彩票?(buy/sell)"<<endl;
if (d==2)
cout<<"每张彩票 购入价为2美元,出售价为3美元,有五个奖项"<<endl<<"小奖:5美元"<<endl<<"中奖:20美元"<<endl<<"大奖:100美元"<<endl<<"巨额奖金:1,000美元"<<endl<<"杰克壶:10,000美元"<<endl;
cout<<"你有100美元,当你赚了超过10,000美元,你就发财了。"<<endl<<"但如果你失去了所有的钱,你破产了。"<<endl;
cout<<"你可能想借钱(最多1,000美元),如果你想,请按0。"<<endl<<"请记住,当你借了十天以后。你必须偿还两倍,"<<endl;
cout<<"你想买彩票还是卖彩票?(buy/sell)"<<endl;
if (d==3)
cout<<"每张彩票 售价2美元,有五个奖项"<<endl<<"小奖:5美元"<<endl<<"中奖:20美元"<<endl<<"大奖:100美元"<<endl<<"巨额奖金:1,000美元"<<endl<<"杰克壶:10,000美元"<<endl;
cout<<"你有100美元,当你赚了超过10,000美元,你就发财了。"<<endl<<"但如果你失去了所有的钱,你破产了。"<<endl;
cout<<"你可能想借钱(最多100美元),如果你想,请按0。"<<endl<<"请记住,当你借了十天以后。你必须偿还两倍,"<<endl;
cout<<"你想买彩票还是卖彩票?(buy/sell)"<<endl;
if (d==4)
cout<<"每张彩票 售价3美元,有五个奖项"<<endl<<"小奖:5美元"<<endl<<"中奖:20美元"<<endl<<"大奖:100美元"<<endl<<"巨额奖金:1,000美元"<<endl<<"杰克壶:10,000美元"<<endl;
cout<<"你有100美元,当你赚了超过100,000美元,你就发财了。"<<endl<<"但如果你失去了所有的钱,你破产了。"<<endl;
cout<<"你可能想借钱(最多100美元),如果你想,请按0。"<<endl<<"请记住,当你借了七天以后。你必须偿还两倍,"<<endl;
cout<<"你想买彩票还是卖彩票?(buy/sell)"<<endl;
if (d==5)
cout<<"每张彩票 购入价为5美元,出售价为2美元,有五个奖项"<<endl<<"小奖:5美元"<<endl<<"中奖:20美元"<<endl<<"大奖:100美元"<<endl<<"巨额奖金:1,000美元"<<endl<<"杰克壶:5,000美元"<<endl;
cout<<"你有100美元,当你赚了超过100,000美元,你就发财了。"<<endl<<"但如果你失去了所有的钱,你就破产了。"<<endl;
cout<<"你可能想借钱(最多100美元),如果你想,请按0。"<<endl<<"请记住,当你借了五天以后。你必须偿还两倍,"<<endl;
cout<<"你想买彩票还是卖彩票?(buy/sell)"<<endl;
cin>>c;
if(c[0]=='b'||c[0]=='B')
while(money>0)
if (d==1||d==2||d==3) if(money>=10000)
cout<<"你发财了! "<<endl;
cout<<"你花了 "<<t<<"天"<<endl;
system("pause");
return 0;
if (d==4||d==5) if(money>=100000)
cout<<"你发财了! "<<endl;
cout<<"你花了 "<<t<<"天"<<endl;
system("pause");
return 0;
t++;
cout<<"你要买几张票?"<<" "<<"你有$"<<money<<endl;
cin>>n;
if(n==0)
if (d=4)
borrow();
tt=t+7;
if (d=5)
borrow();
tt=t+5;
else
borrow();
tt=t+10;
if(t==tt)
flag=pay();
if(t==tt-1) cout<<"[警告]你必须在明天还钱!"<<endl;
if(flag==false)
cout<<"你不能偿还你借的钱!"<<endl;
cout<<"你破产了。"<<endl;
cout<<"你生存了"<<t<<"天。"<<endl;
system("pause");
return 0;
flag=true;
if(n<0)
cout<<"因为你违反规则,所以系统强制停止了你的游戏"<<endl;
system("pause");
if (d==1) money=money-n;
if (d==2||d==3) money=money-n*2;
if (d==4) money=money-n*3;
if (d==5) money=money-n*5;
if(money<0)
cout<<"你破产了。"<<endl;
cout<<"你生存了"<<t<<"天"<<endl;
system("pause");
return 0;
for(int i=0; i<n; i++)
p=rand()%12000;
if(p==0)
int q=0;
q=rand()%4;
if(q==1)
cout<<"你获得了杰克壶!"<<endl;
if (d==5) money+=5000;
else money+=10000;
else if(p>=1&&p<=8)
int g=0;
g=rand()%2;
if(g==0)
cout<<"你获得了巨额奖金! "<<endl;
money+=1000;
else if(p>=9&&p<=99)
cout<<"你获得了大奖!"<<endl;
money+=100;
else if((p>=100&&p<=399)||(p>1500&&p<=1600))
cout<<"你获得了中间奖!"<<endl;
money+=20;
else if(p>=400&&p<=1500)
cout<<"你获得了小奖!"<<endl;
if (d==1) money+=10;
else money+=5;
if(money<=0)
cout<<"你破产了。"<<endl;
cout<<"你生存了"<<t<<"天。"<<endl;
system("pause");
return 0;
if(c[0]=='s'||c[0]=='S')
if (d==1)
cout<<"你有$"<<money<<endl;
cout<<"你必须付25美元买一个商店。 "<<endl;
cout<<"你只能卖同样数量的票作为你的钱。 "<<endl;
money-=25;
if (d==2)
cout<<"你有$"<<money<<endl;
cout<<"你必须付35美元买一个商店。 "<<endl;
cout<<"你只能卖同样数量的票作为你的钱。 "<<endl;
money-=35;
if (d==3||d==4)
cout<<"你有$"<<money<<endl;
cout<<"你必须付50美元买一个商店。 "<<endl;
cout<<"你只能卖同样数量的票作为你的钱。 "<<endl;
money-=50;
if (d==5)
cout<<"你有$"<<money<<endl;
cout<<"你必须付60美元买一个商店。 "<<endl;
cout<<"你只能卖同样数量的票作为你的钱。 "<<endl;
money-=60;
cout<<"你有$"<<money<<endl;
while(money>0)
if (d==1||d==2||d==3) if(money>=10000)
if (d==4||d==5) if(money>=100000)
cout<<"你发财了!"<<endl;
cout<<"你花了"<<t<<"天。"<<endl;
system("pause");
return 0;
t++;
cout<<"你要卖几张票? "<<" "<<"你有$"<<money<<endl;
cin>>n;
if(n==0)
borrow();
tt=t+10;
if(t==tt) bool flag=pay();
if(flag==false)
cout<<"你不能偿还你借的钱。"<<endl;
cout<<"你破产了!"<<endl;
cout<<"你生存了"<<t<<" 天。"<<endl;
system("pause");
return 0;
if(n<0 || n>money)
cout<<"注意"<<endl;
cout<<"你破产了!"<<endl;
cout<<"你生存了"<<t<<" 天"<<endl;
system("pause");
return 0;
if (d=1) money=money+n*5;
if (d=2) money=money+n*3;
else money=money+n*2;
if(money<0)
cout<<"你破产了!"<<endl;
cout<<"你生存了"<<t<<" 天"<<endl;
system("pause");
return 0;
for(int i=0; i<n; i++)
p=rand()%12000;
if(p==0)
int y;
y=rand()%4;
if(y==1)
cout<<"你失去了杰克壶!"<<endl;
if (d==5) money-=5000;
else money-=10000;
else if(p>=1&&p<=8)
cout<<"你失去了巨额奖金!"<<endl;
money-=1000;
else if(p>=15&&p<=50)
cout<<"你失去了大奖!"<<endl;
money-=100;
else if(p>=61&&p<=360)
cout<<"你失去了中奖!"<<endl;
money-=20;
else if(p>=401&&p<=1500)
cout<<"你失去了小奖!"<<endl;
money-=5;
if(money<=0)
cout<<"你破产了。"<<endl;
cout<<"你生存了"<<t<<"天。"<<endl;
system("pause");
return 0;
三国杀
#include<iostream>
#include<time.h>
#include<stdio.h>
#include <stdlib.h>
using namespace std;
struct pai
int paifu;
int huase;
int yanse;
int dianshu;
int leixing;
int changdu;
void Kanpai()
if(paifu==0||paifu==1);
else
printf("牌副参数错误!\n");
switch(huase)
case 0:cout<<"黑桃";break;
case 1:cout<<"红桃";break;
case 2:cout<<"草花";break;
case 3:cout<<"方片";break;
case -1:cout<<"无色";break;
default:printf("花色错误!\n");break;
switch(dianshu)
case 0:cout<<"A ";break;
case 1:cout<<"2 ";break;
case 2:cout<<"3 ";break;
case 3:cout<<"4 ";break;
case 4:cout<<"5 ";break;
case 5:cout<<"6 ";break;
case 6:cout<<"7 ";break;
case 7:cout<<"8 ";break;
case 8:cout<<"9 ";break;
case 9:cout<<"10 ";break;
case 10:cout<<"J ";break;
case 11:cout<<"Q ";break;
case 12:cout<<"K ";break;
case -1:cout<<"无点数";break;
default:printf("点数错误!\n");break;
switch(leixing)
case 101:cout<<"【杀】"<<endl;break;
case 102:cout<<"【闪】"<<endl;break;
case 103:cout<<"【桃】"<<endl;break;
case 201:cout<<"【过河拆桥】"<<endl;break;
case 202:cout<<"【顺手牵羊】"<<endl;break;
case 203:cout<<"【无中生有】"<<endl;break;
case 204:cout<<"【决斗】"<<endl;break;
case 205:cout<<"【借刀杀人】"<<endl;break;
case 206:cout<<"【桃园结义】"<<endl;break;
case 207:cout<<"【五谷丰登】"<<endl;break;
case 208:cout<<"【南蛮入侵】"<<endl;break;
case 209:cout<<"【万箭齐发】"<<endl;break;
case 210:cout<<"【无懈可击】"<<endl;break;
case 251:cout<<"【乐不思蜀】"<<endl;break;
case 252:cout<<"【闪电】"<<endl;break;
case 301:cout<<"【诸葛连弩(1)】"<<endl;break;
case 302:cout<<"【雌雄双股剑(2)】"<<endl;break;
case 303:cout<<"【青釭剑(2)】"<<endl;break;
case 304:cout<<"【青龙偃月刀(3)】"<<endl;break;
case 305:cout<<"【丈八蛇矛(3)】"<<endl;break;
case 306:cout<<"【贯石斧(3)】"<<endl;break;
case 307:cout<<"【方天画戟(4)】"<<endl;break;
case 308:cout<<"【麒麟弓(5)】"<<endl;break;
case 331:cout<<"【八卦阵】"<<endl;break;
case 361:cout<<"【赤兔(-1)】"<<endl;break;
case 362:cout<<"【大宛(-1)】"<<endl;break;
case 363:cout<<"【紫辛(-1)】"<<endl;break;
case 381:cout<<"【爪黄飞电(+1)】"<<endl;break;
case 382:cout<<"【的卢(+1)】"<<endl;break;
case 383:cout<<"【绝影(+1)】"<<endl;break;
default:printf("类型参数错误!");break;
;
void Qishixipai(pai A[2][4][13],pai paidui[104])
int i,m,x,y,z,a[104]=0;
srand((unsigned)time(NULL));
for(i=1;i<=104;i++)
while(a[m=rand()%104]);
a[m]=i;
for(i=0;i<=103;i++)
x=(a[i]-1)/52;
y=((a[i]-1)-52*x)/13;
z=(a[i]-1)%13;
paidui[i]=A[x][y][z];
void Xipai(pai paidui[104],int*paiduishu,pai qipaidui[104],int*qipaishu)
int i,m,a[104]=0;
srand((unsigned)time(NULL));
for(i=1;i<=(*qipaishu);i++)
while(a[m=rand()%(*qipaishu)]);
a[m]=i;
for(i=0;i<=((*qipaishu)-1);i++)
paidui[i]=qipaidui[a[i]];
qipaidui[a[i]].leixing=-1;
(*paiduishu)++;
(*qipaishu)--;
for(i=(*paiduishu);i<=103;i++)paidui[i].leixing=-1;
pai Mo1pai(pai A[104],int *x,pai B[104],int*y,int *b)
pai p;
if((*x)==0)Xipai(A,x,B,y);
else if((*x)<0)printf("摸牌参数错误!");
else;
p=A[104-(*x)];
(*x)--;
(*b)++;
return(p);
struct wujiang
char name;
int tili;
int tilishangxian;
int shoupaishangxian;
int huihekaishi;
int panding;
int mopai;
int chupai;
int qipai;
int huihejieshu;
int juese;
pai shoupai[20];
int shoupaishu;
pai zhuangbei[4];
int zhuangbeishu;
pai pandingpai[3];
int pandingshu;
int juli[1];
void Kanshoupai()
printf("玩家当前手牌:\n");
if(shoupaishu)
int m;
for(m=0;m<=(shoupaishu-1);m++)
printf("%d ",m);
(shoupai[m]).Kanpai();
else printf("空城!\n");
printf("\n");
void Kanzhuangbei()
if(juese)printf("玩家");
else printf("电脑");
printf("当前装备:\n");
printf("0 武器: ");
if((zhuangbei[0]).leixing==-1)printf("空\n");
else (zhuangbei[0]).Kanpai();
printf("1 防具: ");
if((zhuangbei[1]).leixing==-1)printf("空\n");
else (zhuangbei[1]).Kanpai();
printf("2 进攻马: ");
if((zhuangbei[2]).leixing==-1)printf("空\n");
else (zhuangbei[2]).Kanpai();
printf("3 防御马: ");
if((zhuangbei[3]).leixing==-1)printf("空\n");
else (zhuangbei[3]).Kanpai();
printf("\n");
void Kanpandingpai()
if(juese)printf("玩家");
else printf("电脑");
printf("当前判定区:\n");
if((pandingpai[0]).leixing==-1)printf("空\n");
else
printf("0 ");
(pandingpai[0]).Kanpai();
if((pandingpai[1]).leixing==-1);
else
printf("1 ");
(pandingpai[1]).Kanpai();
if((pandingpai[2]).leixing==-1);
else
printf("2 ");
(pandingpai[2]).Kanpai();
;
void Mopai(int*shoupaishu,pai shoupai[20],pai A[104],int *x,pai B[104],int*y,int juese)
if(juese)printf("玩家从牌堆摸2张牌\n");
else printf("电脑从牌堆摸2张牌\n");
pai p;
p=Mo1pai(A,x,B,y,shoupaishu);
shoupai[*shoupaishu-1]=p;
pai q;
q=Mo1pai(A,x,B,y,shoupaishu);
shoupai[*shoupaishu-1]=q;
int m;
if(juese)
printf("玩家当前手牌:\n");
for(m=0;m<=(*shoupaishu-1);m++)
printf("%d ",m);
(shoupai[m]).Kanpai();
printf("牌堆还剩%d张牌!\n\n",*x);
void Qishishoupai(wujiang *w,pai A[104],int *x,pai B[104],int*y)
pai a;
a=Mo1pai(A,x,B,y,&((*w).shoupaishu));
(*w).shoupai[(*w).shoupaishu-1]=a;
pai b;
b=Mo1pai(A,x,B,y,&((*w).shoupaishu));
(*w).shoupai[(*w).shoupaishu-1]=b;
pai c;
c=Mo1pai(A,x,B,y,&((*w).shoupaishu));
(*w).shoupai[(*w).shoupaishu-1]=c;
pai d;
d=Mo1pai(A,x,B,y,&((*w).shoupaishu));
(*w).shoupai[(*w).shoupaishu-1]=d;
int m;
if((*w).juese)printf("玩家从牌堆摸4张牌\n");
else printf("电脑从牌堆摸4张牌\n");
if((*w).juese)
printf("玩家当前手牌:\n");
for(m=0;m<=((*w).shoupaishu-1);m++)
printf("%d ",m);
((*w).shoupai[m]).Kanpai();
printf("牌堆还剩%d张牌!\n\n",*x);
void Panding(pai paidui[104],int*paiduishu,pai qipaidui[104],int*qipaishu)
paidui[*paiduishu].Kanpai();
qipaidui[*qipaishu]=paidui[*paiduishu];
(*paiduishu)--;
(*qipaishu)++;
pai Zhangba(wujiang*w,pai qipaidui[104],int*qipaishu)
int x,y;
pai p;
for(;;)
int i,j;
printf("请输入任意两张手牌之前的编号,以空格隔开,以回车结束!\n");
scanf("%d",&x);
scanf("%d",&y);
if((x>=0)&&(x<(*w).shoupaishu)&&(y>=0)&&(y<(*w).shoupaishu-1))
switch((((*w).shoupai[x].huase)%2)+(((*w).shoupai[y].huase)%2))
case 0:p.yanse=0;break;
case 2:p.yanse=1;break;
case 1:p.yanse=2;break;
default:printf("【丈八蛇矛】函数参数错误!\n");
qipaidui[*qipaishu]=(*w).shoupai[x];
(*w).shoupai[x].leixing=-1;
((*w).shoupaishu)--;
(*qipaishu)++;
qipaidui[*qipaishu]=(*w).shoupai[y];
(*w).shoupai[y].leixing=-1;
((*w).shoupaishu)--;
(*qipaishu)++; printf("弃牌数:%d",*qipaishu);
for(i=0;i<=(((*w).shoupaishu)+1);i++)
if((*w).shoupai[i].leixing==-1)
for(j=i+1;j<=(((*w).shoupaishu)+2);j++)
(*w).shoupai[j-1]=(*w).shoupai[j];
i--;
printf("玩家把:\n");
qipaidui[(*qipaishu)-2].Kanpai();
qipaidui[(*qipaishu)-1].Kanpai();
printf("当作一张");
switch(p.yanse)
case 0:printf("黑色");break;
case 2:printf("红色");break;
case 1:printf("无色");break;
default:printf("绿色");break;
printf("无点数的【杀】");
p.dianshu=-1;
p.leixing=101;
return p;
break;
printf("你将两张空气当作一张空气属性的【杀】使用或打出!\n");
int Xuanpai(wujiang*w,int t)
int x;
if((*w).juese)
for(;;)
printf("出牌请输入手牌之前的编号,以回车结束!\n如果你想结束出牌阶段,请输入“-1”,以回车结束!\n");
scanf("%d",&x);
if((x>=-1&&x<((*w).shoupaishu))||((x==100)&&((*w).zhuangbei[0].leixing==305)))
return x;
break;
printf("你打出了一张空气!\n");
else return t;
pai Panpai(wujiang*w1,int*sha,int y,pai qipaidui[104],int*qipaishu)
pai p,q;
p.leixing=0;
q.leixing=-1;
if(y==-1)return q;
else
if(y==100)
if((*sha)>0)
q=Zhangba(w1,qipaidui,qipaishu);
printf("使用!\n");
return q;
else
printf("当前回合使用【杀】的次数已用尽,你也不能使用【丈八蛇矛】效果!\n");
return p;
switch((*w1).shoupai[y].leixing)
case 101:
if(((*sha)>0)||((*w1).zhuangbei[0].leixing==301))
if(((*w1).zhuangbei[0].leixing==301))printf("武器【诸葛连弩】效果被触发!\n");
return (*w1).shoupai[y];
break;
else
if((*w1).juese)printf("当前回合使用【杀】的次数已用尽,你不能使用【杀】!\n");
return p;break;
case 102:
if((*w1).juese)
printf("当前不需要响应任何操作,你不能主动打出【闪】!\n");
return p;break;
case 103:
if(((*w1).tili)<((*w1).tilishangxian))
return (*w1).shoupai[y];
break;
else
if((*w1).juese)
printf("你并未受伤,不能对自己使用【桃】!\n");
return p;break;
case 210:
if((*w1).juese)
printf("当前不需要响应任何锦囊,你不能主动打出【无懈可击】!\n");
return p;break;
case 201:
case 202:
case 203:
case 204:
case 205:
case 206:
case 207:
case 208:
case 209:
case 251:
case 252:
case 301:
case 302:
case 303:
case 304:
case 305:
case 306:
case 307:
case 308:
case 331:
case 361:
case 362:
case 363:
case 381:
case 382:
case 383:return (*w1).shoupai[y];break;
default:printf("手牌类型参数错误!\n");return p;break;
int Mubiao(pai p,wujiang *w1,wujiang *w2,int*sha)
int x;
switch(p.leixing)
case 101:
if((*w1).juese)
printf("请选择【杀】的目标!\n输入目标前的编号,以回车结束!\n0 电脑1\n");
scanf("%d",&x);
if(x==0)
if((*w1).zhuangbei[0].changdu>=(*w1).juli[0])
(*sha)--;
return((*w2).juese);
else
printf("武器长度不够!\n");
return -2;
else
printf("目标错误!\n");
return -2;
else
if((*w1).zhuangbei[0].changdu>=(*w1).juli[0])
(*sha)--;
return((*w2).juese);
else return -2;
break;
case 103:return((*w1).juese);break;
case 201:
if((*w1).juese)
printf("请选择【过河拆桥】的目标!\n输入目标前的编号,以回车结束!\n0 电脑1\n");
scanf("%d",&x);
if(x==0)
if((*w2).shoupaishu||(*w2).zhuangbeishu||(*w2).pandingshu)return((*w2).juese);
else
printf("目标没有牌!\n");
return -2;
else
printf("目标错误!\n");
return -2;
else return((*w2).juese);
break;
case 202:
if((*w1).juese)
printf("请选择【顺手牵羊】的目标!\n输入目标前的编号,以回车结束!\n0 电脑1\n");
scanf("%d",&x);
if(x==0)
if(((*w2).shoupaishu||(*w2).zhuangbeishu||(*w2).pandingshu)&&((*w1).juli[0]<=1))return((*w2).juese);
else
printf("目标没有牌!\n");
return -2;
else
printf("目标错误!\n");
return -2;
else
if((*w1).juli[0]<=1)return((*w2).juese);
else return -2;
break;
case 203:
return((*w1).juese);break;
case 204:
if((*w1).juese)
printf("请选择【决斗】的目标!\n输入目标前的编号,以回车结束!\n0 电脑1\n");
scanf("%d",&x);
if(x==0)return((*w2).juese);
else
printf("目标错误!\n");
return -2;
else return((*w2).juese);
break;
case 205:
int y;
if((*w1).juese)
printf("请选择【借刀杀人】的目标!\n输入目标前的编号,以回车结束!\n0 电脑1\n");
scanf("%d",&x);
if(x!=0)
printf("目标错误!\n");
return -2;
else
if(((*w2).zhuangbei[0]).leixing<=300||((*w2).zhuangbei[0]).leixing>=331)
printf("目标装备区里没有武器!\n");
return -2;
else
printf("请选择【杀】的目标!\n提示:【杀】的目标必须在【借刀杀人】的目标的攻击范围之内!\n输入目标前的编号,以回车结束!\n0 玩家\n");
scanf("%d",&y);
if(y!=0)
printf("目标错误!\n");
return -2;
else
if(((*w2).zhuangbei[0].changdu)<(*w2).juli[0])
printf("武器距离不够!\n");
return -2;
else
return((*w2).juese);
else
if(((*w2).zhuangbei[0]).leixing<=300||((*w2).zhuangbei[0]).leixing>=331)return -2;
else
if(((*w2).zhuangbei[0].changdu)<(*w2).juli[0])return -2;
else return((*w2).juese);
break;
case 206:
case 207:return 99;break;
case 208:
case 209:return 100;break;
case 251:
if((*w1).juese)
printf("请选择【乐不思蜀】的目标!\n输入目标前的编号,以回车结束!\n0 电脑1\n");
scanf("%d",&x);
if(x==0)
int i;
for(i=0;i<=2;i++)
if((*w2).pandingpai[i].leixing==251)
i=-1;
break;
if(i==-1)
printf("目标判定区里不能同时存在两张相同的延时类锦囊!\n");
return -2;
else return((*w2).juese);
else
printf("目标错误!\n");
return -2;
else
int i;
for(i=0;i<=2;i++)
if((*w2).pandingpai[i].leixing==251)
i=-1;
break;
if(i==-1)return -2;
else return((*w2).juese);
break;
case 252:
int i;
for(i=0;i<=2;i++)
if((*w1).pandingpai[i].leixing==252)
i=-1;
break;
if(i==-1)
if((*w1).juese)printf("目标判定区里不能同时存在两张相同的延时类锦囊!\n");
return -2;
else return ((*w1).juese);
break;
case 301:
case 302:
case 303:
case 304:
case 305:
case 306:
case 307:
case 308:
case 331:
case 361:
case 362:
case 363:
case 381:
case 382:
case 383:return((*w1).juese);break;
default:return -2;break;
void Da1pai(wujiang *w1,wujiang*w2,pai qipaidui[104],int *qipaishu,int x)
int i;
if((x<0||x>=((*w1).shoupaishu))&&x!=100)
printf("你的牌呢?!\n");
else
switch(((*w1).shoupai)[x].leixing)
case 101:
case 102:
case 103:
case 201:
case 202:
case 203:
case 204:
case 205:
case 206:
case 207:
case 208:
case 209:
case 210:
qipaidui[*qipaishu]=((*w1).shoupai)[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
break;
case 251:
for(i=1;i>=0;i--)(*w2).pandingpai[i+1]=(*w2).pandingpai[i];
(*w2).pandingpai[0]=(*w1).shoupai[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
((*w2).pandingshu)++;
break;
case 252:
for(i=1;i>=0;i--)(*w1).pandingpai[i+1]=(*w1).pandingpai[i];
(*w1).pandingpai[0]=(*w1).shoupai[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
((*w1).pandingshu)++;
break;
case 301:
case 302:
case 303:
case 304:
case 305:
case 306:
case 307:
case 308:
if((*w1).zhuangbei[0].leixing==-1)((*w1).zhuangbeishu)++;
else
qipaidui[*qipaishu]=((*w1).zhuangbei)[0];
(*qipaishu)++;
(*w1).zhuangbei[0]=(*w1).shoupai[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
break;
case 331:
if((*w1).zhuangbei[1].leixing==-1)((*w1).zhuangbeishu)++;
else
qipaidui[*qipaishu]=((*w1).zhuangbei)[1];
(*qipaishu)++;
(*w1).zhuangbei[1]=(*w1).shoupai[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
break;
case 361:
case 362:
case 363:
if((*w1).zhuangbei[2].leixing==-1)((*w1).zhuangbeishu)++;
else
qipaidui[*qipaishu]=((*w1).zhuangbei)[2];
(*qipaishu)++;
(*w1).zhuangbei[2]=(*w1).shoupai[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
break;
case 381:
case 382:
case 383:
if((*w1).zhuangbei[3].leixing==-1)((*w1).zhuangbeishu)++;
else
qipaidui[*qipaishu]=((*w1).zhuangbei)[3];
(*qipaishu)++;
(*w1).zhuangbei[3]=(*w1).shoupai[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
break;
default:break;
void Miaoshu(pai p,int juese,int duixiang)
if(juese==0)printf("电脑");
else if(juese==1)printf("玩家");
else printf("角色参数错误!\n");
if(p.leixing<=300&&p.leixing>100)
switch(duixiang)
case -1:printf("打出");break;
case 0:printf("对电脑使用");break;
case 1:printf("对玩家使用");break;
case 99:printf("使用");break;
case 100:printf("对所有人使用");break;
default:printf("对象参数错误\n");break;
else if(p.leixing>=301&&p.leixing<=400)
printf("装备");
else printf("你出的是什么东西?\n");
p.Kanpai();
if(!juese&&(p.leixing==101||p.leixing==204||p.leixing==205||p.leixing==207||p.leixing==208||p.leixing==209))printf("请响应!\n");
int Wuxie(pai *p,wujiang*w1,wujiang*w2,pai qipaidui[104],int*qipaishu,int a)
int x;
if((*w1).juese)
printf("是否使用【无懈可击】响应?\n\n");
for(;;)
(*w1).Kanshoupai();
printf("如果要使用【无懈可击】请输入手牌之前编号,不需要请输入“-1”,以回车结束!\n");
scanf("%d",&x);
if(x==-1)
for(x=0;x<((*w2).shoupaishu);x++)
if((*w2).shoupai[x].leixing==210)
printf("电脑使用");
((*w2).shoupai)[x].Kanpai();
printf("对象是");
(*p).Kanpai();
(*p)=((*w2).shoupai)[x];
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(int i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
a++;
break;
break;
else if((*w1).shoupai[x].leixing==210)
printf("玩家使用");
((*w1).shoupai)[x].Kanpai();
printf("对象是");
(*p).Kanpai();
(*p)=((*w1).shoupai)[x];
qipaidui[*qipaishu]=((*w1).shoupai)[x];
for(int i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
(*w1).Kanshoupai();
a++;
break;
else printf("你确定你使用的是【无懈可击】?\n");
else
printf("是否使用【无懈可击】响应?\n");
for(;;)
(*w2).Kanshoupai();
printf("如果要使用【无懈可击】请输入手牌之前编号,不需要请输入“-1”,以回车结束!\n");
scanf("%d",&x);
if(x==-1)break;
else if((*w2).shoupai[x].leixing==210)
printf("玩家使用");
((*w2).shoupai)[x].Kanpai();
printf("对象是");
(*p).Kanpai();
(*p)=((*w2).shoupai)[x];
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(int i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
(*w2).Kanshoupai();
a++;
break;
else printf("你确定你使用的是【无懈可击】?\n");
return a;
int Qiutao(wujiang*w,pai qipaidui[104],int*qipaishu)
int x;
if((*w).juese)
for(;;)
printf("如果要使用【桃】请输入手牌之前的编号,不需要请输入“-1”,以回车结束!\n");
scanf("%d",&x);
if(x==-1)
return -1;
break;
else if((*w).shoupai[x].leixing==103)
qipaidui[*qipaishu]=((*w).shoupai)[x];
for(int i=x+1;i<=((*w).shoupaishu);i++)((*w).shoupai)[i-1]=((*w).shoupai)[i];
((*w).shoupaishu)--;
(*qipaishu)++;
return 0;
break;
else printf("你确定你使用的是【桃】?\n");
else
for(x=0;x<((*w).shoupaishu);x++)
if((*w).shoupai[x].leixing==103)
qipaidui[*qipaishu]=((*w).shoupai)[x];
for(int i=x+1;i<=((*w).shoupaishu);i++)((*w).shoupai)[i-1]=((*w).shoupai)[i];
((*w).shoupaishu)--;
(*qipaishu)++;
return 0;
break;
return -1;
int Binsi(wujiang*w1,wujiang*w2,pai qipaidui[104],int*qipaishu)
if(((*w2).tili)>0)return 0;
else
int i;
if((*w1).juese)
for(;;)
printf("电脑濒死,是否使用【桃】?\n");
i=Qiutao(w1,qipaidui,qipaishu);
if(i==0)((*w2).tili)++;
if((i==-1)||((*w2).tili>0))break;
if((*w2).tili>0)return 0;
else
for(;;)
i=Qiutao(w2,qipaidui,qipaishu);
if(i==0)((*w2).tili)++;
if((i==-1)||((*w2).tili>0))break;
if((*w2).tili>0)return 0;
else return -1;
else
for(;;)
printf("玩家濒死,是否使用【桃】?\n");
i=Qiutao(w2,qipaidui,qipaishu);
if(i==0)((*w2).tili)++;
if((i==-1)||((*w2).tili>0))break;
if((*w2).tili>0)return 0;
else return -1;
int Shan(wujiang*w1,wujiang*w2,pai paidui[104],int*paiduishu,pai qipaidui[104],int*qipaishu)
int x;
if((*w2).juese)
if(((*w2).zhuangbei[1].leixing==331)&&((*w1).zhuangbei[0].leixing!=303))
for(;;)
int m;
printf("是否发动【八卦阵】防具效果?\n0 否\n1 是\n请输入选项之前的编号,以回车结束!\n");
scanf("%d",&m);
if(m==1)
Panding(paidui,paiduishu,qipaidui,qipaishu);
if(qipaidui[(*qipaishu)-1].huase%2)
printf("【八卦阵】判定成功!\n");
return 0;
else if(m==0)
printf("【八卦阵】判定失败!\n");
break;
else printf("你确定你输入的是“0”或“1”?\n");
else if(((*w2).zhuangbei[1].leixing==331)&&((*w1).zhuangbei[0].leixing==303))printf("【青釭剑】锁定技被触发!\n");
for(;;)
printf("请输入手牌之前的编号,或者输入“-1”放弃打出【闪】,以回车结束!\n");
scanf("%d",&x);
if(x==-1)
return -1;
break;
else if((*w2).shoupai[x].leixing==102)
printf("玩家打出");
((*w2).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(int i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
return 0;
break;
else printf("你确定你打出的是【闪】?\n");
else
if(((*w2).zhuangbei[1].leixing==331)&&((*w1).zhuangbei[0].leixing!=303))
Panding(paidui,paiduishu,qipaidui,qipaishu);
if(qipaidui[(*qipaishu)-1].huase%2)
printf("【八卦阵】判定成功!\n");
return 0;
else printf("【八卦阵】判定失败!\n");
else if(((*w2).zhuangbei[1].leixing==331)&&((*w1).zhuangbei[0].leixing==303))printf("【青釭剑】锁定技被触发!\n");
int i;
for(x=0;x<((*w2).shoupaishu);x++)
if((*w2).shoupai[x].leixing==102)
printf("电脑打出");
((*w2).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
return 0;
break;
return -1;
int Sha(wujiang *w1,wujiang*w2,pai paidui[104],int*paiduishu,pai qipaidui[104],int*qipaishu)
int x;
if((*w2).juese)
printf("请打出【闪】响应【杀】!否则你将受到1点伤害!\n");
x=Shan(w1,w2,paidui,paiduishu,qipaidui,qipaishu);
if(x==-1)
int i;
((*w2).tili)--;
printf("电脑对玩家造成1点伤害!\n");
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
else if(x==0&&((*w1).zhuangbei[0].leixing==306))
int i;
if(((*w1).shoupaishu)>=2)
printf("电脑弃掉:\n");
((*w1).shoupai)[0].Kanpai();
qipaidui[*qipaishu]=((*w1).shoupai)[0];
for(i=1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
((*w1).shoupai)[0].Kanpai();
qipaidui[*qipaishu]=((*w1).shoupai)[0];
for(i=1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
printf("发动【贯石斧】武器效果使【杀】造成伤害!\n");
((*w2).tili)--;
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
else return 0;
else if(x==0&&((*w1).zhuangbei[0].leixing==304))
int i;
for(x=0;x<((*w1).shoupaishu);x++)
if((*w1).shoupai[x].leixing==101)
printf("电脑发动【青龙偃月刀】效果对玩家使用");
((*w1).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w1).shoupai)[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
i=Sha(w1,w2,paidui,paiduishu,qipaidui,qipaishu);
return i;
break;
return 0;
else
x=Shan(w1,w2,paidui,paiduishu,qipaidui,qipaishu);
if(x==-1)
if((*w1).zhuangbei[0].leixing==308)
for(;;)
printf("是否发动【麒麟弓】武器效果?\n0 否\n1 是\n");
scanf("%d",&x);
if(x==1)
if(((*w2).zhuangbei[2].leixing==-1)&&((*w2).zhuangbei[3].leixing==-1))
printf("电脑根本没有马,射你妹的马啊!\n");
break;
else
for(;;)
printf("0 ");
((*w2).zhuangbei[2]).Kanpai();
printf("1 ");
((*w2).zhuangbei[3]).Kanpai();
printf("请选择要弃掉的马,输入之前的编号,以回车结束!\n");
scanf("%d",&x);
if((x==0)&&((*w2).zhuangbei[2].leixing!=-1))
printf("你弃掉了电脑的");
((*w2).zhuangbei)[2].Kanpai();
qipaidui[*qipaishu]=((*w2).zhuangbei)[2];
((*w2).zhuangbeishu)--;
(*qipaishu)++;
((*w2).zhuangbei)[2].leixing=-1;
((*w2).juli[0])++;
break;
else if((x==1)&&((*w2).zhuangbei[3].leixing!=-1))
printf("你弃掉了电脑的");
((*w2).zhuangbei)[3].Kanpai();
qipaidui[*qipaishu]=((*w2).zhuangbei)[3];
((*w2).zhuangbeishu)--;
(*qipaishu)++;
((*w2).zhuangbei)[3].leixing=-1;
((*w1).juli[0])--;
break;
else printf("射你妹的马!");
break;
else if(x==0)break;
else printf("键盘上的“0”和“1”被你吃了吗?\n");
int i;
((*w2).tili)--;
printf("玩家对电脑造成1点伤害!\n");
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
else if(x==0&&((*w1).zhuangbei[0].leixing==306))
for(;;)
printf("是否发动【贯石斧】武器效果?\n0 否\n1 是\n");
scanf("%d",&x);
if(x==1)
int i;
if((*w1).shoupaishu+(*w1).zhuangbeishu<=2)
printf("你除了【贯石斧】以外连2张牌都没有,发动你妹的效果!\n");
break;
else
printf("请分别弃掉两张牌!\n");
for(i=0;i<=2;i++)
for(;;)
printf("请选择区域:\n0 手牌\n1 装备\n");
scanf("%d",&x);
if(x==0&&((*w1).shoupaishu==0))printf("你根本没有手牌,弃你妹啊!\n");
else if(x==1&&((*w1).zhuangbeishu==1))printf("你根本没有别的装备,弃你妹啊!\n");
else if(x>=0&&x<=1)break;
else printf("键盘上的“0”和“1”被你吃了吗?\n");
if(x==0)
for(;;)
(*w1).Kanshoupai();
printf("弃牌请输入手牌之前的编号,以回车结束!\n");
scanf("%d",&x);
if(x>=0&&x<((*w1).shoupaishu))break;
else printf("弃你妹的手牌!\n");
printf("你弃掉了");
((*w1).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w1).shoupai)[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
else
for(;;)
(*w1).Kanzhuangbei();
printf("请输入装备之前的编号,以回车键结束!\n");
scanf("%d",&x);
if((((*w1).zhuangbei[x]).leixing!=-1)&&(x>=0)&&(x<=3))
printf("你弃掉了");
((*w1).zhuangbei)[x].Kanpai();
qipaidui[*qipaishu]=((*w1).zhuangbei)[x];
((*w1).zhuangbeishu)--;
(*qipaishu)++;
((*w1).zhuangbei)[x].leixing=-1;
break;
else printf("弃你妹的装备!\n");
printf("玩家发动【贯石斧】武器效果使【杀】造成伤害!\n");
((*w2).tili)--;
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
break;
else if(x==0)break;
else printf("键盘上的“0”和“1”被你吃了吗?\n");
else if(x==0&&((*w1).zhuangbei[0].leixing==304))
for(;;)
printf("是否发动【青龙偃月刀】武器效果?\n0 否\n1 是\n");
scanf("%d",&x);
if(x==1)
for(;;)
printf("请对电脑使用一张【杀】!\n请输入手牌之前的编号,或者输入“-1”放弃出【杀】,以回车结束!\n");
(*w1).Kanshoupai();
scanf("%d",&x);
if(x==-1)
return 0;
break;
else if((*w1).shoupai[x].leixing==101)
int i;
printf("玩家对电脑使用");
((*w1).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w1).shoupai)[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
i=Sha(w1,w2,paidui,paiduishu,qipaidui,qipaishu);
return i;
break;
else printf("你确定你打出的是【杀】?\n");
else if(x==0)
return 0;
break;
else printf("你确定你输入的是“0”或“1”?\n");
else return 0;
return 0;
void Tao(wujiang*w1)
((*w1).tili)++;
if((*w1).juese)printf("玩家");
else printf("电脑");
printf("恢复了1点体力!\n");
if(((*w1).tili)>((*w1).tilishangxian))printf("你被撑死了!\n");
void Chai(wujiang*w1,wujiang*w2,pai qipaidui[104],int*qipaishu)
int i,x,y;
if((*w1).juese)
for(;;)
if((*w2).shoupaishu+(*w2).zhuangbeishu+(*w2).pandingshu==0)
printf("对方空城,拆你妹啊!\n");
break;
else
printf("请选择想拆的区域,输入选项之前的编号,以回车结束!\n0 手牌\n1 装备区\n2 判定区\n");
scanf("%d",&x);
if(x==0&&((*w2).shoupaishu==0))printf("你拆掉了一张空气!\n");
else if(x==1&&((*w2).zhuangbeishu==0))printf("你拆掉了一张空气!\n");
else if(x==2&&((*w2).pandingshu==0))printf("你拆掉了一张空气!\n");
else if(x>=0&&x<=2)break;
else printf("你拆掉了太空区里的一张牌!\n");
switch(x)
case 0:
srand((unsigned)time(NULL));
y=rand()%((*w2).shoupaishu);
printf("你弃掉了电脑的");
((*w2).shoupai)[y].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[y];
for(i=y+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
break;
case 1:
for(;;)
(*w2).Kanzhuangbei();
printf("请输入装备之前的编号,以回车键结束!\n");
scanf("%d",&y);
if((((*w2).zhuangbei[y]).leixing!=-1)&&(y>=0)&&(y<=3))
printf("你弃掉了电脑的");
((*w2).zhuangbei)[y].Kanpai();
qipaidui[*qipaishu]=((*w2).zhuangbei)[y];
((*w2).zhuangbeishu)--;
(*qipaishu)++;
((*w2).zhuangbei)[y].leixing=-1;
if(!y)((*w2).zhuangbei)[y].changdu=1;
else if(y==2)((*w2).juli[0])++;
else if(y==3)((*w1).juli[0])--;
break;
else printf("你弃掉了一张空气!\n");
break;
case 2:
for(;;)
(*w2).Kanpandingpai();
printf("请输入判定牌之前的编号,以回车键结束!\n");
scanf("%d",&y);
if((*w2).pandingpai[y].leixing!=-1)
printf("你弃掉了电脑的");
((*w2).pandingpai)[y].Kanpai();
qipaidui[*qipaishu]=((*w2).pandingpai)[y];
((*w2).pandingshu)--;
(*qipaishu)++;
((*w2).pandingpai)[y].leixing=-1;
break;
else printf("你弃掉了一张空气!\n");
break;
default:break;
else
if((*w2).zhuangbeishu)
if((*w2).zhuangbei[1].leixing!=-1)
printf("电脑弃掉了玩家的");
((*w2).zhuangbei)[1].Kanpai();
qipaidui[*qipaishu]=((*w2).zhuangbei)[1];
((*w2).zhuangbeishu)--;
(*qipaishu)++;
((*w2).zhuangbei)[1].leixing=-1;
else if((*w2).zhuangbei[3].leixing!=-1)
printf("电脑弃掉了玩家的");
((*w2).zhuangbei)[3].Kanpai();
qipaidui[*qipaishu]=((*w2).zhuangbei)[3];
((*w2).zhuangbeishu)--;
(*qipaishu)++;
((*w2).zhuangbei)[3].leixing=-1;
((*w1).juli[0])--;
else if((*w2).zhuangbei[0].leixing!=-1)
printf("电脑弃掉了玩家的");
((*w2).zhuangbei)[0].Kanpai();
qipaidui[*qipaishu]=((*w2).zhuangbei)[0];
((*w2).zhuangbeishu)--;
(*qipaishu)++;
((*w2).zhuangbei)[0].leixing=-1;
((*w2).zhuangbei)[0].changdu=1;
else
printf("电脑弃掉了玩家的");
((*w2).zhuangbei)[2].Kanpai();
qipaidui[*qipaishu]=((*w2).zhuangbei)[2];
((*w2).zhuangbeishu)--;
(*qipaishu)++;
((*w2).zhuangbei)[2].leixing=-1;
((*w2).juli[0])++;
else
srand((unsigned)time(NULL));
y=rand()%((*w2).shoupaishu);
printf("电脑弃掉了玩家的手牌");
((*w2).shoupai)[y].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[y];
for(i=y+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
void Qian(wujiang *w1,wujiang *w2)
int i,x,y;
if((*w1).juese)
for(;;)
if((*w2).shoupaishu+(*w2).zhuangbeishu+(*w2).pandingshu==0)
printf("对方空城啦!你牵走了一张寂寞!\n");
break;
else
printf("请选择想牵的区域,输入选项之前的编号,以回车结束!\n0 手牌\n1 装备区\n2 判定区\n");
scanf("%d",&x);
if(x==0&&((*w2).shoupaishu==0))printf("你牵走了一张空气!\n");
else if(x==1&&((*w2).zhuangbeishu==0))printf("你牵走了一张空气!\n");
else if(x==2&&((*w2).pandingshu==0))printf("你牵走了一张空气!\n");
else if(x>=0&&x<=2)break;
else printf("你牵走了太空区里的一张牌!\n");
switch(x)
case 0:
srand((unsigned)time(NULL));
y=rand()%((*w2).shoupaishu);
printf("你牵走了电脑的");
((*w2).shoupai)[y].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).shoupai)[y];
for(i=y+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
((*w1).shoupaishu)++;
break;
case 1:
for(;;)
(*w2).Kanzhuangbei();
printf("请输入装备之前的编号,以回车键结束!\n");
scanf("%d",&y);
if((((*w2).zhuangbei[y]).leixing!=-1)&&(y>=0)&&(y<=3))
printf("你牵走了电脑的");
((*w2).zhuangbei)[y].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).zhuangbei)[y];
((*w2).zhuangbeishu)--;
((*w1).shoupaishu)++;
((*w2).zhuangbei)[y].leixing=-1;
if(!y)((*w2).zhuangbei[y]).changdu=1;
else if(y==2)((*w2).juli[0])++;
else if(y==3)((*w1).juli[0])--;
break;
else printf("你弃掉了一张空气!\n");
break;
case 2:
for(;;)
(*w2).Kanpandingpai();
printf("请输入判定牌之前的编号,以回车键结束!\n");
scanf("%d",&y);
if((*w2).pandingpai[y].leixing!=-1)
printf("你牵走了电脑的");
((*w2).pandingpai)[y].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).pandingpai)[y];
((*w2).pandingshu)--;
((*w1).shoupaishu)++;
((*w2).pandingpai)[y].leixing=-1;
break;
else printf("你牵走了一张空气!\n");
break;
default:break;
else
if((*w2).zhuangbeishu)
if((*w2).zhuangbei[1].leixing!=-1)
printf("电脑牵走了玩家的");
((*w2).zhuangbei)[1].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).zhuangbei)[1];
((*w2).zhuangbeishu)--;
((*w1).shoupaishu)++;
((*w2).zhuangbei)[1].leixing=-1;
else if((*w2).zhuangbei[3].leixing!=-1)
printf("电脑牵走了玩家的");
((*w2).zhuangbei)[3].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).zhuangbei)[3];
((*w2).zhuangbeishu)--;
((*w1).shoupaishu)++;
((*w2).zhuangbei)[3].leixing=-1;
((*w1).juli[0])--;
else if((*w2).zhuangbei[0].leixing!=-1)
printf("电脑牵走了玩家的");
((*w2).zhuangbei)[0].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).zhuangbei)[0];
((*w2).zhuangbeishu)--;
((*w1).shoupaishu)++;
((*w2).zhuangbei)[0].leixing=-1;
((*w2).zhuangbei)[0].changdu=1;
else
printf("电脑牵走了玩家的");
((*w2).zhuangbei)[2].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).zhuangbei)[2];
((*w2).zhuangbeishu)--;
((*w1).shoupaishu)++;
((*w2).zhuangbei)[2].leixing=-1;
((*w2).juli[0])--;
else
srand((unsigned)time(NULL));
y=rand()%((*w2).shoupaishu);
printf("电脑牵走了玩家的手牌");
((*w2).shoupai)[y].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).shoupai)[y];
for(i=y+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
((*w1).shoupaishu)++;
void Wuzhong(wujiang*w1,pai A[104],int *x,pai B[104],int*y)
Mopai(&((*w1).shoupaishu),(*w1).shoupai,A,x,B,y,(*w1).juese);
int Juedou(wujiang*w1,wujiang*w2,pai qipaidui[104],int*qipaishu)
int i,j,x;
if((*w1).juese)
for(;;)
j=0;
for(x=0;x<((*w2).shoupaishu);x++)
if((*w2).shoupai[x].leixing==101)
printf("电脑打出");
((*w2).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(int i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
j=1;
break;
if(!j)
printf("玩家对电脑造成1点伤害!\n");
((*w2).tili)--;
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
break;
j=0;
for(;;)
printf("请打出一张【杀】响应【决斗】,否则你将受到1点伤害!\n请输入手牌之前的编号,或者输入“-1”放弃出【杀】,以回车结束!\n");
if(((*w1).zhuangbei[0].leixing==305))printf("如果想发动【丈八蛇矛】效果,请输入“100”,以回车结束!\n");
(*w1).Kanshoupai();
scanf("%d",&x);
if(x==-1)
int i;
((*w1).tili)--;
printf("电脑对玩家造成1点伤害!\n");
i=Binsi(w2,w1,qipaidui,qipaishu);
return i;
break;
else if(((*w1).zhuangbei[0].leixing==305)&&x==100)
pai p=Zhangba(w1,qipaidui,qipaishu);
p.paifu=-1;
printf("打出!\n");
j=1;
break;
else if((*w1).shoupai[x].leixing==101)
printf("玩家打出");
((*w1).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w1).shoupai)[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
j=1;
break;
else printf("你确定你打出的是【杀】?\n");
else
for(;;)
j=0;
for(;;)
printf("请打出一张【杀】响应【决斗】,否则你将受到1点伤害!\n请输入手牌之前的编号,或者输入“-1”放弃出【杀】,以回车结束!\n");
if(((*w1).zhuangbei[0].leixing==305))printf("如果想发动【丈八蛇矛】效果,请输入“100”,以回车结束!\n");
(*w2).Kanshoupai();
scanf("%d",&x);
if(x==-1)
int i;
((*w2).tili)--;
printf("电脑对玩家造成1点伤害!\n");
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
break;
else if(((*w2).zhuangbei[0].leixing==305)&&x==100)
pai p=Zhangba(w2,qipaidui,qipaishu);
p.paifu=-1;
printf("打出!\n");
j=1;
break;
else if((*w2).shoupai[x].leixing==101)
printf("玩家打出");
((*w2).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
j=1;
break;
else printf("你确定你打出的是【杀】?\n");
j=0;
for(x=0;x<((*w1).shoupaishu);x++)
if((*w1).shoupai[x].leixing==101)
printf("电脑打出");
((*w1).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w1).shoupai)[x];
for(int i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
j=1;
break;
if(!j)
printf("玩家对电脑造成1点伤害!\n");
((*w2).tili)--;
i=Binsi(w2,w1,qipaidui,qipaishu);
return i;
break;
int Jiedao(wujiang*w1,wujiang*w2,pai paidui[104],int*paiduishu,pai qipaidui[104],int*qipaishu)
int i,j=0,x;
if((*w1).juese)
for(x=0;x<((*w2).shoupaishu);x++)
if((*w2).shoupai[x].leixing==101)
printf("电脑对玩家使用");
((*w2).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(int i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
j=1;
break;
if(j)
i=Sha(w2,w1,paidui,paiduishu,qipaidui,qipaishu);
return i;
printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w1).tili,(*w1).tilishangxian,(*w2).tili,(*w2).tilishangxian);
else
printf("电脑放弃使用【杀】,玩家获得电脑的武器");
(*w2).zhuangbei[0].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).zhuangbei)[0];
((*w2).zhuangbeishu)--;
((*w1).shoupaishu)++;
((*w2).zhuangbei)[0].leixing=-1;
((*w2).zhuangbei)[0].changdu=1;
(*w1).Kanshoupai();
return 0;
else
for(;;)
printf("请对电脑使用一张【杀】,否则电脑将获得你的武器!\n请输入手牌之前的编号,或者输入“-1”放弃出【杀】,以回车结束!\n");
if(((*w2).zhuangbei[0].leixing==305))printf("如果想发动【丈八蛇矛】效果,请输入“100”,以回车结束!\n");
(*w2).Kanshoupai();
scanf("%d",&x);
if(x==-1)break;
else if(((*w2).zhuangbei[0].leixing==305)&&x==100)
pai p=Zhangba(w2,qipaidui,qipaishu);
p.paifu=-1;
printf("使用!\n");
j=1;
break;
else if((*w2).shoupai[x].leixing==101)
printf("玩家对电脑使用");
((*w2).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
j=1;
break;
else printf("你确定你使用的是【杀】?\n");
if(j)
i=Sha(w2,w1,paidui,paiduishu,qipaidui,qipaishu);
return i;
printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w2).tili,(*w2).tilishangxian,(*w1).tili,(*w1).tilishangxian);
else
printf("玩家放弃使用【杀】,电脑获得玩家的武器");
((*w2).zhuangbei)[0].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).zhuangbei)[0];
((*w2).zhuangbeishu)--;
((*w1).shoupaishu)++;
((*w2).zhuangbei)[0].leixing=-1;
((*w2).zhuangbei)[0].changdu=1;
return 0;
void Taoyuan(wujiang*w)
if((*w).tili<(*w).tilishangxian)
((*w).tili)++;
if((*w).juese)printf("玩家");
else printf("电脑");
printf("恢复1点体力!\n");
void Kaipai(pai paidui[104],int* paiduishu,int renshu,pai wugu[10])
int i;
printf("五谷丰登开牌:\n");
for(i=1;i<=renshu;i++)
wugu[i-1]=paidui[104-(*paiduishu)];
(*paiduishu)--;
printf("%d ",i-1);
wugu[i-1].Kanpai();
void Qupai(pai wugu[10],wujiang*w)
int i,x;
printf("五谷丰登开牌:\n");
for(i=0;(wugu[i].leixing)!=-1;i++)
printf("%d ",i);
wugu[i].Kanpai();
if((*w).juese)
for(;;)
printf("请选择你想要的卡牌,输入卡牌之前的编号,以回车结束!\n");
scanf("%d",&x);
if(wugu[x].leixing!=-1)
printf("玩家选择");
wugu[x].Kanpai();
(*w).shoupai[(*w).shoupaishu]=wugu[x];
((*w).shoupaishu)++;
for(i=x+1;i<=9;i++)wugu[i-1]=wugu[i];
wugu[9].leixing=-1;
break;
printf("你选择了一张空气加入手牌!");
else
printf("电脑选择");
wugu[0].Kanpai();
(*w).shoupai[(*w).shoupaishu]=wugu[0];
((*w).shoupaishu)++;
for(i=1;i<=9;i++)wugu[i-1]=wugu[i];
wugu[9].leixing=-1;
void Rengpai(pai wugu[10],pai qipaidui[104],int*qipaishu)
int i;
for(i=0;wugu[i].leixing!=-1;i++)
qipaidui[*qipaishu]=wugu[i];
(*qipaishu)++;
wugu[i].leixing=-1;
int Nanman(wujiang*w1,wujiang*w2,pai qipaidui[104],int*qipaishu)
int i,x;
if((*w1).juese)
for(x=0;x<((*w2).shoupaishu);x++)
if((*w2).shoupai[x].leixing==101)
printf("电脑打出");
((*w2).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(int i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
return 0;
break;
printf("玩家对电脑造成1点伤害!\n");
((*w2).tili)--;
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
else
for(;;)
printf("请打出一张【杀】响应【南蛮入侵】,否则你将受到1点伤害!\n请输入手牌之前的编号,或者输入“-1”放弃出【杀】,以回车结束!\n");
if(((*w2).zhuangbei[0].leixing==305))printf("如果想发动【丈八蛇矛】效果,请输入“100”,以回车结束!\n");
(*w2).Kanshoupai();
scanf("%d",&x);
if(x==-1)
int i;
((*w2).tili)--;
printf("电脑对玩家造成1点伤害!\n");
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
break;
else if(((*w2).zhuangbei[0].leixing==305)&&x==100)
pai p=Zhangba(w2,qipaidui,qipaishu);
p.paifu=-1;
printf("使用!\n");
return 0;
break;
else if((*w2).shoupai[x].leixing==101)
printf("玩家打出");
((*w2).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
return 0;
break;
else printf("你确定你打出的是【杀】?\n");
int Wanjian(wujiang*w1,wujiang*w2,pai paidui[104],int*paiduishu,pai qipaidui[104],int*qipaishu)
int i;
i=Shan(w1,w2,paidui,paiduishu,qipaidui,qipaishu);
if(i==-1)
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
else return 0;
int Chupai(pai paidui[104],pai qipaidui[104],int *paiduishu,int*qipaishu,wujiang*w1,wujiang*w2,pai yuanshipaidui[2][4][13])
pai p1;
int sha=1;int y=-1,i,t=((*w1).shoupaishu)-1;
for(;;t--)
if((*w1).juese)
printf("\n电脑当前手牌数:%d\n",((*w2).shoupaishu));
(*w2).Kanzhuangbei();
(*w1).Kanshoupai();
(*w1).Kanzhuangbei();
int j=0;
if((*w1).juese&&((*w1).zhuangbei[0].leixing==305))printf("如果想发动【丈八蛇矛】效果,请输入“100”,以回车结束!\n");
y=Xuanpai(w1,t);
p1=Panpai(w1,&sha,y,qipaidui,qipaishu);
if((p1).leixing==-1)break;
else if((p1).leixing==0)continue;
else
int duixiang;
duixiang=Mubiao(p1,w1,w2,&sha);
if(duixiang==-2)continue;
else
Da1pai(w1,w2,qipaidui,qipaishu,y);
Miaoshu(p1,((*w1).juese),duixiang);
if(!((*w1).juese))
printf("\n电脑当前手牌数:%d\n",((*w1).shoupaishu));
(*w1).Kanzhuangbei();
(*w2).Kanshoupai();
(*w2).Kanzhuangbei();
switch(p1.leixing)
case 101:
i=Sha(w1,w2,paidui,paiduishu,qipaidui,qipaishu);
if(i==-1)return -1;break;
if((*w1).juese)printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w1).tili,(*w1).tilishangxian,(*w2).tili,(*w2).tilishangxian);
else printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w2).tili,(*w2).tilishangxian,(*w1).tili,(*w1).tilishangxian);
break;
case 103:
Tao(w1);
break;
case 201:
for(;;)
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
if(!(j%2))Chai(w1,w2,qipaidui,qipaishu);
else;
if((*w1).juese)(*w1).Kanshoupai();
break;
case 202:
for(;;)
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
if(!(j%2))Qian(w1,w2);
else;
if((*w1).juese)(*w1).Kanshoupai();
break;
case 203:
for(;;)
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
if(!(j%2))Wuzhong(w1,paidui,paiduishu,qipaidui,qipaishu);
else;
break;
case 204:
for(;;)
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
if(!(j%2))
i=Juedou(w1,w2,qipaidui,qipaishu);
if(i==-1)return -1;
if((*w1).juese)printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w1).tili,(*w1).tilishangxian,(*w2).tili,(*w2).tilishangxian);
else printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w2).tili,(*w2).tilishangxian,(*w1).tili,(*w1).tilishangxian);
break;
case 205:
for(;;)
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
if(!(j%2))
i=Jiedao(w1,w2,paidui,paiduishu,qipaidui,qipaishu);
if(i==-1)return -1;
if((*w1).juese)printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w1).tili,(*w1).tilishangxian,(*w2).tili,(*w2).tilishangxian);
else printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w2).tili,(*w2).tilishangxian,(*w1).tili,(*w1).tilishangxian);
break;
case 206:
for(;;)
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
if(!(j%2))Taoyuan(w1);
j=0;
for(;;)
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
if(!(j%2))Taoyuan(w2);
break;
case 207:
pai wugu[10];
for(i=1;i<=10;i++)wugu[i-1].leixing=-1;
Kaipai(paidui,paiduishu,2,wugu);
for(;;)
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
if(!(j%2))Qupai(wugu,w1);
for(;;)
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
if(!(j%2))Qupai(wugu,w2);
Rengpai(wugu,qipaidui,qipaishu); printf("弃牌数:%d\n",*qipaishu);
break;
case 208:
for(;;)
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
if(!(j%2))
i=Nanman(w1,w2,qipaidui,qipaishu);
if(i==-1)return -1;
if((*w1).juese)printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w1).tili,(*w1).tilishangxian,(*w2).tili,(*w2).tilishangxian);
else printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w2).tili,(*w2).tilishangxian,(*w1).tili,(*w1).tilishangxian);
break;
case 209:
for(;;)
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
if(!(j%2))
i=Wanjian(w1,w2,paidui,paiduishu,qipaidui,qipaishu);
if(i==-1)return -1;
if((*w1).juese)printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w1).tili,(*w1).tilishangxian,(*w2).tili,(*w2).tilishangxian);
else printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w2).tili,(*w2).tilishangxian,(*w1).tili,(*w1).tilishangxian);
break;
case 361:
case 362:
case 363:
((*w1).juli[0])--;break;
case 381:
case 382:
case 383:
((*w2).juli[0])++;break;
default:break;
printf("\n");
return 0;
void Qipai(pai shoupai[20],int *shoupaishu,pai qipaidui[104],int *qipaishu,int juese,int *shoupaishangxian)
int x;
if((*shoupaishu)>(*shoupaishangxian))
if(juese!=1&&juese!=0)printf("身份参数错误!");
int q=(*shoupaishu)-(*shoupaishangxian);
int i,j;
for(j=1;j<=q;j++)
for(;;)
if(juese)
printf("弃牌请输入手牌之前的编号,以回车结束!\n注:一次只能弃一张牌\n");
printf("手牌数:%d\n",*shoupaishu);
scanf("%d",&x);
if(x>=0&&x<(*shoupaishu))break;
else printf("你弃掉了一张空气!\n");
else
srand((unsigned)time(NULL));
x=rand()%(*shoupaishu);
break;
qipaidui[*qipaishu]=shoupai[x];
for(i=x+1;i<=(*shoupaishu);i++)shoupai[i-1]=shoupai[i];
(*shoupaishu)--;
if(juese)printf("弃牌阶段玩家弃置");
else printf("弃牌阶段电脑弃置");
qipaidui[*qipaishu].Kanpai();
(*qipaishu)++;
int m;
if(juese)
printf("玩家当前手牌:\n");
for(m=0;m<=(*shoupaishu-1);m++)
printf("%d ",m);
(shoupai[m]).Kanpai();
printf("弃牌堆:%d\n",*qipaishu);
int Huihe(pai A[104],pai B[104],int *x,int *y,pai yuanshipaidui[2][4][13],wujiang *w1,wujiang *w2)
printf("\n回合开始阶段……\n");
switch((*w1).huihekaishi)
case 0:break;
default:printf("回合开始阶段参数错误!\n");break;
printf("判定阶段……\n");
int K=0;
if((*w1).pandingshu>0)
int i,j;
for(;(*w1).pandingshu;)
switch((*w1).pandingpai[0].leixing)
case 251:printf("【乐不思蜀】开始判定……\n"); break;
case 252:printf("【闪电】开始判定……\n");break;
default:printf("【??】开始判定……\n");break;
j=0;
pai p=((*w1).pandingpai[0]);
for(;;)//在判定之前询问【无懈】
i=Wuxie(&p,w2,w1,B,y,0);
if(!i)break;
j++;
i=Wuxie(&p,w1,w2,B,y,0);
if(!i)break;
j++;
switch((*w1).pandingpai[0].leixing)
case 251:
if(!(j%2))
printf("【乐不思蜀】的判定牌是:");
Panding(A,x,B,y);
if((B[(*y)-1].huase)!=1)
printf("【乐不思蜀】判定成功!\n");
if((*w1).juese)printf("玩家");
else printf("电脑");
printf("跳过出牌阶段!\n");
K=-1;
else printf("【乐不思蜀】判定失败!\n");
B[*y]=(*w1).pandingpai[0];
((*w1).pandingshu)--;
(*w1).pandingpai[0]=(*w1).pandingpai[1];
(*w1).pandingpai[1]=(*w1).pandingpai[2];
(*w1).pandingpai[2].leixing=-1;
(*y)++;
break;
case 252:
if(!(j%2))
printf("【闪电】的判定牌是:");
Panding(A,x,B,y);
if((B[(*y)-1].huase==0)&&(B[(*y)-1].dianshu>=1)&&(B[(*y)-1].dianshu<=8))
printf("【闪电】判定成功!\n");
if((*w1).juese)printf("玩家");
else printf("电脑");
printf("受到3点雷电伤害!");
((*w1).tili)=((*w1).tili)-3;
i=Binsi(w2,w1,B,y);
B[*y]=(*w1).pandingpai[0];
((*w1).pandingshu)--;
(*w1).pandingpai[0]=(*w1).pandingpai[1];
(*w1).pandingpai[1]=(*w1).pandingpai[2];
(*w1).pandingpai[2].leixing=-1;
(*y)++;
if(i==-1)return -1;
else
printf("【闪电】判定失败!\n");
(*w2).pandingpai[2]=(*w2).pandingpai[1];
(*w2).pandingpai[1]=(*w2).pandingpai[0];
(*w2).pandingpai[0]=(*w1).pandingpai[0];
(*w1).pandingpai[0]=(*w1).pandingpai[1];
(*w1).pandingpai[1]=(*w1).pandingpai[2];
(*w1).pandingpai[2].leixing=-1;
((*w1).pandingshu)--;
((*w2).pandingshu)++;
break;
default:printf("判定牌错误!");
printf("弃牌数:%d\n",*y);
else if(!((*w1).pandingshu));
else printf("判定阶段参数错误!\n");
printf("摸牌阶段……\n");
switch((*w1).mopai)
case 0:Mopai(&((*w1).shoupaishu),(*w1).shoupai,A,x,B,y,(*w1).juese);break;
case -1:break;
default:printf("摸牌阶段参数错误!\n");break;
if(K==-1)goto M;
printf("出牌阶段……\n");
switch((*w1).chupai)
case 0:
int i;
i=Chupai(A,B,x,y,w1,w2,yuanshipaidui);
if(i==-1)
return -1;
break;
else break;
case -1:break;
default:printf("出牌阶段参数错误!\n");break;
M:
printf("弃牌阶段……\n");
switch((*w1).qipai)
case 0:
Qipai((*w1).shoupai,&((*w1).shoupaishu),B,y,(*w1).juese,&((*w1).tili));break;
default:printf("弃牌阶段参数错误!\n");break;
printf("回合结束阶段……\n");
switch((*w1).huihejieshu)
case 0:break;
default:printf("回合结束阶段参数错误!\n");break;
return 0;
int main()
void Kanshoupai(pai p);
pai yuanshipaidui[2][4][13],qipaidui[104],paidui[104];
wujiang wanjia,com;
com.tili=wanjia.tili=5;
com.tilishangxian=wanjia.tilishangxian=5;
com.huihekaishi=wanjia.huihekaishi=0;
com.panding=wanjia.panding=0;
com.mopai=wanjia.mopai=0;
com.chupai=wanjia.chupai=0;
com.qipai=wanjia.qipai=0;
com.huihejieshu=wanjia.huihejieshu=0;
com.shoupaishu=wanjia.shoupaishu=0;
com.pandingshu=wanjia.pandingshu=0;
com.zhuangbeishu=wanjia.zhuangbeishu=0;
com.juese=0;wanjia.juese=1;
pai p;
p.leixing=-1;
com.zhuangbei[0]=com.zhuangbei[1]=com.zhuangbei[2]=com.zhuangbei[3]=wanjia.zhuangbei[0]=wanjia.zhuangbei[1]=wanjia.zhuangbei[2]=wanjia.zhuangbei[3]=p;
com.zhuangbei[0].changdu=wanjia.zhuangbei[0].changdu=1;
com.pandingpai[0]=com.pandingpai[1]=com.pandingpai[2]=wanjia.pandingpai[0]=wanjia.pandingpai[1]=wanjia.pandingpai[2]=p;
com.juli[0]=wanjia.juli[0]=1;
int a,b,c;
for(a=0;a<=1;a++)
for(b=0;b<=3;b++)
for(c=0;c<=12;c++)
yuanshipaidui[a][b][c].paifu=a;
yuanshipaidui[a][b][c].huase=b;
yuanshipaidui[a][b][c].dianshu=c;
yuanshipaidui[0][0][0].leixing=204;
yuanshipaidui[0][0][1].leixing=331;
yuanshipaidui[0][0][2].leixing=201;
yuanshipaidui[0][0][3].leixing=201;
yuanshipaidui[0][0][4].leixing=304;yuanshipaidui[0][0][4].changdu=3;
yuanshipaidui[0][0][5].leixing=251;
yuanshipaidui[0][0][6].leixing=101;
yuanshipaidui[0][0][7].leixing=101;
yuanshipaidui[0][0][8].leixing=101;
yuanshipaidui[0][0][9].leixing=101;
yuanshipaidui[0][0][10].leixing=202;
yuanshipaidui[0][0][11].leixing=201;
yuanshipaidui[0][0][12].leixing=208;
yuanshipaidui[0][1][0].leixing=209;
yuanshipaidui[0][1][1].leixing=102;
yuanshipaidui[0][1][2].leixing=103;
yuanshipaidui[0][1][3].leixing=103;
yuanshipaidui[0][1][4].leixing=308;yuanshipaidui[0][1][4].changdu=5;
yuanshipaidui[0][1][5].leixing=103;
yuanshipaidui[0][1][6].leixing=103;
yuanshipaidui[0][1][7].leixing=103;
yuanshipaidui[0][1][8].leixing=103;
yuanshipaidui[0][1][9].leixing=101;
yuanshipaidui[0][1][10].leixing=101;
yuanshipaidui[0][1][11].leixing=103;
yuanshipaidui[0][1][12].leixing=102;
yuanshipaidui[0][2][0].leixing=204;
yuanshipaidui[0][2][1].leixing=101;
yuanshipaidui[0][2][2].leixing=101;
yuanshipaidui[0][2][3].leixing=101;
yuanshipaidui[0][2][4].leixing=101;
yuanshipaidui[0][2][5].leixing=101;
yuanshipaidui[0][2][6].leixing=101;
yuanshipaidui[0][2][7].leixing=101;
yuanshipaidui[0][2][8].leixing=101;
yuanshipaidui[0][2][9].leixing=101;
yuanshipaidui[0][2][10].leixing=101;
yuanshipaidui[0][2][11].leixing=205;
yuanshipaidui[0][2][12].leixing=205;
yuanshipaidui[0][3][0].leixing=204;
yuanshipaidui[0][3][1].leixing=102;
yuanshipaidui[0][3][2].leixing=102;
yuanshipaidui[0][3][3].leixing=102;
yuanshipaidui[0][3][4].leixing=102;
yuanshipaidui[0][3][5].leixing=101;
yuanshipaidui[0][3][6].leixing=101;
yuanshipaidui[0][3][7].leixing=101;
yuanshipaidui[0][3][8].leixing=101;
yuanshipaidui[0][3][9].leixing=101;
yuanshipaidui[0][3][10].leixing=102;
yuanshipaidui[0][3][11].leixing=103;
yuanshipaidui[0][3][12].leixing=101;
yuanshipaidui[1][0][0].leixing=252;
yuanshipaidui[1][0][1].leixing=302;yuanshipaidui[1][0][1].changdu=2;
yuanshipaidui[1][0][2].leixing=202;
yuanshipaidui[1][0][3].leixing=202;
yuanshipaidui[1][0][4].leixing=383;
yuanshipaidui[1][0][5].leixing=303;yuanshipaidui[1][0][5].changdu=2;
yuanshipaidui[1][0][6].leixing=208;
yuanshipaidui[1][0][7].leixing=101;
yuanshipaidui[1][0][8].leixing=101;
yuanshipaidui[1][0][9].leixing=101;
yuanshipaidui[1][0][10].leixing=210;
yuanshipaidui[1][0][11].leixing=305;yuanshipaidui[1][0][11].changdu=3;
yuanshipaidui[1][0][12].leixing=362;
yuanshipaidui[1][1][0].leixing=206;
yuanshipaidui[1][1][1].leixing=102;
yuanshipaidui[1][1][2].leixing=207;
yuanshipaidui[1][1][3].leixing=207;
yuanshipaidui[1][1][4].leixing=361;
yuanshipaidui[1][1][5].leixing=251;
yuanshipaidui[1][1][6].leixing=203;
yuanshipaidui[1][1][7].leixing=203;
yuanshipaidui[1][1][8].leixing=203;
yuanshipaidui[1][1][9].leixing=101;
yuanshipaidui[1][1][10].leixing=203;
yuanshipaidui[1][1][11].leixing=201;
yuanshipaidui[1][1][12].leixing=381;
yuanshipaidui[1][2][0].leixing=301;yuanshipaidui[1][2][0].changdu=1;
yuanshipaidui[1][2][1].leixing=331;
yuanshipaidui[1][2][2].leixing=201;
yuanshipaidui[1][2][3].leixing=201;
yuanshipaidui[1][2][4].leixing=382;
yuanshipaidui[1][2][5].leixing=251;
yuanshipaidui[1][2][6].leixing=208;
yuanshipaidui[1][2][7].leixing=101;
yuanshipaidui[1][2][8].leixing=101;
yuanshipaidui[1][2][9].leixing=101;
yuanshipaidui[1][2][10].leixing=101;
yuanshipaidui[1][2][11].leixing=210;
yuanshipaidui[1][2][12].leixing=210;
yuanshipaidui[1][3][0].leixing=301;yuanshipaidui[1][3][0].changdu=1;
yuanshipaidui[1][3][1].leixing=102;
yuanshipaidui[1][3][2].leixing=202;
yuanshipaidui[1][3][3].leixing=202;
yuanshipaidui[1][3][4].leixing=306;yuanshipaidui[1][3][4].changdu=3;
yuanshipaidui[1][3][5].leixing=102;
yuanshipaidui[1][3][6].leixing=102;
yuanshipaidui[1][3][7].leixing=102;
yuanshipaidui[1][3][8].leixing=102;
yuanshipaidui[1][3][9].leixing=102;
yuanshipaidui[1][3][10].leixing=102;
yuanshipaidui[1][3][11].leixing=307;yuanshipaidui[1][3][11].changdu=4;
yuanshipaidui[1][3][12].leixing=363;
int paiduishu=104;
int qipaishu=0;
printf("游戏开始!\n");
Qishixipai(yuanshipaidui,paidui);
Qishishoupai(&wanjia,paidui,&(paiduishu),qipaidui,&(qipaishu));
Qishishoupai(&com,paidui,&(paiduishu),qipaidui,&(qipaishu));
int i;
for(;;)
i=Huihe(paidui,qipaidui,&paiduishu,&qipaishu,yuanshipaidui,&wanjia,&com);
if(i==-1)break;
i=Huihe(paidui,qipaidui,&paiduishu,&qipaishu,yuanshipaidui,&com,&wanjia);
if(i==-1)break;
return 0;
扫雷
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<conio.h>
#include<windows.h>
#include<cstdlib>
#include<ctime>
using namespace std;
#define MAXN 35
#define MIDX 10
#define MIDY 40
#define CG 25
#define CK 80
int G,K,Lnum,Wnum;//G为地图高,K为地图,Lnum为地图中的雷数,Wnum为剩余的小旗数
int nx,ny;//现在光标所在的位置
bool QR=0,Lose=0,is_flag_true[MAXN][MAXN];//QR为确认模式是否打开,Lose为是否输,第三个是这个位置上的旗是否放对
char map[MAXN][MAXN],tmap[MAXN][MAXN];//第一个是只有雷和空地的地图,第二个是玩家能看到的地图
int map1[MAXN][MAXN],mapc[MAXN][MAXN];//map1为数字的地图,其中0代表空地,-1为雷,1-8为周围雷的个数
//mapc为当前格子的颜色
int col[10]=240,249,242,252,241,244,243,240,248;//col[i]表示windows扫雷中i的颜色,col[0]为空格的颜色
int d[10][4]=0,0,1,1,0,0,-1,-1,0,1,1,1,-1,-1,1,-1,-1;//8个方向
bool ZB;//作弊是否打开
/*各种函数*/
void color(int);//颜色
void gto(int,int);//光标位置
void make();//制作随机地图
void print();//打印地图等
bool check(int,int);//判断坐标是否合法
bool is_win();//判断是否赢
bool is_lose();//是否输
void dfs(int,int);//用深搜来打开方块
void st(int,int);//试探,即windows扫雷中的左右键同时按
void flag(int,int);//小旗
void bj(int,int);//标记
void swt();//确认模式
void again();//重新开始
void zb();//作弊模式
void mainmain();//主函数
void print_real_map();//打印最终的地图
void begin();//各种操作
int main()
mainmain();
void color(int a)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
void gto(int x,int y)
COORD pos;pos.X=y;pos.Y=x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
void make()
for(int i=1;i<=G;i++)
for(int j=1;j<=K;j++)
map[i][j]='#';//初始化
for(int i=1;i<=Lnum;i++)
int x=rand()%G+1,y=rand()%K+1;
while(map[x][y]=='O')
x=rand()%G+1,y=rand()%K+1;
map[x][y]='O';
//随机放雷
for(int i=1;i<=G;i++)
for(int j=1;j<=K;j++)
if(map[i][j]=='O')map1[i][j]=-1,mapc[i][j]=240;//如果是雷
else
for(int k=1;k<=8;k++)
if(map[i+d[k][0]][j+d[k][1]]=='O')
map1[i][j]++;//计算周围雷的个数
mapc[i][j]=col[map1[i][j]];//根据格子上的数设置颜色
for(int i=1;i<=G;i++)
for(int j=1;j<=K;j++)
if(mapc[i][j]==0)//空地
mapc[i][j]=240;
void print()
system("cls");
gto(0,MIDY-4); color(233); printf("扫雷");
color(240);
gto(1,MIDY);
for(int i=2;i<=G+1;i++)
gto(i,0);
for(int j=1;j<=K;j++)
printf("#"),tmap[i-1][j]='#';//初始化玩家所看到的地图
gto(2,0);
nx=2,ny=0;
color(15);
printf("@");
color(15);
gto(2,2*K+5);printf("-----规则-----");
gto(3,2*K+5);printf("wasd:选择位置");
gto(4,2*K+5);printf("空格:打开");
gto(5,2*K+5);printf("1键:试探周围8个方块,如果其中有雷则不会打开,无");
gto(6,2*K+5);printf(" 雷或旗帜标对了则会将周围无雷的位置打开,");
gto(7,2*K+5);printf(" 如果试探时周围有标错的旗帜,则会游戏失败");
gto(8,2*K+5);printf(" 必须额外确认一次,以便查看周围被试探的区域");
gto(9,2*K+5);printf("2键:放置/取消小旗(F)");
gto(10,2*K+5);printf("3键:放置/取消标记(?)");
gto(11,2*K+5);printf("4键:打开/关闭确认模式,即每次操作需再按一次确认");
gto(12,2*K+5);printf("5键:打开/关闭作弊模式,即显示原本地图");
gto(13,2*K+5);printf("0键:重新开始");//打印规则
gto(G+4,0);printf("-----操作提示-----\n");
printf("请选择方块进行操作");
gto(1,2*K+10);color(12);printf("剩余小旗数:%d",Wnum=Lnum);
bool check(int x,int y)return y>=0&&y<K&&x>=2&&x<G+2;
//因为地图是从2行0列开始打的,而地图是从1行1列开始存的,所以gto(x,y)走到的是map[x-1][y+1]
bool is_win()
int cnt=0;
for(int i=1;i<=G;i++)
for(int j=1;j<=K;j++)
if(map[i][j]=='#'&&map1[i][j]==-1)
cnt++;
if(cnt==Lnum) return 1;
//所有没被打开的方块都是雷=>胜利
for(int i=1;i<=G;i++)
for(int j=1;j<=K;j++)
if((tmap[i][j]!='F'&&map1[i][j]==-1)||(tmap[i][j]=='F'&&map1[i][j]!=-1))
return 0;
return 1;
//所有雷都标有旗
bool is_lose()return Lose;
void dfs(int x,int y)
if(map1[x-1][y+1]>0)//只要边界全部是数字就return
gto(x,y),color(mapc[x-1][y+1]),printf("%d",map1[x-1][y+1]);
tmap[x-1][y+1]=map1[x-1][y+1]+'0';
return;
gto(x,y);color(255);
tmap[x-1][y+1]=' ';
printf(" ");//因为下面判断了雷,上面判断了数字,这里就一定是空地
for(int i=1;i<=8;i++)
int xx=x+d[i][0]-1,yy=y+d[i][1]+1;//这里的xx和yy是在map中的,而不是gto中的
if(check(xx+1,yy-1)&&tmap[xx][yy]=='#'&&map1[xx][yy]!=-1)//所以check和dfs的参数要变化
dfs(xx+1,yy-1);
void st(int x,int y)
for(int i=1;i<=8;i++)
int xx=x+d[i][0],yy=y+d[i][1];
if(check(xx,yy))
gto(xx,yy);
if(tmap[xx-1][yy+1]!='#')
color(mapc[xx-1][yy+1]-128);//减去128使周围的8个格子的背景颜色变为灰色
else
color(112);//这里特判一下'#',应该可以不用
printf("%c",tmap[xx-1][yy+1]);
gto(G+5,0),color(15),printf("请确认 ");
//试探必须额外确认一次,规则上有说
char c=getch();
if(c=='1')
for(int i=1;i<=8;i++)
int xx=x+d[i][0],yy=y+d[i][1];
if(check(xx,yy))
if(tmap[xx-1][yy+1]=='F'&&map1[xx-1][yy+1]!=-1)//试探时有格子的小旗标错了=>失败
Lose=1;
return;
for(int i=1;i<=8;i++)
int xx=x+d[i][0],yy=y+d[i][1];
if(check(xx,yy))
if(map1[xx-1][yy+1]==-1&&tmap[xx-1][yy+1]!='F')//试探是有格子为雷=>取消打开
return;
for(int i=1;i<=8;i++)
int xx=x+d[i][0],yy=y+d[i][1];
if(check(xx,yy)&&tmap[xx-1][yy+1]=='#')//打开周围8个格子
dfs(xx,yy);
void flag(int x,int y)
x-=1,y+=1;
if(tmap[x][y]=='F')//原本为小旗=>取消小旗
tmap[x][y]='#';mapc[x][y]=240;
gto(x+1,y-1),color(240),printf("#");
Wnum++;//更新小旗数
else//否则就放置小旗
is_flag_true[x][y]=map1[x][y]==-1;//判断小旗是否放对
tmap[x][y]='F';mapc[x][y]=253;
gto(x+1,y-1),color(253),printf("F");
Wnum--;//更新小旗数
gto(1,2*K+10);color(12);printf("剩余小旗数: ");
gto(1,2*K+22);printf("%d",Wnum);//更新小旗数
void bj(int x,int y)//和放小旗差不多,只是不用更新is_flag_true
x-=1,y+=1;
if(tmap[x][y]=='?')
gto(x+1,y-1),color(240),printf("#");
tmap[x][y]='#';mapc[x][y]=240;
else
if(tmap[x][y]=='F')//如果原本这个位置上是小旗,而你把它变为了标记,就要更新小旗数
Wnum++;
gto(1,2*K+10);color(12);printf("剩余小旗数: ");
gto(1,2*K+22);printf("%d",Wnum);
gto(x+1,y-1),color(240),printf("?");
tmap[x][y]='?';mapc[x][y]=240;
void swt()QR=!QR;
void zb()
if(ZB)//如果本来作弊打开了就把作弊地图清除
for(int i=1;i<=G;i++)
gto(i+1,K+2);
for(int j=1;j<=K;j++)
color(15),printf(" ");
ZB=0;
else//否则打印作弊地图
for(int i=1;i<=G;i++)
gto(i+1,K+2);
for(int j=1;j<=K;j++)
color(mapc[i][j]);
if(map1[i][j]==-1) printf("O");
else if(map1[i][j]>0) printf("%d",map1[i][j]);
else printf(" ");
ZB=1;
void again()
G=K=Lnum=nx=ny=Lose=ZB=0;
QR=0;
memset(is_flag_true,0,sizeof(is_flag_true));
memset(map,0,sizeof(map));
memset(tmap,0,sizeof(tmap));
memset(map1,0,sizeof(map1));
memset(mapc,0,sizeof(mapc));
color(15);
system("cls");//初始化
mainmain();
void begin()//各种操作
char c=getch();
gto(G+5,0),color(15),printf("请选择方块进行操作");
color(240);
if(c=='w'&&check(nx-1,ny))
gto(nx,ny);
if(tmap[nx-1][ny+1]!='#'||tmap[nx-1][ny+1]==' ')
color(mapc[nx-1][ny+1]);
printf("%c",tmap[nx-1][ny+1]);
gto(nx-=1,ny);color(15);printf("@");
else if(c=='s'&&check(nx+1,ny))
gto(nx,ny);if(tmap[nx-1][ny+1]!='#'||tmap[nx-1][ny+1]==' ')color(mapc[nx-1][ny+1]);printf("%c",tmap[nx-1][ny+1]);
gto(nx+=1,ny);color(15);printf("@");
else if(c=='a'&&check(nx,ny-1))
gto(nx,ny);if(tmap[nx-1][ny+1]!='#'||tmap[nx-1][ny+1]==' ')color(mapc[nx-1][ny+1]);printf("%c",tmap[nx-1][ny+1]);
gto(nx,ny-=1);color(15);printf("@");
else if(c=='d'&&check(nx,ny+1))
gto(nx,ny);if(tmap[nx-1][ny+1]!='#'||tmap[nx-1][ny+1]==' ')color(mapc[nx-1][ny+1]);printf("%c",tmap[nx-1][ny+1]);
gto(nx,ny+=1);color(15);printf("@");
//上下左右移动
else
if(c==' '&&(!(tmap[nx-1][ny+1]<='9'&&tmap[nx-1][ny+1]>='0'))&&tmap[nx-1][ny+1]!='F')
mapc[nx-1][ny+1]=col[map1[nx-1][ny+1]];//如果本来放了标记,mapc[nx-1][ny+1]的颜色为黑色,在打开时里面的颜色却不一定是黑色
if(QR)
gto(G+5,0),color(15),printf("请确认 ");
if(getch()==' ')
if(map1[nx-1][ny+1]==-1) Lose=1;return;
dfs(nx,ny);
else
if(map1[nx-1][ny+1]==-1) Lose=1;return;
dfs(nx,ny);
else if(c=='1')
if(QR)
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='1') st(nx,ny);
else st(nx,ny);
for(int i=1;i<=8;i++)
int xx=nx+d[i][0],yy=ny+d[i][1];
if(check(xx,yy))
gto(xx,yy);
if(tmap[xx-1][yy+1]!='#') color(mapc[xx-1][yy+1]);
else color(240);
printf("%c",tmap[xx-1][yy+1]);
else if(c=='2'&&(tmap[nx-1][ny+1]>'9'||tmap[nx-1][ny+1]<'1'))
if(QR)
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='2') flag(nx,ny);
else flag(nx,ny);
else if(c=='3'&&(tmap[nx-1][ny+1]>'9'||tmap[nx-1][ny+1]<'1'))
if(QR)
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='3') bj(nx,ny);
else bj(nx,ny);
else if(c=='4')
if(QR)
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='4') swt();
else swt();
else if(c=='5')
if(QR)
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='5') zb();
else zb();
else if(c=='0')
if(QR)
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='0') again();
else again();
void mainmain()
system("mode con cols=120 lines=35");//设置窗口大小
srand((unsigned)time(NULL));
int mode;
printf("1.初级\n2.中级\n3.高级\n4.自定义\n");
scanf("%d",&mode);if(mode>4) mode=4;
if(mode==1) G=9,K=9,Lnum=10;
else if(mode==2) G=16,K=16,Lnum=40;
else if(mode==3) G=16,K=30,Lnum=99;//三种等级的参数
else
printf("请输入雷区高度:");scanf("%d",&G);
printf("请输入雷区宽度:");scanf("%d",&K);
printf("请输入雷个数(建议不超过总大小的三分之一):");scanf("%d",&Lnum);
if(G>24) G=24;if(K>30) K=30;
if(G<9) G=9;if(K<9) K=9;
if(Lnum<10) Lnum=10;if(Lnum>G*K*9/10) Lnum=G*K*9/10;
//控制参数的范围,最后一个if是雷的数量不超过地图大小的9/10
make();
print();
while(1)
begin();
bool f1=is_win(),f2=is_lose();
if(f1||f2)
gto(0,0);
if(f1)
color(202),gto(0,0),printf("你 赢 了!!是否重来?(y/n)");
if(f2)
color(137),gto(0,0),printf("你 输 了!!是否重来?(y/n)");//输赢
print_real_map();
char c=getch();
if(c=='y'||c=='Y') again();
else
color(15);
system("cls");
gto(MIDX,MIDY-5);
printf("欢迎下次再来");
return;
void print_real_map()
color(240);
for(int i=1;i<=G;i++)
gto(i+1,0);
for(int j=1;j<=K;j++)
if(tmap[i][j]=='F'&&is_flag_true[i][j]==0)//如果旗标错了显示红色的X
color(252),printf("X");
else if(map1[i][j]==-1)//雷为黑色O
color(240),printf("O");
else if(map1[i][j]==0)//空
color(240),printf(" ");
else//数字
color(mapc[i][j]),printf("%d",map1[i][j]);
以上是关于机房小游戏的主要内容,如果未能解决你的问题,请参考以下文章