Exemplo n.º 1
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);
        }
Exemplo n.º 2
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();
            }
        }