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; }
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)); } }
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); } }
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; }
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); } }
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); }
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; }
public abstract void CheckHand(PokerHand pokerHand);