public void TestIsDuplicateCard()
        {
            //Arrange
            PlayPokerGame PokerFirstGame = new PlayPokerGame();

            PokerPlayer Joe = new PokerPlayer("Joe");

            PokerFirstGame.AddPlayer(Joe);

            PokerFirstGame.GivePlayingCards(Joe, new PlayingCard {
                Rank = RankType.Eight, Suit = SuitType.Clubs
            });
            PokerFirstGame.GivePlayingCards(Joe, new PlayingCard {
                Rank = RankType.Six, Suit = SuitType.Heart
            });
            PokerFirstGame.GivePlayingCards(Joe, new PlayingCard {
                Rank = RankType.Eight, Suit = SuitType.Heart
            });
            PokerFirstGame.GivePlayingCards(Joe, new PlayingCard {
                Rank = RankType.Jack, Suit = SuitType.Heart
            });
            PokerFirstGame.GivePlayingCards(Joe, new PlayingCard {
                Rank = RankType.Eight, Suit = SuitType.Diamond
            });
            PokerFirstGame.GivePlayingCards(Joe, new PlayingCard {
                Rank = RankType.Eight, Suit = SuitType.Diamond
            });

            //Act
            try
            {
                PokerHand pokerHand = PokerFirstGame.GetWinner();
            }
            catch (Exception ex)
            {
                //Assert
                StringAssert.Contains(ex.Message.ToString(), "Duplicate card(s) found");
                return;
            }

            Assert.Fail("No exception was thrown.");
        }
Example #2
0
        static void Main(string[] args)
        {
            //Create object for the first game
            PlayPokerGame PokerFirstGame = new PlayPokerGame();

            //Create object players
            PokerPlayer Joe = new PokerPlayer("Joe");
            PokerPlayer Jen = new PokerPlayer("Jen");
            PokerPlayer Bob = new PokerPlayer("Bob");

            //Added players to the first poker game object
            PokerFirstGame.AddPlayer(Joe);
            PokerFirstGame.AddPlayer(Bob);
            PokerFirstGame.AddPlayer(Jen);

            //Assign cards to the players using poker game object
            PokerFirstGame.GivePlayingCards(Joe, new PlayingCard {
                Rank = RankType.Three, Suit = SuitType.Heart
            });
            PokerFirstGame.GivePlayingCards(Joe, new PlayingCard {
                Rank = RankType.Six, Suit = SuitType.Heart
            });
            PokerFirstGame.GivePlayingCards(Joe, new PlayingCard {
                Rank = RankType.Eight, Suit = SuitType.Heart
            });
            PokerFirstGame.GivePlayingCards(Joe, new PlayingCard {
                Rank = RankType.Jack, Suit = SuitType.Heart
            });
            PokerFirstGame.GivePlayingCards(Joe, new PlayingCard {
                Rank = RankType.King, Suit = SuitType.Heart
            });

            PokerFirstGame.GivePlayingCards(Jen, new PlayingCard {
                Rank = RankType.Three, Suit = SuitType.Clubs
            });
            PokerFirstGame.GivePlayingCards(Jen, new PlayingCard {
                Rank = RankType.Three, Suit = SuitType.Diamond
            });
            PokerFirstGame.GivePlayingCards(Jen, new PlayingCard {
                Rank = RankType.Three, Suit = SuitType.Spades
            });
            PokerFirstGame.GivePlayingCards(Jen, new PlayingCard {
                Rank = RankType.Eight, Suit = SuitType.Clubs
            });
            PokerFirstGame.GivePlayingCards(Jen, new PlayingCard {
                Rank = RankType.Ten, Suit = SuitType.Diamond
            });

            PokerFirstGame.GivePlayingCards(Bob, new PlayingCard {
                Rank = RankType.Two, Suit = SuitType.Heart
            });
            PokerFirstGame.GivePlayingCards(Bob, new PlayingCard {
                Rank = RankType.Five, Suit = SuitType.Clubs
            });
            PokerFirstGame.GivePlayingCards(Bob, new PlayingCard {
                Rank = RankType.Seven, Suit = SuitType.Spades
            });
            PokerFirstGame.GivePlayingCards(Bob, new PlayingCard {
                Rank = RankType.Ten, Suit = SuitType.Clubs
            });
            PokerFirstGame.GivePlayingCards(Bob, new PlayingCard {
                Rank = RankType.Ace, Suit = SuitType.Heart
            });

            //Evaluate and get the second winner
            PokerHand firstWinner = PokerFirstGame.GetWinner();

            Console.WriteLine("Winner for the first game is: {0} using {1}", firstWinner.Name, firstWinner.Category.ToString());

            Console.WriteLine("------------------------------------------");
            Console.WriteLine("Press any key to proceed to the next round");
            Console.WriteLine("------------------------------------------");
            Console.ReadKey();

            //Create object for the first game
            PlayPokerGame PokerSecondGame = new PlayPokerGame();

            //Used the same object for the player and cleared the cards for the new round
            Joe.ClearCards();
            Bob.ClearCards();
            Jen.ClearCards();

            //Added players to the second poker game object
            PokerSecondGame.AddPlayer(Joe);
            PokerSecondGame.AddPlayer(Jen);
            PokerSecondGame.AddPlayer(Bob);

            //Assign cards to the players using poker game object
            PokerSecondGame.GivePlayingCards(Joe, new PlayingCard {
                Rank = RankType.Three, Suit = SuitType.Heart
            });
            PokerSecondGame.GivePlayingCards(Joe, new PlayingCard {
                Rank = RankType.Four, Suit = SuitType.Diamond
            });
            PokerSecondGame.GivePlayingCards(Joe, new PlayingCard {
                Rank = RankType.Nine, Suit = SuitType.Clubs
            });
            PokerSecondGame.GivePlayingCards(Joe, new PlayingCard {
                Rank = RankType.Nine, Suit = SuitType.Diamond
            });
            PokerSecondGame.GivePlayingCards(Joe, new PlayingCard {
                Rank = RankType.Queen, Suit = SuitType.Heart
            });

            PokerSecondGame.GivePlayingCards(Jen, new PlayingCard {
                Rank = RankType.Five, Suit = SuitType.Clubs
            });
            PokerSecondGame.GivePlayingCards(Jen, new PlayingCard {
                Rank = RankType.Seven, Suit = SuitType.Diamond
            });
            PokerSecondGame.GivePlayingCards(Jen, new PlayingCard {
                Rank = RankType.Nine, Suit = SuitType.Heart
            });
            PokerSecondGame.GivePlayingCards(Jen, new PlayingCard {
                Rank = RankType.Nine, Suit = SuitType.Spades
            });
            PokerSecondGame.GivePlayingCards(Jen, new PlayingCard {
                Rank = RankType.Queen, Suit = SuitType.Spades
            });

            PokerSecondGame.GivePlayingCards(Bob, new PlayingCard {
                Rank = RankType.Two, Suit = SuitType.Heart
            });
            PokerSecondGame.GivePlayingCards(Bob, new PlayingCard {
                Rank = RankType.Two, Suit = SuitType.Clubs
            });
            PokerSecondGame.GivePlayingCards(Bob, new PlayingCard {
                Rank = RankType.Five, Suit = SuitType.Spades
            });
            PokerSecondGame.GivePlayingCards(Bob, new PlayingCard {
                Rank = RankType.Ten, Suit = SuitType.Clubs
            });
            PokerSecondGame.GivePlayingCards(Bob, new PlayingCard {
                Rank = RankType.Ace, Suit = SuitType.Heart
            });

            //Evaluate and get the second winner
            PokerHand secondWinner = PokerSecondGame.GetWinner();

            Console.WriteLine("Winner for the second game is: {0} using {1}", secondWinner.Name, secondWinner.Category.ToString());

            Console.ReadKey();
        }
Example #3
0
        public static void PlayPoker()
        {
            List <string> Name = new List <string>();

            PlayPokerGame PokerGameFirst = new PlayPokerGame();

            for (int i = 1; i < 3; i++)
            {
                Console.WriteLine("Please Enter Name of Player Number {0}", i);
                string name = Console.ReadLine();
                Name.Add(name);
            }

            for (int i = 0; i < Name.Count; i++)
            {
                PokerPlayer player = new PokerPlayer(Name[i]);


                PokerGameFirst.AddPlayer(player);
                Console.WriteLine("");
                Console.WriteLine("Card No for {0}", Name[i]);
                Console.WriteLine("----------------------------------------------------------------------");
                Console.WriteLine("Ranktype: Please Enter Rank Type for: {0} ", Name[i]);
                Console.WriteLine("For Rank Type Please Choose Five from the Following List");
                Console.WriteLine("List:  Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten");
                Console.WriteLine("List:  Jack, Queen, King, Ace, None");
                Console.WriteLine("EXAMPLE TO TYPE IN THE CONSOLE: *** Jack, Queen, King, Ace, Five *** ");
                Console.WriteLine("-----------------------------------------------------------------------");


                List <int> RankType  = new List <int>();
                List <int> SuitsType = new List <int>();

                string   valueRank     = Console.ReadLine();
                string[] testValueRank = UtilityClass.SplitString(valueRank);


                for (int k = 0; k < testValueRank.Length; k++)
                {
                    UtilityClass.ParseRank(RankType, testValueRank, k);
                }

                Console.WriteLine("");
                Console.WriteLine("-------------------------------------------------------------------------------");
                Console.WriteLine("Suit Card: Please Enter Suit Card for: {0}", Name[i]);
                Console.WriteLine("For Suit Card Please Choose FIVE From the Following List");
                Console.WriteLine("List:  Diamond, Heart, Spades, Clubs, None");
                Console.WriteLine("EXAMPLE TO TYPE IN THE CONSOLE: **** Diamond, Spades, Heart, Heart, Clubs *** ");
                Console.WriteLine("---------------------------------------------------------------------------------");
                Console.WriteLine("");
                string valueForType = Console.ReadLine();

                string[] SuitTypeValue = UtilityClass.SplitString(valueForType);

                UtilityClass.ParseSuit(SuitsType, SuitTypeValue);

                for (int m = 0; m < 4; m++)
                {
                    int ranktype = RankType[m];
                    int suitType = SuitsType[m];

                    RankType rankForPlayingCard = (RankType)Enum.ToObject(typeof(RankType), ranktype);
                    SuitCard suit = (SuitCard)Enum.ToObject(typeof(SuitCard), suitType);
                    PokerGameFirst.GivePlayingCards(player, new PlayingCard {
                        Rank = rankForPlayingCard, Suit = suit
                    });
                }
            }
            Console.WriteLine("");
            PokerHand firstWinner = PokerGameFirst.GetWinner();

            Console.WriteLine("Winner for the first game is: {0} using {1}", firstWinner.Name, firstWinner.Category.ToString());
            Console.Read();
        }