人机对战取柴游戏源代码.docVIP

  • 8
  • 0
  • 约1.18千字
  • 约 5页
  • 2016-12-03 发布于贵州
  • 举报
人机对战取柴游戏源代码

# include iostream.h # include time.h # include stdlib.h int man(int m); int cmp(int m); static int quanju=0; void main() { int sum=21; xz: cout1:先手\t2:后手\n请正确输入:flush; int i; cini; switch(i) { case 1:{ while(sum!=0) { sum=man(sum); if(sum==0) break; sum=cmp(sum); } break; } case 2: {quanju++; while(sum!=0) { sum=cmp(sum); if(sum==0) break; sum=man(sum); } break; } default: { cout您的输入有误,请正确输入endl; system(pause); system(cls); goto xz ; } } cout游戏结束...endl; system(pause); } int man(int m) { int qude=0; xx: cout剩余m根火柴endl; cout请输入取得的火柴数范围(1--4):flush; cinqude; if(qude4||qude1||qudem) { cout输入错误,请重新输入:flush; goto xx; } cout你取得了qude根火柴endl; if (m==qude) { cout你输了...endl; system(pause); } return(m-qude); } int cmp(int m) { srand(time(0)); cout剩余m根火柴endl; int qude; if (quanju==0) { qude=(m-1)%5; } else {x: qude=rand()%4+1; if(qudem)goto x; } cout电脑取了qude根火柴endl; if(m-qude==0) { cout电脑输了...; system(pause); } return(m-qude); }

文档评论(0)

1亿VIP精品文档

相关文档