示例#1
0
        // Do a round
        public void DoRound()
        {
            pack.Shuffle();

            Hand communityCards = new Hand();


            List <Player> playersIn = new List <Player>(players); // PlayersIn are the players that haven't folded this round

            int pot = 0;                                          // Number of chips in the pot
            int bet = 0;                                          // The amount that a player must match to remain in the game

            // Dealing cards to players
            for (int i = 0; i < playersIn.Count; i++)
            {
                Draw(playersIn[i].pHand, 2);
            }

            bool roundOver    = false;
            bool playerFolded = false;
            int  roundNum     = 0;

            int[] toDeal = { 0, 2, 1, 1, 1 }; // The number of cards to deal to commCards each round
            while (!roundOver)
            {
                // Drawing cards to the community hand
                try
                {
                    Draw(communityCards, toDeal[roundNum]);
                }
                catch
                {
                    Console.WriteLine("All cards drawn...");
                    roundOver = true;
                    break;
                }

                roundNum++;
                // Displaying information about the round if the player is still in
                if (!playerFolded)
                {
                    Console.WriteLine($"\nPOT:        {pot}");
                    Console.WriteLine($"YOUR CHIPS: {players[0].Chips()}");
                    Console.Write("\nYOUR HAND:  ");
                    players[0].pHand.DisplayHand();
                    Console.Write("COMMUNITY:  ");
                    communityCards.DisplayHand(true, 5);
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine("You have folded...");
                }

                // Taking bets
                for (int i = 0; i < playersIn.Count; i++)
                {
                    Console.WriteLine($"{playersIn[i].GetName()}'s turn");

                    if (playersIn[i].HasChips()) // Has player gone all in or not
                    {
                        playersIn[i].SetCommCards(communityCards);

                        //playersIn[i].pHand.DisplayHand();
                        int pBet = playersIn[i].TakeBet(bet); // Returns -1 if they want to fold

                        if (pBet >= 0)                        // not folding
                        {
                            pot += pBet;
                            bet  = playersIn[i].ChipsIn();
                        }
                        else // folding
                        {
                            if (playersIn[i].IsPlayer())
                            {
                                playerFolded = true;
                            }

                            playersIn.RemoveAt(i);
                            i--;
                        }
                    }
                    else
                    {
                        Console.WriteLine("They are all in, skipping go");
                    }

                    Thread.Sleep(1000);
                }

                if (playersIn.Count <= 1) // Checking if the round should be over
                {
                    roundOver = true;
                }
            }

            Console.WriteLine("COMMUNITY CARDS: ");
            communityCards.DisplayHand();
            foreach (Player p in playersIn) // Displaying players and their cards
            {
                Console.Write($"{p.GetName()}'s cards: ");
                p.pHand.DisplayHand();
            }

            // Calculating winner
            int highestHand  = 0;
            int highestScore = 0;

            bool done = false;

            for (int j = 0; j < 7;)            // Do 7 times because 7 cards
            {
                for (int ii = 0; ii < 2; ii++) // Do twice
                {
                    for (int i = 0; i < playersIn.Count; i++)
                    {
                        List <Tuple <int, int> > value = playersIn[i].GetHandValue();


                        if (value[j].Item1 > highestHand)
                        {
                            highestHand  = value[j].Item1;
                            highestScore = value[j].Item2;
                        }
                        else if (value[j].Item1 == highestHand)
                        {
                            if (value[j].Item2 > highestScore)
                            {
                                highestScore = value[j].Item2;
                            }
                            else if (value[j].Item2 < highestScore)
                            {
                                playersIn.RemoveAt(i);
                                i--;
                            }
                        }
                        else if (value[j].Item1 < highestHand)
                        {
                            playersIn.RemoveAt(i);
                            i--;
                            highestScore = 0;
                        }
                    }
                }

                if (playersIn.Count > 1)
                {
                    j++;
                }
                else
                {
                    break;
                }
            }


            int moneyToGive = pot / playersIn.Count;

            foreach (Player p in playersIn)
            {
                Console.WriteLine($"{p.GetName()} wins {moneyToGive}!");
                players[p.PLAYERID].AddChips(moneyToGive);
            }

            // ROUND IS OVER, CLEARING COMMUNITY CARDS
            pack.AddCard(communityCards);
        }