示例#1
0
        static void Main(string[] args)
        {
            GameDriver game = new GameDriver();

            // Run the game
            game.RunGame();
        }
示例#2
0
        public static void displayHand(Player currentPlayer)
        {
            GameDriver.Sleep(3000);

            int numOfCardsDisplayed = 1;

            foreach (Card card in currentPlayer.HandOfCards)
            {
                numOfCardsDisplayed++;
                Card.ResetCursor(numOfCardsDisplayed);
                Card.PrintCard(card);

                // Console.WriteLine($"{card.Value} of {card.Suit}");
            }
        }
示例#3
0
        private void declareWinner(Player player1, Player player2)
        {
            if (player1.NumOfPairs > player2.NumOfPairs)
            {
                Console.WriteLine("\n**************** WE HAVE A WINNER ****************************\n");
                Console.WriteLine("\n The deck has run out and now we need to decide a winner.... drumroll please...\n");
                GameDriver.Sleep(4000);

                Console.WriteLine($"\nPlayer {player1.PlayerNumber} has won! Player {player1.PlayerNumber} had {player1.NumOfPairs} pairs while " +
                                  $"Player {player2.PlayerNumber} came close with {player2.NumOfPairs} pairs!");


                Console.WriteLine("\n Press enter to exit the program.");
                Console.ReadLine();
            }

            else if (player2.NumOfPairs > player1.NumOfPairs)
            {
                Console.WriteLine("\n**************** WE HAVE A WINNER ****************************\n");
                Console.WriteLine("\nThe deck has run out and now we need to decide a winner.... drumroll please...\n");
                GameDriver.Sleep(4000);

                Console.WriteLine($"\nPlayer {player2.PlayerNumber} has won! Player {player2.PlayerNumber} had {player2.NumOfPairs} pairs while " +
                                  $"Player {player1.PlayerNumber} came close with {player1.NumOfPairs} pairs!\n");


                Console.WriteLine("\n Press enter to exit the program.");
                Console.ReadLine();
            }

            else
            {
                Console.WriteLine("\nThe game has ended in a tie!\n");

                Console.WriteLine($"\nBoth players have {player1.NumOfPairs} pairs!\n");

                Console.WriteLine("\nPress enter to exit the program.");
                Console.ReadLine();
            }
        }
示例#4
0
        public static void checkForDuplicates(Player currentPlayer)
        {
            // Returns Dictionary<CardValue, Card>>
            var cardsOrderedByValue = currentPlayer.HandOfCards.GroupBy(card => card.Value);

            // Create the new hand for the player
            var newHand = new List <Card>();

            // for each key: value pair in the dictionary
            foreach (var valueCardPair in cardsOrderedByValue)
            {
                // Gets the card value of the current iteration
                var currentKey = valueCardPair.Key;

                // Returns the list of cards that correspond to the given key (card value in this case)
                var listOfCardsByKey = valueCardPair.ToList();

                // Gives us the number of cards that correspond to the given card value
                var numOfCards = listOfCardsByKey.Count;

                // If the cnumber of cards
                if (numOfCards == 1)
                {
                    // If the key only has one or three corresponding card, it's safe to add the first card to the deck
                    // Other wise we do nothing
                    newHand.Add(listOfCardsByKey[0]);
                }

                else if (numOfCards == 2)
                {
                    currentPlayer.NumOfPairs++;

                    Console.WriteLine($"\nYou had a pair of {currentKey}'s! They will removed from your deck and your pair count is now: " +
                                      $"{currentPlayer.NumOfPairs} pairs!\n");

                    GameDriver.Sleep(3000);
                }

                else if (numOfCards == 3)
                {
                    currentPlayer.NumOfPairs++;

                    Console.WriteLine($"\nYou had a pair of {currentKey}'s! They will removed from your deck and your pair count is now: " +
                                      $"{currentPlayer.NumOfPairs} pairs!\n");

                    newHand.Add(listOfCardsByKey[0]);
                    GameDriver.Sleep(3000);
                }

                else if (numOfCards == 4)
                {
                    currentPlayer.NumOfPairs += 2;

                    Console.WriteLine($"\nLucky! You had two pairs of {currentKey}'s! They will removed from your deck and your pair count is now: " +
                                      $"{currentPlayer.NumOfPairs} pairs!\n");

                    GameDriver.Sleep(3000);
                }
            }

            if (newHand.Count != currentPlayer.HandOfCards.Count)
            {
                Console.WriteLine($"\nPlayer {currentPlayer.PlayerNumber} it is still your turn, press enter to get your new hand:\n ");

                currentPlayer.HandOfCards = newHand;
                Console.ReadLine();
                Console.Clear();
                displayHand(currentPlayer);
            }
        }