c++ - I can't figure out why this value calculates in one function but not the other -
Hi I'm new and I'm working on this blackjack program for a while, I'm trying to practice To make such a simple game. I am just finished, but I have run a small problem which is preparing me to go crazy all night. There is a game, player, deck, and card class. I just try to post the relevant code, I really do not want to make it long and hard to read. I think that this work in the game class interprets the problem.
Game.cpp:
Zero Games :: Creates players (int p) // Players and stores creates players in vector (for x (x = 0; x & lt; p; x ++) player. Push_back (player (x + 1));} Void Game :: startRound () / 2 card deal for each player and print their hand (dealer.hit (Deck.draw ()); dealer.hit (deck.draw ()); Cout & lt; "Dealer's Hand:" Dealer.Get total ()) {cout & lt; & Lt; "Player" & lt; & Lt; Player [i] .getSeat () & lt; & Lt; "Win" & lt; & Lt; Endl; Players [i] .winBet (); } And if (players [i] .getTotal () & lt; dealer.gate total ()) {cout & lt; & Lt; "Player" & lt; & Lt; Player [i] .getSeat () & lt; & Lt; "Loses." & Lt; & Lt; Endl; Players [i] .loseBet (); } And cout & lt; & Lt; "Player" & lt; & Lt; Player [i] .getSeat () & lt; & Lt; "relation." & Lt; & Lt; Endl; }} I'm so sad if it's too messy or too much my problem is that Winnings (), when I use calcTotal () then getTotal ( ) It always starts only with the initial 2 cards which were given in the beginning (). However, if I use getTotal () then calcTotal () at the end of the player selection () then it returns a total of whole hand, in some way it does not calculate the whole hand when I collect it Winnings () Is there a reason for this? Am I trying to do that which does not allow? Game :: playerChoice (player x)
Code> x . In other words, a local copy is created for the duration of the function. Changes (such as new cards added to the player's deck) are lost when the caller comes back, because they are original player example (a players Used in vector which is used in startRound () and collections Winnings () ). To avoid this problem, you can pass the player to the context:
void game :: playerChoice (Player & x) // ^^^ Changes made to are made X in the caller area on the original player example. Therefore, if you were calling playerChoice in something like this: void Game :: allPlayersChoice () (for (int x = 0; x & lt; Players.size (); X ++) {playerChoice (player [x]);}} then player example players [x] < The game of the / code> object will be updated. Since archive () with the similar players [x] examples , calls players [i] .calcTotal () in collecting wings () will then be done on an updated player, which will be complete Will the student.
Comments
Post a Comment