C++课程设计---21点纸牌游戏程序资料

上传人:w****i 文档编号:92361742 上传时间:2019-07-09 格式:DOC 页数:11 大小:76KB
返回 下载 相关 举报
C++课程设计---21点纸牌游戏程序资料_第1页
第1页 / 共11页
C++课程设计---21点纸牌游戏程序资料_第2页
第2页 / 共11页
C++课程设计---21点纸牌游戏程序资料_第3页
第3页 / 共11页
C++课程设计---21点纸牌游戏程序资料_第4页
第4页 / 共11页
C++课程设计---21点纸牌游戏程序资料_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《C++课程设计---21点纸牌游戏程序资料》由会员分享,可在线阅读,更多相关《C++课程设计---21点纸牌游戏程序资料(11页珍藏版)》请在金锄头文库上搜索。

1、#include#include#include#include#include#includeclass Gamepublic: 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

2、(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: in

3、t 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 ) milli );/=void Game: pause() coutPress Any Key To Continueendl; getch();/=int Game:GetInt(int L=0,int H=100) int ent; coutPl

4、ease Enter A Number Between L and Hent; while(entH) coutErrorendl; coutValue must be between L and Hent; 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() coutttt *欢迎使用21点游戏软件*endl; coutendl; coutendl; co

5、utttt 游戏规则: endl; coutendl;coutttt :每轮游戏你最多只可以有5张牌。endl;coutttt :如果你的点数超过21将输掉这轮游戏。endl;coutttt :高级玩家可以看下一张牌。endl;coutttt :胜利者将得到2倍的注金。endl;coutttt :庄家牌点数不会小于16点。endl;coutttt;pause();/-void Game:BET()/下注system(cls);/执行系统命令clscoutttt你的资本:$moneyendl;coutbet; if(bet=0) cout对不起,输入有误; exit(0); if(money-b

6、et0) cout对不起,你没有那么多钱!:(; /sees if your broke exit(0);money-=bet;/-void Game:deal()/发前两张牌int playercard1,playercard2,cpucard1,cpucard2;float ccard1,ccard2,pcard2,pcard1;playerturns=2;/开始给玩家发两张牌cputurns=2;/庄家也发两张牌playercard1=random(13,1);/在1到13中找出一个随机数coutnttt正在洗牌,请稍候.endl;wait(500);playercard2=random

7、(13,1); wait(500); coutplayercard1; coutplayercard210)/大于十的牌点数全部置为0.5pcard1=0.5,player=pcard1,playercard1=0; if(playercard210)/大于十的牌点数全部置为0.5pcard2=0.5,player+=pcard2,playercard2=0; player+=playercard1+playercard2;/总点数 coutttt你现在的点数为:playerendl; coutendl;cpucard1=random(13,1);/调用函数 wait(350);cpucard

8、2=random(13,1);/调用函数 coutttt庄家有一张 cpucard1 为正面牌!endl; cout* cpucard110)/大于十的牌点数全部置为0.5ccard1=0.5,cpu=ccard1,cpucard1=0;if(cpucard210)/大于十的牌点数全部置为0.5ccard2=0.5,cpu+=ccard2,cpucard2=0; cpu+=cpucard1+cpucard2;/总的点数 coutendl; /-void Game:run(Game &c2)/进行异常处理 char ans; do int m=0;system(cls);/执行系统命令clsc2

9、.clean();/进行新的一轮游戏! c2.check();/检验是否爆庄 c2.BET(); /进行下注 c2.deal(); /洗牌do if(playerturns=5)cout已达最大牌数,不能再要牌了,请按任意键看你的总的点数!endl; do try /开始捕获异常处理 coutttt你愿意继续吗?(hit愿意,stay否):; m=0; /可以没有的!但把下面的if语句改一下就必须有了coutans;cin.ignore(20,n);/把输入行中的其余字符取空,以便后面的输入从新一轮开始 if(ans=h)|(ans=H)|(ans=s)|(ans=S) break;else throw ans;/产生异常事件 catch(char)/开始处理异常机制 cout你的输入有误!:(请重新输入endl;m=1;catch(.)cout你的输入有误!:(请重新输入endl

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号