二十一点游戏
C++ Blackjack Gameplay
好吧,我对编程真的很陌生,我正试图为我正在上的课制作一款21点游戏。到目前为止,我已经掌握了所有内容的要点,但当涉及到实际的游戏内容部分时,我遇到了麻烦。当我看着自己的代码时,我不知道为什么我的游戏不能正常运行。我希望这是一个比我看到的更容易解决的问题,因为我经常错过一些小事情。
for(;;)
{
cout << "1)Bet, 2)Hit or 3)Stay?n";
cin >> ans;
if(ans == 1)
{
}
if(ans == 2) // Hit
{
Console::Clear();
cout << "Your Handn";
Player.AddCard(Deck.Draw());
cout << "nHand Value: " << Player.HandValue() << "n";
Player.Show();
if(Player.HandValue() > 21)
{
cout << "You Busted man...Sorry :/nn"
//<< "Dealer's Handnn";
//Dealer.Show();
}
else if(Player.HandValue() == 21)
{
cout << "You've Won Your Freedom! :D";
}
while( Dealer.HandValue() <= 17)
{
Dealer.AddCard(Deck.Draw());
Dealer.Show(1);
if(Dealer.HandValue() > 21)
{
cout << "Dealer Busted man...You Win! :Dn"
<< "nDealer's Handn";
Dealer.Show();
}
else if(Dealer.HandValue() == 21)
{
cout << "Dealer Wins...Your Soul! >:Dn"
}
}
if(Player.HandValue() > Dealer.HandValue())
{
cout << "Your Hand Beats Dealer's...You Win!! :Dn"
}
else if(Player.HandValue() < Dealer.HandValue() && Dealer.HandValue() > 17 && Player.HandValue() > 17)
{
cout << "Dealer's Hand Wins...Sorry :/n"
}
cin.ignore(INT_MAX, 'n');
cin.clear();
cin.ignore(INT_MAX, 'n');
}
break;
if(ans == 3) // Stay
{
Console::Clear();
cout << "Your Handn";
cout << "nHand Value: " << Player.HandValue() << "n";
Player.Show();
if(Player.HandValue() > 21)
{
cout << "You Busted man...Sorry :/n"
}
else if(Player.HandValue() == 21)
{
cout << "You've Won Your Freedom! :Dn";
cout << "nn";
cout << "Dealer's Handn";
Dealer.Show();
}
while(Dealer.HandValue() < 17)
{
Dealer.AddCard(Deck.Draw());
Dealer.Show(1);
if(Dealer.HandValue() > 21)
{
cout << "Dealer Busted man...You Win! :Dn"
}
else if(Dealer.HandValue() == 21)
{
cout << "Dealer Wins...Your Soul! >:Dn"
}
}
if(Player.HandValue() > Dealer.HandValue())
{
cout << "Your Hand Beats Dealer's...You Win!! :Dn"
}
else if(Player.HandValue() < Dealer.HandValue() && Dealer.HandValue() > 17 && Player.HandValue() > 17)
{
cout << "Dealer's Hand Wins...Sorry :/n;
cin.ignore(INT_MAX, 'n');
}
cin.clear();
cin.ignore(INT_MAX, 'n');
}
if(ans == 4)
{
exit(0);
}
system("pause");
}
不要介意if(ans == 1),我把它保存在我的投注代码中。这段代码在很大程度上做了我需要它做的事情。我还没有查a的东西。我们有一个用于牌组的堆栈,这就是Draw()和AddCard()提取的内容。任何帮助是非常感激的,并与评论温柔,我是新的。:)
您的问题很可能源于没有处理某些情况。如果players.HandValue() == dealers.HandValue(),您的代码将通过测试。同时也不能保证玩家拥有<17(你在你的测试中依赖)。
我建议加入else{}子句,打印玩家和发牌手值和调试信息,看看你错过了什么条件,然后你可以尝试找出原因。
if(Player.HandValue() > Dealer.HandValue())
{
cout << "Your Hand Beats Dealer's...You Win!! :Dn";
}
else if(Player.HandValue() < Dealer.HandValue() && Dealer.HandValue() > 17 && Player.HandValue() > 17)
{
cout << "Dealer's Hand Wins...Sorry :/n";
}
else
{
cout << "Unhandled case! Player handvalue: " << Player.HandValue()
<< " dealer handvalue: " << Dealer.HandValue() << 'n';
}
HTH
相关文章:
- 如何在openssl-ecc中获取十六进制格式的私钥
- 如何将包含epoch时间的十六进制字符串转换为time_t
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- 如何将一个ostringstream十六进制字符串字符对转换为单个unit8t等价的二进制值
- 如何在C++中用std::cout正确显示带十六进制的字符串文本
- 在C++游戏中与库存系统作斗争
- 通过错误处理,在C++中可靠地获得用户十六进制输入
- 换位表导致测试失败(但在游戏中运行良好)
- 为什么mpfr_printf与十六进制浮点(%a转换说明符)的printf不同
- Craps游戏问题,忽略if语句
- 矢量下标超出SFML游戏中的范围
- 我是 c++ 的新手.学习基本知识后,我想做井字游戏.对于印刷板,我在下面写代码,但它显示错误
- 在 std::无符号字符的向量处存储 int 的十六进制表示形式
- 指向存储在字符串 c++ 中的十六进制
- 我正在制作一个二十一点程序。我目前有两个问题
- 弄清楚如何修复二十一点程序的问题C++
- C++ 二十一点卡住试图给王牌编程
- 二十一点模拟器与类
- 二十一点游戏
- 二十一点计分程序与错误