Im working on a texas holdem game. I have a method getEveryonesBet that goes through a round of betting, makes sure all the bets are equal, collects money, puts it in the pot. In that method I call:
which asks a player for a bet and returns it. This worked fine in earlier versions of my program which were console based. Now that it is GUI based, and event based, execution stops while my program waits for getBetFromPlayer to return.
I have solved the problem by running in a thread, but I know that isnt the way to do it, and instead I need to convert to an event based program flow. Im stuck and looking for ideas. Since getBetFromPlayer is nested in a couple loops, the event driven code would get very complicated any way I can think of.
Here is getEveryonesBet:
The entire project is at code.google.com/wlhcards
Code:
(float)getBetFromPlayer:(Player *)player
I have solved the problem by running in a thread, but I know that isnt the way to do it, and instead I need to convert to an event based program flow. Im stuck and looking for ideas. Since getBetFromPlayer is nested in a couple loops, the event driven code would get very complicated any way I can think of.
Here is getEveryonesBet:
Code:
-(void) getEveryonesBet {
// get Everyone's initial bet
lastBet = 0;
currentBet = -1.0;
// while bets are not square (all the same) ask the next player for a bet.
int j = 0;
int oneRound = NO; // to insure at least one round of betting completes
while ( ( ![self betsAreSquare] ) || ( oneRound==NO ) ) { // while bets are not square (all the same) ask the next player for a bet.
currentBet = [gameView getBetFromPlayer:[players objectAtIndex:j]];
while (currentBet < lastBet) { // make sure bet is at least as high as previous bet
[gameView invalidBet:lastBet];
currentBet = [gameView getBetFromPlayer:[players objectAtIndex:j]];
}
lastBet = currentBet;
// update the money in the pot
pot += lastBet;
[gameView updatePot:pot];
// subtract bet from player
Player *player = ((Player *)[players objectAtIndex:j]);
player.money -= lastBet;
if (player.money < 0) {
pot += player.money; // don't allow more added to pot than player has
player.money = 0;
[gameView updatePot:pot];
}
[player display];
if ( (++j)==[players count]) {j = 0;oneRound=TRUE;} // loop back to player 0 until while loop is satisfied.
} //while loop
} // get everyones bet
The entire project is at code.google.com/wlhcards