public Game(List<Player> players) { if (players.Count > 0) { currentRound = null; thread = new Thread(this.play); gameForm = new GameForm(this); gameForm.Show(); // set up gameform with player names and starting chip counts gameForm.updatePlayers(players); this.activePlayers = players; startingBlindAmount = players[0].getChipCount() / 100; thread.Start(); } }
// plays this round of poker with the given players // removes players from the list if they have been knocked out (0 chips) // updates the game UI as needed public Player playRound(List<Player> players, GameForm gameForm, int indexOfBigBlindPlayer, int bigBlindAmount) { // save a global reference to the gameform for UI updates this.gameForm = gameForm; // create a shuffled deck of cards for this round of poker Deck deck = new Deck(); // calculate the blinds and add them to the pot potAmount = calculateBlinds(players, indexOfBigBlindPlayer, bigBlindAmount); gameForm.setPotTotal(potAmount); // give each player their two starting cards dealStartingHands(players, deck); //Create the string we show at the end for player hands String playerHandString = Environment.NewLine + "****Player Hands****"; foreach(Player p in players) { playerHandString += Environment.NewLine + p.getName() + Environment.NewLine + p.getPlayerHand()[0].toString() + ", " + p.getPlayerHand()[1].toString() + Environment.NewLine; } playerHandString += "****End of Player Hands****"; // each round has 4 possible betting sessions : pre-flop, post-flop, post-turn, post-river for (int i = 0; i < 4; i++) { // check to make sure there is atleast 2 players who havent folded yet or else we have a winner int remainingPlayers = players.Count - foldedPlayersPositions.Count; if (remainingPlayers > 1) { // add flop, turn, river cards to player hands progressGameState(players, deck); System.Threading.Thread.Sleep(DELAY_SPEED); performAllMoves(players, foldedPlayersPositions, remainingPlayers, indexOfBigBlindPlayer); } else break; } // determine the winner of this round after all rounds have finished or only 1 person has not folded Player winner = determineWinner(players, foldedPlayersPositions); // reset all chip contributions to the pot for this round to 0 foreach(Player player in players) { player.resetChipsInCurrentPot(); player.setMoveChoice(null); if (player is AIPlayer) { ((AIPlayer)player).learnAndCleanUp(winner); } } //Round is over, reveal all player hands gameForm.appendHistory(playerHandString); winner.modifyChipCount(potAmount); //Update our history with the round winner information List<Card> winningHand = winner.getPlayerHand(); gameForm.appendHistory(Environment.NewLine + winner.getName() + " has won the round!"); gameForm.appendHistory("Pot Winnings: " + potAmount); gameForm.appendHistory("Winning Hand: " + winningHand[0].toString() + " and " + winningHand[1].toString()); gameForm.setPotTotal(0); gameForm.updatePlayerChipCount(winner); gameForm.clearRevealedCards(); return winner; }