Heeeello!
So, i've made the game blackjack. When I bet all of my money and get busted the program will reset my player/s. That's a problem, because after the bust the program will ask the user if he/she wants to play again, if 'y' there is no longer a player, but the dealer is still there. The dealer will get cards but as there are no players the dealer will go into an infinite loop.
I can't see what I should do, please help. And if you want to see inside a function, please say so.
int Game::init()
{
mRun = true;
return 0;
}
bool Game::checkBets(Player& player)
{
if (player.getBet() > 0)
returntrue;
returnfalse;
}
int Game::run()
{
init();
while (mRun)
{
int choice = 0;
cout << "BLACKJACK!\n\n" << "1) Play Game\n2) Exit\n";
(cin >> choice).get();
switch (choice)
{
case 1:
{
int players = 0;
cout << "Select players (1-5) : ";
(cin >> players).get();
if (players < 1 || players > 5)
{
cout << "error, " << players << " is not a valid input\n";
}
else
{
game(players);
}
break;
}
case 2:
mRun = false;
break;
default:
cout << "Incorrect input\n";
break;
}
}
return 0;
}
void Game::game(int players)
{
PlayerList playerList;
for (unsignedint i = 0; i < players; i++)
{
std::string tmpName;
cout << "Player " << i + 1 << " , please enter your name: ";
getline(cin, tmpName);
Player tmpPlayer(tmpName);
playerList.addPlayer(tmpPlayer);
}
bool play = true;
while (play)
{
playerList.makeBet();
//PlayerList inGameList = playerList.createNewPlayerList(); // a list of players that made a bet (non betting players are exluded from this round)
Dealer dealer;
bool firstRound = true;
if (!playerList.empty())
{
srand(time(0));
while (true)
{
playerList.checkMoney(); // removes a player if he has 0 money
if (firstRound) // if it is the first round, draw two cards;
{
dealer.drawCard();
dealer.drawCard();
playerList.drawCard();
playerList.drawCard();
firstRound = false;
}
else
{
playerList.drawCard();
dealer.drawCard();
}
dealer.printHand();
playerList.printHand();
dealer.checkBusted(); // check if the dealer is busted
playerList.checkForBusted(dealer); // check if any players are busted
playerList.makeChoice(dealer);
dealer.makeChoice(&playerList); // dealer makes his choice
if (playerList.playerStatusBust())
{
playerList.playersLose();
cout << "\nAll players BUST\n";
if (playerList.continueGame())
{
playerList.resetPlayers();
dealer.reset();
firstRound = true;
break;
}
elseif (!playerList.continueGame())
{
play = false;
break;
}
}
if (playerList.playerStatus(dealer)) // if so proceed to the verdict of the game
{
dealer.printFullHand();
playerList.verdict(dealer);
if (playerList.continueGame())
{
playerList.resetPlayers();
dealer.reset();
firstRound = true;
break;
}
else
{
play = false;
break;
}
}
}
}
else
{
cout << "No bets have been made, please make a bet.\n";
}
}
}
Okey, need to add more information. When the player have no money left, he will be resetted. Not just when busted.
You can play till all the money is gone, then there is an infinite loop.