예제 #1
0
        static HandCards compareSameCategory(List <HandCards> cardGroupsList)
        {
            HandCards result  = cardGroupsList[0];
            int       maxRank = 0;

            foreach (HandCards handCards in cardGroupsList)
            {
                if (handCards.getRank() > maxRank)
                {
                    result  = handCards;
                    maxRank = handCards.getRank();
                }
            }
            return(result);
        }
예제 #2
0
        static void Main(string[] args)
        {
            bool quit = false;

            while (!quit)
            {
                Console.WriteLine("Start Game\n");

                // generate a new whole deck
                WholeDeckCards wholeDeckcards = new WholeDeckCards();
                wholeDeckcards.generateDeck();

                // shuffle deck
                wholeDeckcards.shuffleCards();
                Console.WriteLine("the shuffled deck are showing below: ");
                wholeDeckcards.printCards();
                Console.WriteLine("\n");

                // deal cards to 4 players
                Console.WriteLine("deal cards to 4 players");

                CardGroup player1Deck = wholeDeckcards.popCards(0, 5);
                CardGroup player2Deck = wholeDeckcards.popCards(0, 5);
                CardGroup player3Deck = wholeDeckcards.popCards(0, 5);
                CardGroup player4Deck = wholeDeckcards.popCards(0, 5);

                HandCards player1HandCards = HandCards.CreateInstance(player1Deck);
                HandCards player2HandCards = HandCards.CreateInstance(player2Deck);
                HandCards player3HandCards = HandCards.CreateInstance(player3Deck);
                HandCards player4HandCards = HandCards.CreateInstance(player4Deck);

                Console.WriteLine("\n");

                if (player1HandCards != null && player2HandCards != null && player3HandCards != null && player4HandCards != null)
                {
                    List <HandCards> handCardsList = new List <HandCards> {
                        player1HandCards,
                        player2HandCards,
                        player3HandCards,
                        player4HandCards,
                    };

                    int numOfPlayer = 1;
                    foreach (HandCards handCards in handCardsList)
                    {
                        numOfPlayer += 1;
                        Console.WriteLine($"player{numOfPlayer}'s hand:");
                        handCards.printCards();
                        Console.Write($"player{numOfPlayer}'s hand Categoery: ");
                        Console.WriteLine(handCards.handCategory);
                        Console.WriteLine("-------------------------------------------------------------");
                    }

                    // compare category
                    HandCards.HandCategory largesetCategory = getLargestCategory(handCardsList);
                    Console.WriteLine($"the largest category is {largesetCategory}");
                    Console.WriteLine("\n");

                    // get player's who have largest category
                    List <HandCards> lCHandCardsList = new List <HandCards>();

                    foreach (HandCards handCards in handCardsList)
                    {
                        if (handCards.handCategory == largesetCategory)
                        {
                            lCHandCardsList.Add(handCards);
                        }
                    }

                    HandCards winner = compareSameCategory(lCHandCardsList);
                    Console.WriteLine($"Winner has a {winner.handCategory}");
                    Console.WriteLine("Winner's Cards are:");
                    winner.printCards();

                    Console.WriteLine("game finished");
                    Console.WriteLine("\n");

                    // Wait for the user to respond before closing.
                    Console.Write("Press 'n' and Enter to close the app, or press any other key and Enter to continue: ");
                    if (Console.ReadLine() == "n")
                    {
                        quit = true;
                    }

                    Console.WriteLine("\n");                     // Friendly linespacing.
                }
            }
        }