コード例 #1
0
        private bool IsRoyal(PokerHand pokerHand)
        {
            Suit cardSuit = pokerHand.Cards[0].Suit;
            int countOfCardsWithEqualSuits = pokerHand.Cards.Count(card => card.Suit == cardSuit);

            if (countOfCardsWithEqualSuits != 5)
            {
                return false;
            }

            var copyOfHand = pokerHand.Cards;
            Helper.SortCardsByFace(copyOfHand);

            int startNumber = (int)copyOfHand[0].Face;

            // it can be done with for
            foreach (Card card in copyOfHand)
            {
                if ((int)card.Face != startNumber)
                {
                    return false;
                }

                startNumber++;
            }

            return true;
        }
コード例 #2
0
 public override void CheckHand(PokerHand pokerHand)
 {
     if (IsFlush(pokerHand))
     {
         Console.WriteLine(String.Format("{0} said: You have a flush!", this.GetType().Name));
     }
     else
     {
         Console.WriteLine(String.Format("{0} said: You need more methods on the chain!", this.GetType().Name));
     }
 }
コード例 #3
0
 public override void CheckHand(PokerHand pokerHand)
 {
     if (IsStraight(pokerHand))
     {
         Console.WriteLine(String.Format("{0} said: You have a straight!", this.GetType().Name));
     }
     else
     {
         this.NextChecker.CheckHand(pokerHand);
     }
 }
コード例 #4
0
        private bool IsFlush(PokerHand pokerHand)
        {
            Suit cardSuit = pokerHand.Cards[0].Suit;
            int countOfCardsWithEqualSuits = pokerHand.Cards.Count(card => card.Suit == cardSuit);

            if (countOfCardsWithEqualSuits != 5)
            {
                return false;
            }

            return true;
        }
コード例 #5
0
 public override void CheckHand(PokerHand pokerHand)
 {
     if (IsRoyal(pokerHand))
     {
         Console.WriteLine(String.Format("{0} said: You have a straight flush!", this.GetType().Name));
     }
     else
     {
         //Console.WriteLine("Someone else must check for it.");
         this.NextChecker.CheckHand(pokerHand);
     }
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: viktorD1m1trov/T-Academy
        static void Main()
        {
            PokerHand straightFlush = new PokerHand(new List<Card>()
            {
                new Card(Suit.Clubs, Face.Ace),
                new Card(Suit.Clubs, Face.Ten),
                new Card(Suit.Clubs, Face.King),
                new Card(Suit.Clubs, Face.Jack),
                new Card(Suit.Clubs, Face.Queen),
            });

            PokerHand straight = new PokerHand(new List<Card>()
            {
                new Card(Suit.Spades, Face.Ace),
                new Card(Suit.Clubs, Face.Ten),
                new Card(Suit.Clubs, Face.King),
                new Card(Suit.Diamonds, Face.Jack),
                new Card(Suit.Clubs, Face.Queen),
            });

            PokerHand flush = new PokerHand(new List<Card>()
            {
                new Card(Suit.Clubs, Face.Ace),
                new Card(Suit.Clubs, Face.Ten),
                new Card(Suit.Clubs, Face.Four),
                new Card(Suit.Clubs, Face.Six),
                new Card(Suit.Clubs, Face.Queen),
            });

            PokerHand nothing = new PokerHand(new List<Card>()
            {
                new Card(Suit.Spades, Face.Ace),
                new Card(Suit.Spades, Face.One),
                new Card(Suit.Clubs, Face.Four),
                new Card(Suit.Clubs, Face.Six),
                new Card(Suit.Diamonds, Face.Queen),
            });

            StraightFlushChecker straightFlushChecker = new StraightFlushChecker();
            StraightChecker straightChecker = new StraightChecker();
            FlushChecker flushCkecker = new FlushChecker();

            straightChecker.SetChecker(flushCkecker);
            straightFlushChecker.SetChecker(straightChecker);

            straightFlushChecker.CheckHand(straightFlush);
            straightFlushChecker.CheckHand(straight);
            straightFlushChecker.CheckHand(flush);
            straightFlushChecker.CheckHand(nothing);
        }
コード例 #7
0
        private bool IsStraight(PokerHand pokerHand)
        {
            var copyOfHand = pokerHand.Cards;
            Helper.SortCardsByFace(copyOfHand);

            int startNumber = (int)copyOfHand[0].Face;

            // it can be done with for
            foreach (Card card in copyOfHand)
            {
                if ((int)card.Face != startNumber)
                {
                    return false;
                }

                startNumber++;
            }

            return true;
        }
コード例 #8
0
 public abstract void CheckHand(PokerHand pokerHand);