示例#1
0
        public void TestCardRank()
        {
            // Check whether Function works appropriately or not
            int cardValue = PockerSolvingMethods.GetCardByRank("A");

            Assert.AreEqual(14, cardValue);
        }
示例#2
0
        public void TestPockerWinner()
        {
            Player        pl             = new Player();
            List <Player> lstPlayerHands = new List <Player>();

            // Add Cards in List
            List <Cards> player1Cards = new List <Cards>();

            player1Cards.Add(new Cards(PockerEnum.Suit.Spades, PockerEnum.Rank.A));
            player1Cards.Add(new Cards(PockerEnum.Suit.Diamonds, PockerEnum.Rank.J));
            pl.hand.AddRange(player1Cards);
            lstPlayerHands.Add(pl);

            pl = new Player();
            List <Cards> player2Cards = new List <Cards>();

            player2Cards.Add(new Cards(PockerEnum.Suit.Hearts, PockerEnum.Rank.Four));
            player2Cards.Add(new Cards(PockerEnum.Suit.Hearts, PockerEnum.Rank.Nine));
            pl.hand.AddRange(player2Cards);
            lstPlayerHands.Add(pl);

            Dictionary <string, int> dict = PockerSolvingMethods.ShowHands(lstPlayerHands);
            string winnerName             = PockerSolvingMethods.GetWinnerName(dict);

            // Comparison of expected value with input values
            Assert.AreEqual("Player2", winnerName);
        }
示例#3
0
        public void TestGetWinnerName()
        {
            Dictionary <string, int> dict = new Dictionary <string, int>();

            dict.Add("Player1", 1);
            dict.Add("Player2", 4);
            dict.Add("Player3", 3);
            dict.Add("Player4", 2);
            // Check whether Function works appropriately or not
            string winnerName = PockerSolvingMethods.GetWinnerName(dict);

            Assert.AreEqual("Player2", winnerName);
        }
示例#4
0
        public void TestHandType()
        {
            // Add Cards in List
            List <Cards> playerCards = new List <Cards>();

            playerCards.Add(new Cards(PockerEnum.Suit.Spades, PockerEnum.Rank.Ten));
            playerCards.Add(new Cards(PockerEnum.Suit.Diamonds, PockerEnum.Rank.Ten));

            // Check whether Function works appropriately or not
            int handValue = PockerSolvingMethods.DetermineHand(playerCards);

            // Both Cards have same Rank, Return value must be Pair, 2
            Assert.AreEqual(2, handValue);
        }
示例#5
0
        static void Main(string[] args)
        {
            Console.Title = "Poker";
            Console.WriteLine("Welcome to Two(2) Card Poker Challenge");

PlayAgain:
            try
            {
                GetPlayer();
                GetRound();

                Console.WriteLine("------------------------------------");
                Console.Write("\n");

                // Looping for total round of Poker
                for (int countRound = 1; countRound <= Convert.ToInt32(totalRound); countRound++)
                {
                    Console.WriteLine("--------");
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("Round {0}", countRound);
                    Console.ResetColor();
                    Console.WriteLine("--------");

                    GetShuffleNumber();

                    deck.ShuffleCards(Convert.ToInt32(shuffleNo));
                    Console.WriteLine("--------");

                    List <Player> lstplayer = new List <Player>();
                    for (int countPlayer = 1; countPlayer <= Convert.ToInt32(totalPlayer); countPlayer++)
                    {
                        Player player = new Player();
                        //Deal cards
                        player.GenerateCards();
                        lstplayer.Add(player);
                    }

                    // Show Player Hands and Return Dictionary with Score
                    winnerDict  = PockerSolvingMethods.ShowHands(lstplayer, isPlayAgain);
                    isPlayAgain = false;
                    // Return WinnerName with higher Score
                    winnerName = PockerSolvingMethods.GetWinnerName(winnerDict);
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("After Round {0}, the Winner is {1}", countRound, winnerName);
                    Console.WriteLine("-----------------------------------------------------------------------------\n");
                    Console.ResetColor();
                }

                Console.ForegroundColor = ConsoleColor.DarkGray;
                //Find OverAll Winner
                winnerName = PockerSolvingMethods.GetWinnerName(winnerDict);
                Console.WriteLine(winnerName + " won the Poker! Cheers!");

                //Play Again Message
                Console.WriteLine("Play Again? 'Y' to continue or 'Anykey' to exit");
                Console.ResetColor();
                string playAgain = Console.ReadLine();
                Console.WriteLine("\n");
                Console.ResetColor();
                // If Y then Jump to PlayAgain otherwise Exit
                if (playAgain.ToUpper() == "Y")
                {
                    ResetVariables();
                    isPlayAgain = true;
                    goto PlayAgain;
                }
                else
                {
                    Console.ReadLine();
                }
            }
            catch (InvalidOperationException ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Invalid Operation: ", ex.Message);
                Console.ResetColor();
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: ", ex.Message);
                Console.ResetColor();
                Console.ReadLine();
            }
        }