示例#1
0
        static bool isAllHighCard = true; // if both the cards have HighCard Combination

        /// <summary>
        /// Show Individual Player Hands Card and add winners in Dictionary
        /// </summary>
        /// <param name="lstPlayerHands"></param>
        /// <returns>Dictionary with Score added</returns>
        public static Dictionary <string, int> ShowHands(List <Player> lstPlayerHands, bool isPlayAgain = false)
        {
            isAllHighCard = true;
            //High Card Dictionary, to find the winner in case of High Cards Combination
            highCardDict = new Dictionary <string, int>();
            if (isPlayAgain)
            {
                winnerDict = new Dictionary <string, int>();
            }

            // Handle high card calculation between two hands:
            for (int i = 0; i < Convert.ToInt32(lstPlayerHands.Count); i++)
            {
                Console.Write("Player " + (i + 1) + " Cards: { ");
                Console.ResetColor();
                Console.OutputEncoding = Encoding.UTF8;
                Console.Write(lstPlayerHands[i].hand[0].rank + " of " + lstPlayerHands[i].hand[0].suit + " (" + CardSign(Convert.ToString(lstPlayerHands[i].hand[0].suit)) + ")");
                Console.Write(", ");
                Console.Write(lstPlayerHands[i].hand[1].rank + " of " + lstPlayerHands[i].hand[1].suit + " (" + CardSign(Convert.ToString(lstPlayerHands[i].hand[1].suit)) + ")");
                Console.OutputEncoding = Encoding.Default;
                Console.Write(" }, ");

                // Check Player Cards
                string key   = "Player" + Convert.ToInt32(i + 1);
                int    score = DetermineHand(lstPlayerHands[i].hand);
                string name  = Enum.GetName(typeof(PockerEnum.PockerWinning), score);
                Console.Write("Hand Ranks: [ " + name + " ]; \n");

                if (score == 0 && isAllHighCard)
                {
                    string highCard  = WinningCombinations.GetHighCardRank(lstPlayerHands[i].hand);
                    int    rankValue = GetCardByRank(highCard);
                    highCardDict.Add(key, rankValue);
                }
                else
                {
                    //If no high card combination then variable false
                    isAllHighCard = false;
                }

                if (winnerDict.ContainsKey(key))
                {
                    winnerDict[key] += score;
                }
                else
                {
                    winnerDict.Add(key, score);
                }
            }

            CheckHighCard();
            PrintRoundWinner();
            return(winnerDict);
        }
示例#2
0
 /// <summary>
 /// Check the card Combination
 /// </summary>
 /// <param name="playerHand"></param>
 /// <returns>Integer Value of Hand Type</returns>
 public static int DetermineHand(List <Cards> playerHand)
 {
     if (WinningCombinations.StraightFlushCheck(playerHand))
     {
         return((int)PockerEnum.PockerWinning.StraightFlush); // 5;StraightFlush
     }
     if (WinningCombinations.FlushCheck(playerHand))
     {
         return((int)PockerEnum.PockerWinning.Flush);// 4;Flush
     }
     if (WinningCombinations.StraightCheck(playerHand))
     {
         return((int)PockerEnum.PockerWinning.Straight);// 3;Straight
     }
     if (WinningCombinations.PairCheck(playerHand))
     {
         return((int)PockerEnum.PockerWinning.Pair); // 2;Pair
     }
     return((int)PockerEnum.PockerWinning.HighCard); // 0;HighCard
 }