23根火柴游戏.doc

  1. 1、本文档共3页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
23根火柴游戏

#includeiostream #includestring #define NUM 20 using namespace std; void main() { //规则的输出 coutendl; cout***************************************************endl; cout游戏规则:共有23根火柴,2个人依次拿取,每个人每次只endl; cout能拿1跟或者2跟或者3跟火柴。拿到最后一跟火柴的人算输endl; cout****************************************************endl; coutendl; //变量的定义 int match_num=23; //火柴数目 int *p_match_num; //指向火柴数目的指针 int player = 0; //玩家变量,偶数代表玩家1,奇数代表玩家2 char player_first[NUM]; //玩家1的名字 char player_second[NUM]; //玩家2的名字 char judge; //判断变量,值为y时,表示玩家1先开局 int put_num=0; //拿走火柴的数目 char temp[NUM]; char *p_player_now; int *p_put_num; //指向拿走火柴数目的指针 int *p_player; //指针赋值 p_match_num=match_num; p_put_num=put_num; p_player=player; p_player_now=player_first; //函数的定义 void match(int* p_player, int* p_match_num,int* p_put_num,char* p_player_now); //火柴拿走数目函数 //游戏开始 cout请输入玩家1的名字:; gets(player_first); cout请输入玩家2的名字:; gets(player_second); //玩家开局顺序的选择 cout玩家“player_first”选择拿火柴顺序(“F(First)/S(Second)”); cinjudge; if(judge==s) { strcpy(temp,player_first); strcpy(player_first,player_second); strcpy(player_second,temp); } cout玩家“player_first”先开始endl; coutendl; //火柴的拿取 while(1) { if(player%2==0) p_player_now=player_first; else p_player_now=player_second; match(p_player,p_match_num,p_put_num,p_player_now); match_num=match_num-put_num; if(match_num==0) { cout玩家“p_player_now”您输了!endl; break; } } } void match(int* p_player,int* p_match_num,int* p_put_num,char* p_player_now) { cout请“p_player_now”输入准备拿走火柴的数目:; cin*p_put_num; while(*p_put_num!=1 *p_put_num!=2 *p_put_num!=3 || *p_match_num-*p_put_num0) { if(*p_put_num!=1 *p_put_num!=2 *p_put_num!=3) { cout您输入的数值不合法,拿走的火柴数目只能是 1 或 2 或 3,请重新输入:; cin*p_put_num; } if(*p_match_num-*p_put_num0) { cout您输入的数值大于剩余火柴数目,请重新输入:; cin*p_put_num; } } cout您拿走的火柴数目是: *p_put_numendl; cout剩余火柴数目是: *p_match_num-*p_put_numendl; coutendl; (*p_player)++; }

文档评论(0)

xy88118 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档