コード例 #1
0
        public void TablePlayRound(Deck gameDeck, Card[] garbage, Dealer dealer, Player[] players, int playerNumber)
        {
            for (int i = 1; i < players.Length; i++)
            {
                bool condition = players[i].PlayerPlays();
                if (condition)
                {
                    while (condition)
                    {
                        dealer.DealOnce(gameDeck, garbage, i);
                        PlayerHit(dealer, players, i);
                        condition = players[i].PlayerPlays();
                    }
                }
            }

            bool dealerCondition = players[0].PlayerPlays();

            if (dealerCondition)
            {
                while (dealerCondition)
                {
                    dealer.DealOnce(gameDeck, garbage, 0);
                    PlayerHit(dealer, players, 0);
                    dealerCondition = players[0].PlayerPlays();
                }
            }

            //PrintTable(gameDeck,garbage,players);
            int[] winners = DecidedWinners(players);
            for (int j = 0; j < players.Length; j++)
            {
                // show dealer's hands
                // show players' hands and announce winners
                if (j == 0)
                {
                    Console.WriteLine("Dealer's hand: ");
                    //dealer
                    Player dealerPlayer = players[j];
                    foreach (Card card in dealerPlayer.cards)
                    {
                        if (card != null)
                        {
                            int caseSwitch = card.Value;

                            switch (caseSwitch)
                            {
                            case 11:
                                Console.Write("Jack");
                                break;

                            case 12:
                                Console.Write("Queen");
                                break;

                            case 13:
                                Console.Write("King");
                                break;

                            case 14:
                                Console.Write("Ace");
                                break;

                            default:
                                Console.Write(card.Value);
                                break;
                            }
                            Console.Write(" of ");
                            Console.Write(card.Suit);
                            Console.Write(", ");
                            Console.Write("of ");
                            Console.Write(card.Suit);
                            Console.Write(", ");
                        }
                    }

                    int lost = 0;
                    int won  = 0;
                    foreach (int number in winners)
                    {
                        if (number == 1)
                        {
                            lost += 1;
                        }
                        else
                        {
                            won += 1;
                        }
                    }

                    int total = (won - lost) * 10;
                    players[j].wallet += total;

                    Console.Write("Total: ");
                    Console.WriteLine(ReturnTotalPoints(dealerPlayer.cards));
                    Console.Write("Casino net: ");
                    Console.WriteLine(players[j].wallet);
                    Console.WriteLine("");
                }
                else
                {
                    //players
                    Player dealerPlayer = players[j];
                    foreach (Card card in dealerPlayer.cards)
                    {
                        if (card != null)
                        {
                            int caseSwitch = card.Value;

                            switch (caseSwitch)
                            {
                            case 11:
                                Console.Write("Jack");
                                break;

                            case 12:
                                Console.Write("Queen");
                                break;

                            case 13:
                                Console.Write("King");
                                break;

                            case 14:
                                Console.Write("Ace");
                                break;

                            default:
                                Console.Write(card.Value);
                                break;
                            }
                            Console.Write(" of ");
                            Console.Write(card.Suit);
                            Console.Write(", ");
                        }
                    }
                    Console.Write("Total: ");
                    Console.WriteLine(ReturnTotalPoints(dealerPlayer.cards));

                    if (winners[j] == 1)
                    {
                        Console.WriteLine("Player wins");
                    }
                    else
                    {
                        Console.WriteLine("Player loses");
                    }
                    Console.WriteLine(players[j].wallet);
                }
            }
        }