• 大小: 10.2MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-31
  • 语言: C/C++
  • 标签: 21点游戏  

资源简介

21点是一个广受欢迎的游戏,这里用纯C++实现了21点游戏!

资源截图

代码片段和文件信息

#include “BlackJack.h“

BlackJack::BlackJack()
{
m_nCount = 0;
m_arrBanker.clear();
m_arrPlayer.clear();

Init();
}

BlackJack::~BlackJack()
{
m_nCount = 0;
m_arrBanker.clear();
m_arrPlayer.clear();
}

void BlackJack::FirstDeal()
{
BankerDeal();

PlayerDeal();

BankerDeal();

PlayerDeal();
}

void BlackJack::Shuffle()
{
m_nCount = 0;

srand(static_cast(time(NULL)));

int a = 0;

int b = 0;

for (int i = 0; i < 1000; ++i)
{
a = rand() % 52;

b = rand() % 52;

Swap(a b);
}
}

void BlackJack::PlayerDeal()
{
if (m_nCount >= 52)
{
m_nCount = 0;
m_arrBanker.clear();
m_arrPlayer.clear();

Init();

Shuffle();

m_arrPlayer.push_back(m_arrPoker[m_nCount]);
}
else
{
m_arrPlayer.push_back(m_arrPoker[m_nCount++]);
}
}

void BlackJack::BankerDeal() 
{
if (m_nCount >= 52)
{
m_nCount = 0;
m_arrBanker.clear();
m_arrPlayer.clear();

Init();

Shuffle();

m_arrPlayer.push_back(m_arrPoker[m_nCount]);
}
else
{
m_arrBanker.push_back(m_arrPoker[m_nCount++]);
}
}

bool BlackJack::IsDead(vector arrCard) const
{
if (GetToteNumber(arrCard) > 21)
{
return true;
}

return false;
}

bool BlackJack::PlayerWanted()
{
char c;

do 
{
cout << “要抓牌吗 ? (Y/N) : “;
cin >> c;
cout << endl;
} while (!(c == ‘y‘ || c == ‘Y‘ || c == ‘n‘ || c == ‘N‘));

if (c == ‘y‘ || c == ‘Y‘)
{
return true;
}
else
{
return false;
}
}

bool BlackJack::BankerWanted()
{
if (!IsDead(m_arrBanker) &&
!IsDead(m_arrPlayer) &&
GetToteNumber(m_arrBanker) < GetToteNumber(m_arrPlayer))
{
return true;
}
else if (
!IsDead(m_arrBanker) && 
!IsDead(m_arrPlayer) &&
GetToteNumber(m_arrBanker) == GetToteNumber(m_arrPlayer) &&
GetToteNumber(m_arrBanker) >= 20)
{
return false;
}
else 
{
return false;
}
}

bool BlackJack::Replay()
{
m_arrBanker.clear();
m_arrPlayer.clear();
char c;

do 
{
cout << “是否在来一局 ? (Y/N) : “;
cin >> c;
cout << endl;

} while (c != ‘y‘ && c != ‘Y‘ && c != ‘n‘ && c != ‘N‘);

if (c == ‘y‘ || c == ‘Y‘)
{
return true;
}
else
{
return false;
}
}

void BlackJack::PrintBanker() const
{
cout << “庄家的牌是:“ << endl;

for (unsigned int i = 0; i < m_arrBanker.size(); ++i) 
{
if (i)
{
cout <<  ‘ ‘ << m_arrBanker[i].nNumber;
}
else
{
cout << m_arrBanker[i].nNumber;
}
}

cout << endl;
cout << “庄家的总点数为:“ << endl;
cout << GetToteNumber(m_arrBanker) << endl;
cout << endl;
}

void BlackJack::PrintPlayer() const
{
cout << “玩家的牌是:“ << endl;

for (unsigned int i = 0; i < m_arrPlayer.size(); ++i) 
{
if (i)
{
cout << ‘ ‘<< m_arrPlayer[i].nNumber;
}
else
{
cout << m_arrPlayer[i].nNumber;
}
}

cout << endl;
cout << “玩家的总点数为: “ << endl;
cout << GetToteNumber(m_arrPlayer)< cout <<  endl;
}

void BlackJack::Result()
{
i

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-10-27 15:54  BlackJack\
     目录           0  2013-10-17 10:55  BlackJack\BlackJack\
     文件    29577216  2013-10-27 15:54  BlackJack\BlackJack.sdf
     文件         894  2013-10-14 15:17  BlackJack\BlackJack.sln
     文件       18432  2013-10-27 15:54  BlackJack\BlackJack.suo
     文件        4690  2013-10-27 15:49  BlackJack\BlackJack\BlackJack.cpp
     文件        4087  2013-10-27 15:26  BlackJack\BlackJack\BlackJack.h
     文件        4095  2013-10-14 21:10  BlackJack\BlackJack\BlackJack.vcxproj
     文件        1223  2013-10-14 21:10  BlackJack\BlackJack\BlackJack.vcxproj.filters
     文件         143  2013-10-14 15:16  BlackJack\BlackJack\BlackJack.vcxproj.user
     目录           0  2013-10-27 15:47  BlackJack\BlackJack\Debug\
     文件         406  2013-10-14 21:24  BlackJack\BlackJack\Debug\BlackJack.exe.embed.manifest
     文件         472  2013-10-27 15:45  BlackJack\BlackJack\Debug\BlackJack.exe.embed.manifest.res
     文件         381  2013-10-27 15:46  BlackJack\BlackJack\Debug\BlackJack.exe.intermediate.manifest
     文件          60  2013-10-27 15:47  BlackJack\BlackJack\Debug\BlackJack.lastbuildstate
     文件         871  2013-10-27 15:47  BlackJack\BlackJack\Debug\BlackJack.log
     文件      322119  2013-10-27 15:46  BlackJack\BlackJack\Debug\BlackJack.obj
     文件     1179648  2013-10-14 21:08  BlackJack\BlackJack\Debug\BlackJack.pch
     文件         208  2013-10-14 21:22  BlackJack\BlackJack\Debug\BlackJack_manifest.rc
     文件        3408  2013-10-27 15:46  BlackJack\BlackJack\Debug\cl.command.1.tlog
     文件       97396  2013-10-27 15:46  BlackJack\BlackJack\Debug\CL.read.1.tlog
     文件        2630  2013-10-27 15:46  BlackJack\BlackJack\Debug\CL.write.1.tlog
     文件           2  2013-10-27 15:46  BlackJack\BlackJack\Debug\link-cvtres.read.1.tlog
     文件           2  2013-10-27 15:46  BlackJack\BlackJack\Debug\link-cvtres.write.1.tlog
     文件           2  2013-10-27 15:46  BlackJack\BlackJack\Debug\link.3040-cvtres.read.1.tlog
     文件           2  2013-10-27 15:46  BlackJack\BlackJack\Debug\link.3040-cvtres.write.1.tlog
     文件           2  2013-10-27 15:46  BlackJack\BlackJack\Debug\link.3040.read.1.tlog
     文件           2  2013-10-27 15:46  BlackJack\BlackJack\Debug\link.3040.write.1.tlog
     文件           2  2013-10-27 15:46  BlackJack\BlackJack\Debug\link.4216-cvtres.read.1.tlog
     文件           2  2013-10-27 15:46  BlackJack\BlackJack\Debug\link.4216-cvtres.write.1.tlog
     文件           2  2013-10-27 15:46  BlackJack\BlackJack\Debug\link.4216.read.1.tlog
............此处省略32个文件信息

评论

共有 条评论