对抗游戏程序设计.docVIP

  • 39
  • 0
  • 约4.18千字
  • 约 5页
  • 2017-01-28 发布于重庆
  • 举报
对抗游戏程序设计

C++程序设计之对抗游戏 #includeiostream.h #includestdlib.h #includetime.h class War { int player,comp; //玩家,电脑的两张牌 static int Score; //player的赌资 static int nWin,nLost,nDraw; //赢,输,平的局数 static int Loop; //游戏进行的局数 public: War(); int PLAYER(); //返回私有成员player的的值 int COMP(); //返回私有成员comp的的值 void SetCard(); //随机发出两张牌 void Show(int a);//显示牌点 void Judge(int);//计算机可根据自己的牌面判断是否加注 static int Scores(int); void friend Compare1(War,War,int,int);//判断牌面的大小,得出结果同时通过d返回输或赢的分数 void ShowResult(int);//得到并显示在一局游戏中玩家得到的分数以及总计的分数 void TJ();//游戏结束后统计出最终的结果 }; int War::Score=26,War::nWin=0,War::nLost=0,War::nDraw=0,War::Loop=0; War::War() {player,comp=0;} int War::PLAYER() { return player; } int War::COMP() { return comp; } void War::SetCard() { player=rand()%13+2; comp=rand()%13+2; } void War::Show(int a) { int pai; if(a==1)pai=player; else if(a==2)pai=comp; switch(pai) { case 14:coutA;break; case 13:coutK;break; case 12:coutQ;break; case 11:coutJ;break; default:coutpai; } cout\n; } void War::Judge(inty) { if(player=comp) { switch(comp) { case 10: case 11: case 12: case 13: case 14: cout电脑选择加注\n; cout加注金额:2;y=2;cout\n;break; default:cout电脑选择加注\n; cout加注金额:1;y=1;cout\n;break; } } else {cout电脑也选择退出\n;y=0;} } int War::Scores(int d=0) { Score+=d; return Score; } void Compare(WarA,WarB,intd,int y) // 判断牌面的大小,同时通过d返回输或赢的分数 { cout######统计######\n; switch(y) {case 0: { if(A.PLAYER()A.COMP()){cout恭喜你^^,玩家的牌大!\n;d=1;} else if(A.PLAYER()==A.COMP())cout双方势均力敌!\n; else {cout555,电脑的牌大!\n;d=-1;} break; } default: { int i,j,m,n; i=A.PLAYER()==B.PLAYER(); j=A.COMP()==B.COMP(); m=(A.PLAYER()+B.PLAYER())(A.COMP()+B.COMP()); n=(A.PLAYER()+B.PLAYER())(A.COMP()+B.COMP()); if(ij) { if(A.PLAYER()A.COMP()){cout恭喜你^^,玩家的对子大!\n;d=y+1;} else if(A.PLAYER()A.COMP()){cout555,电脑的对子大!\n;d=-y-1;} else cout双方势均力敌!\n;} else if(i==1j==0) {cout恭喜你^^,玩家是对子!\n;d=y+1;}

文档评论(0)

1亿VIP精品文档

相关文档