教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 小学教育 >

模拟21点扑克牌游戏(C++课设)(2)

来源:网络收集 时间:2026-09-11
导读: void Game::Draw()//平局 { nDraw++; nMoney+=nGamble; cout平局牌面endl; DisplayPip(); if(GetPip()21) cout暴了!endl; else cout牌面点数:GetPip()endl; cout赌本:$nMoney 赢了nWin次 输了 nLose次 平局nDraw次

void Game::Draw()//平局 { nDraw++;

nMoney+=nGamble; cout<<"平局牌面"<<endl; DisplayPip(); if(GetPip()>21) cout<<"暴了!"<<endl; else

cout<<"牌面点数:"<<GetPip()<<endl;

cout<<"赌本:$"<<nMoney<<" 赢了"<<nWin<<"次 "<<"输了" <<nLose<<"次 "<<"平局"<<nDraw<<"次 "<<endl; cout<<"\n\n\n"; }

void Game::DisplayPip(int n)//除了除了前两张牌,一次全部显示牌面点数(针对计算机牌的显示) {

cout<<"[*]"<<"\t"; cout<<"[*]"<<"\t";

for(int i=2;i<nNumber;i++) cout<<naPip[i]<<"\t"; cout<<endl; }

void Game::error1(char a)// {

do{

cin>>a;

if((a=='y')||(a=='Y')||(a=='N')||(a=='n'))

goto sta;

cout<<"请确定你输入的"<<a<<"是否为“Y/N”。否则请重新输入“Y/N”"<<endl;

}while(cin.good());

}

void Game::error2(int a)// { do {

while(cin.fail()) {

cout<<"你输入的赌金必须为正整数。否则请重新输入:"<<endl; cin.clear();

cin.ignore(1024,'\n'); cin>>a; } cin>>a; sta: chChoice=a;

}while(a<0); nDallor=a; }

void Game::addGamble()//增加赌注 { }

void Game::Judge()// {

cout<<endl;

if((cpu.GetPip()>21&&player.GetPip()>21)||cpu.GetPip()==player.GetPip()) {

cout<<"\n\n平局\n!"; cout<<"\t\t计算机数据:\t"; cpu.DisplayPip();

cout<<"牌面点数:"<<cpu.GetPip()<<endl;

int a;

player.error1(chChoice);

if(chChoice=='y'||chChoice=='Y') { }

player.cls();

cout<<"\n\n\n\n\t你还有赌本:\t"<<player.getMoney()<<endl; cout<<"\t请输入增加的赌金:\t"; do {

player.error2(nDallor); a=player.setGamble(nDallor); }while(a);

cout<<"\n\t\t您的数据\t"; player.Draw(); cout<<endl; }

else if((cpu.GetPip()>21||(player.GetPip())>cpu.GetPip()&&player.GetPip()<=21)) {

cout<<"\n\n恭喜您,您赢了\n!"; cout<<"\t\t计算机数据:\t"; cpu.DisplayPip();

cout<<"牌面点数:"<<cpu.GetPip()<<endl; cout<<"\n\t\t您的数据\t"; player.Win(); cout<<endl; } else {

cout<<"\n\n很遗憾,您输了\n!"; cout<<"\t\t计算机数据:\t"; cpu.DisplayPip();

cout<<"牌面点数:"<<cpu.GetPip()<<endl; cout<<"\n\t\t您的数据\t"; player.Lose(); cout<<endl; } }

void Game::cls()// {

cout<<"请输入任意键继续"<<endl; getchar(); system("cls"); }

void Game::playTurn()// {

int blCpu=1,blPlayer=1; cpu.FirstPlayTwo(); do {

player.TurnPlay();

cout<<"\t您要的这张牌,牌点是\t"<<player.GetCurrentCard()<<endl; cout<<"您的牌点为:\t"<<endl; player.DisplayPip();

cout<<"计算机的牌点为"<<endl; cpu.DisplayPip(1);

cout<<"您的牌面点数是"<<player.GetPip()<<endl; cout<<"\n\t您一共下注:"<<nGamble;

cout<<"\n请问是否要增加赌注,输入“Y”增加,输入“N”不增加"<<endl; player.addGamble(); if(blPlayer) { { {

cpu.TurnPlay();

cout<<"\t计算机要牌,牌点是:\t"<<cpu.GetCurrentCard()<<endl; blCpu=0; } }

} else blCpu=0;

if(cpu.GetPip()<18&&cpu.GetNumber()<5) if(nNumber>5) { }

cout<<"\n\n\n\t您是否继续要牌?(Y/N)"<<endl; player.error1(chChoice); system("cls");

if((chChoice=='Y'||chChoice=='y')) { } else { }

cout<<"\n\t你放弃了该轮抽牌"; nNumber--;blCpu=1; if(nNumber>2) { }

cout<<"\n\t\t你的点数爆了哦~"<<endl; blPlayer=0;blCpu=0; blCpu=1; blCpu=0; else

if(player.GetPip()>21) blPlayer=0; else

while(blCpu)

}while((blCpu)||(blPlayer)); player.Judge(); Sleep(2000); game.StoreUser(); }

void Game::showCpu()// { }

int Game::Movegame()// {

srand((unsigned)time(NULL));

cout<<"\n\n\n\t\t\t是否开始游戏 (Y/N)?\n"; player.error1(chChoice);

while(chChoice=='Y'||chChoice=='y') { do {

cout<<"您现在有的赌本:"<<player.getMoney()<<endl; cout<<"请下注:(赌注不能超过赌本)"<<endl; player.error2(nDallor);

blLogic=player.setGamble(nDallor); }while(blLogic);

player.playTurn(); //玩一局 player.cls();

player.DisplayInfo();//显示赌完之后的结果。 cout<<"\n\n\n\t\t\t是否继续玩游戏(Y/N)"<<endl; player.error1(chChoice); nNumber=0;//开始没有发牌 for(int i=0;i<5;i++) naPip[i]=0; //五张牌全部为0 nGamble=0; nPip=0; system("cls"); } }

Display::Display()// {

game.Begin(); return 0; temp=nNumber; nNumber=2; cpu.DisplayPip(); nNumber=temp;

}

int Display::nMoney()// {return Money;}

void Display::DisplayMenu()//0.进入运行菜单界面 {

cout<<"\n\n\t\t∷∷∷∷∷∷∷∷∷∷∷∷∷∷∷∷∷∷∷∷∷∷∷\n"; cout<<"\t\t∷ ∷\n"; cout<<"\t\t∷ ∷\n"; cout<<"\t\t∷ ∷\n"; cout<<"\t\t∷━━━━>欢迎进入21点游戏世界!<━━━━∷\n"; cout<<"\t\t∷ ∷\n"; cout<<"\t\t∷ …… 此处隐藏:2371字,全部文档内容请下载后查看。喜欢就下载吧 ……

模拟21点扑克牌游戏(C++课设)(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/43761.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)