程序设计21点扑克牌游戏文档格式.docx

上传人:b****5 文档编号:17313539 上传时间:2022-12-01 格式:DOCX 页数:14 大小:177.78KB
下载 相关 举报
程序设计21点扑克牌游戏文档格式.docx_第1页
第1页 / 共14页
程序设计21点扑克牌游戏文档格式.docx_第2页
第2页 / 共14页
程序设计21点扑克牌游戏文档格式.docx_第3页
第3页 / 共14页
程序设计21点扑克牌游戏文档格式.docx_第4页
第4页 / 共14页
程序设计21点扑克牌游戏文档格式.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

程序设计21点扑克牌游戏文档格式.docx

《程序设计21点扑克牌游戏文档格式.docx》由会员分享,可在线阅读,更多相关《程序设计21点扑克牌游戏文档格式.docx(14页珍藏版)》请在冰豆网上搜索。

程序设计21点扑克牌游戏文档格式.docx

Private:

IntmPip[5];

(一共有5张牌)

IntmNumber;

(牌的张数)

IntmDollar;

(一共有多少钱)

IntmGamble;

(赌注)

IntmWin;

(赢得局数)

IntmLose;

(输的局数)

IntmDraw;

(平的局数)

Public:

CCard();

(构造函数初始化)

VoidFistplayTwo();

(第一次出两张牌)

IntGetNumber();

(返回牌的数目)

IntGetPip();

(显示牌的总点数)

VoidDisplayPip();

(一次显示牌的点数)

VoidDisplayPip(int);

(除第一张牌,一次显示牌的点数)

VoidTurnplay();

(出第一张牌)

VoidWin();

(赢了多少钱)

VoidLose();

(输了)

VoidDraw();

(平了)

IntSetGamble(int);

(设置赌注)

IntGetMoney();

(返回钱数)

VoidDisplayInfo();

(打印必要信息)

IntGetCurrentCard();

(返回当前牌)

四、系统的运行结果与分析

主要是开始运行的界面:

当赌注下多了:

玩完游戏:

附录:

系统的源程序

#include<

cstdlib>

iostream>

ctime>

usingnamespacestd;

classCCard

{

private:

intnaPip[5];

intnNumber;

intnDollar;

intnGamble;

intnWin;

intnLose;

intnDraw;

public:

CCard();

voidFirstPlayTwo();

intGetNumber();

intGetPip();

voidDisplayPip();

voidDisplayPip(int);

voidTurnPlay();

voidWin();

voidLose();

voidDraw();

intSetGamble(int);

intGetMoney();

voidDisplayInfo();

intGetCurrentCard();

};

CCard:

:

CCard()

nNumber=0;

nDollar=100;

for(inti=0;

i<

5;

i++)

naPip[i]=0;

nGamble=0;

nWin=nLose=nDraw=0;

}

intCCard:

GetMoney(void)

{returnnDollar;

voidCCard:

DisplayInfo()

{cout<

<

"

您一共玩了"

nWin+nLose+nDraw<

局,"

赢了"

nWin<

输了"

nLose<

局,"

平局"

nDraw<

次。

\n"

;

cout<

你的赌本共计有$"

nDollar<

SetGamble(intgamble)

{if(nDollar-gamble<

0)

return-1;

if(gamble<

{if(nDollar-20<

nGamble=20;

else

nGamble=gamble;

nDollar-=nGamble;

return0;

FirstPlayTwo()

{naPip[0]=rand()%13+1;

naPip[1]=rand()%13+1;

nNumber=2;

GetCurrentCard()

{returnnaPip[nNumber-1];

GetNumber()

{returnnNumber;

GetPip()

{intnPip=0;

for(inti=0;

nNumber;

if(naPip[i]>

=10)

nPip+=10;

else

nPip+=naPip[i];

returnnPip;

DisplayPip()

{for(inti=0;

naPip[i]<

'

\t'

endl;

TurnPlay()

{nNumber++;

naPip[nNumber-1]=rand()%13+1;

Win()

{cout<

赢家牌面:

DisplayPip();

牌面点数:

"

GetPip()<

nDollar=nDollar+2*nGamble;

nWin++;

赌本:

$"

赢了"

次"

次"

endl<

Lose()

{nLose++;

输家牌面:

if(GetPip()>

21)

暴了!

$"

Draw()

{nDraw++;

nDollar+=nGamble;

cout<

平局牌面:

DisplayPip(intn)

[*]"

for(inti=1;

voidDisplayRule(void)

\t欢迎进入曹开明的21点游戏世界!

\n\n"

\t游戏规则:

\t1.玩家最多可以要5张牌;

\t2.如果牌点的总数超过21点则暴点,自动判输;

\t3.赢家可得双倍赌注;

\t4.计算机方在牌点大于等于16时不再要牌。

祝您好运!

voidJudge(CCard&

cpu,CCard&

player)

if((cpu.GetPip()>

21&

&

player.GetPip()>

21)||cpu.GetPip()==player.GetPip())

\n\n平局!

计算机数据:

\t"

cpu.DisplayPip();

cpu.GetPip()<

\n您的数据:

player.Draw();

elseif((cpu.GetPip()>

21)||(player.GetPip()>

cpu.GetPip()&

player.GetPip()<

=21))

\n\n恭喜您,您赢了!

player.Win();

\n\n很遗憾,您输了!

player.Lose();

voidPlayTurn(CCard&

{charchChoice;

intblCpu=1,blPlayer=1;

cpu.FirstPlayTwo();

player.FirstPlayTwo();

do

您的牌点为:

player.DisplayPip();

计算机的牌点为:

cpu.DisplayPip

(1);

您的牌面点数是:

if(blPlayer)

\n\n您是否继续要牌(Y/N)?

cin>

>

chChoice;

if((chChoice=='

Y'

||chChoice=='

y'

))

{if(player.GetNumber()<

5)

{player.TurnPlay();

您要的这张牌是:

player.GetCurrentCard()<

if(player.GetPip()>

blPlayer=0;

对不起,您已经要了5张牌,不能再要牌了!

N'

n'

if(cpu.GetPip()<

16&

cpu.GetNumber()<

{cpu.TurnPlay();

计算机要牌,牌点是:

cpu.GetCurrentCard()<

blCpu=0;

if(blCpu&

player.GetNumber()<

5&

blPlayer=1;

}while(blCpu||blPlayer);

Judge(cpu,player);

return;

intmain(void)

srand((unsigned)time(NULL));

CCardcpu,player;

intblLogic;

intnMoney;

DisplayRule();

charchChoice;

cout<

是否现在开始游戏(Y/N)?

cin>

while(chChoice=='

{do

{cout<

您现在有赌本:

player.GetMoney();

\n请下注(赌注不能超过赌本):

nMoney;

blLogic=player.SetGamble(nMoney);

if(blLogic)

cout<

您的赌本不够,请重新下注!

}while(blLogic);

PlayTurn(cpu,player);

是否继续21点游戏(Y/N)?

}

player.DisplayInfo();

欢迎再次使用本程序!

\n\n\n"

return0;

自评

意见

做这个课程设计不但让我在C++编程方面的能力有很大的提高,更让我明白了做一个项目的困难。

这个项目做了两个星期,付出很多,收获很多。

签名:

年 月  日

等级

A

指导

教师

评定

年月日

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 预防医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1