C++课程设计报告---21点纸牌游戏程序.docx
C+课程设计报告-21点纸牌游戏程序 #include #include #include #include #include #include class Game public: Game() win=0,lose=0,draw=0,playerturns=0,cputurns=0,money=100,bet=0; player=0,cpu=0; char answer1="123456" strcpy(answer,answer1); char answer2="654321" strcpy(daan,answer2); ; void rules();/显示规则 void BET(); /下注 void deal();/交易 void run(Game &);/进行异常处理 void hit1();/拿下一牌 void hit2();/确保庄家不会爆庄并且点数大于16 void print();/打印出最后结果 void results();/最后的胜利结果 void check();/检查是否爆庄 Game operator=(Game &d);/运算符重载 void replay(char &ans);/是否进行新一轮的游戏 void clean();/清屏 void wait(int); void pause(); int GetInt(int,int); int random(long,long); private: int playerturns,cputurns,money; int win,lose,draw,bet; float player,cpu; char answer7; char daan7; ; /- void Game:wait(int milli) clock_t start; start=clock(); while( ( clock()-start ) >ent; while(entH) cout>ent; return(ent); /= int Game:random(long hi,long lo)/随机抽牌 int ran; srand(unsigned)time(NULL); ran=rand()%(hi-(lo-1)+lo; return(ran); /= void Game:rules() cout>bet; if(bet10)/大于十的牌点数全部置为0.5 pcard1=0.5,player=pcard1,playercard1=0; if(playercard2>10)/大于十的牌点数全部置为0.5 pcard2=0.5,player+=pcard2,playercard2=0; player+=playercard1+playercard2;/总点数 cout10)/大于十的牌点数全部置为0.5 ccard1=0.5,cpu=ccard1,cpucard1=0; if(cpucard2>10)/大于十的牌点数全部置为0.5 ccard2=0.5,cpu+=ccard2,cpucard2=0; cpu+=cpucard1+cpucard2;/总的点数 cout>ans; cin.ignore(20,'n');/把输入行中的其余字符取空,以便后面的输入从新一轮开始 if(ans='h')|(ans='H')|(ans='s')|(ans='S') break; else throw ans;/产生异常事件 catch(char)/开始处理异常机制 cout5) cout>ans; label1: if(ans='y'|ans='Y') cin.ignore(20,'n');/把输入行中的其余字符取空,以便后面的输入从新一路轮开始 cout>ans; if(ans='y'|ans='Y') cout>bet1; if(money-bet110) card=0.5; cout>card; if(card>10) card=0.5; cout>ans; if(ans='y'|ans='Y') goto label1; else cout10) cards=0.5,card=0; ; player+=cards+card; cout10) cards=0.5,card=0; ; cpu=cpu+cards+card; if(cpu>21) if(cards=0)cpu-=copycard;/当card小于10但总数大于21时执行 else cpu-=cards; /当card大于10且点数大于21时执行 cout<<"ttt总点数为:"<<cpu<<endl; if(cpu<16)/确保庄家点数大于等于16 cpu=16; cout<<"ttt总点数是:"<<cpu<<endl; /- void Game:results()/找出赢家 if(cpu=player) cout<<"ttt点数一样,你们平了!"<<endl; draw+;