Esempio n. 1
0
        // asks the deck for the next set of board cards (flop, turn, river)
        private void progressGameState(List<Player> players, Deck deck)
        {
            List<Card> boardCards = deck.getBoardCards();
            if (boardCards.Count > 0)//Special case: only appends a new line for post-flop and beyond for formatting purposes
            {
                gameForm.appendHistory(""); //new line
            }
            gameForm.revealBoardCards(boardCards);
            if (boardCards.Count > 0)//Special case: only appends a new line for post-flop and beyond for formatting purposes
            {
                gameForm.appendHistory(""); //new line
            }

            foreach (Player player in players)
                player.addCardsToHand(boardCards);
        }
Esempio n. 2
0
        // 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;
        }
Esempio n. 3
0
 // gives each player in the list 2 cards for their hand
 private void dealStartingHands(List<Player> players, Deck deck)
 {
     foreach(Player player in players)
     {
         player.addStartingCardsToHand(deck.getNextHand());
     }
 }