Esempio n. 1
0
        /// <summary>
        /// Comparission of the values of each player at the end of the game, return a string with the result of the comparision.
        /// </summary>
        /// <param name="player1">Represent the Computer, an instance of CardPlayer object</param>
        /// <param name="player2">Represent the User, an instance of CardPlayer object</param>
        /// <returns></returns>
        public string CheckWinnerFinal(CardPlayer player1, CardPlayer player2)
        {
            var winneris = "NoWinner";

            var who = player1.MaxTotalHand().CompareTo((player2.MaxTotalHand() > 21) ? player2.MinTotalHand() :
                                                       player2.MaxTotalHand());

            if (who == 0)
            {
                winneris = string.Format("Have been a Tie to {0} ", player1.MaxTotalHand());
            }
            else if (who < 0)
            {
                winneris = string.Format("You Win!  {0} to {1} ",
                                         (player2.MaxTotalHand() > 21) ? player2.MinTotalHand() :
                                         player2.MaxTotalHand(),
                                         player1.MaxTotalHand());
            }
            else
            {
                winneris = string.Format("The Computer is the winner {0} to {1} ", player1.MaxTotalHand(),
                                         (player2.MaxTotalHand() > 21) ? player2.MinTotalHand() :
                                         player2.MaxTotalHand());
            }

            return(winneris);
        }
Esempio n. 2
0
        /// <summary>
        /// Comparission of the values of each player during the process of the game, return a string with the result of the comparision.
        /// </summary>
        /// <param name="player1">Represent the Computer, an instance of CardPlayer object</param>
        /// <param name="player2">Represent the User, an instance of CardPlayer object</param>
        /// <returns></returns>
        public string CheckWinner(CardPlayer player1, CardPlayer player2)
        {
            var winneris = "NoWinner";

            if (player1.MaxTotalHand() == 21 && player2.MaxTotalHand() == 21)
            {
                winneris = String.Format("Have been a Tie to {0} ", 21);
            }
            else if (player1.MaxTotalHand() == 21 || (player2.MaxTotalHand() > 21 && player2.MinTotalHand() > 21))
            {
                winneris = string.Format("The Computer is the winner {0} to {1} ", player1.MaxTotalHand(), player2.MaxTotalHand());
            }
            else if (player2.MaxTotalHand() == 21 || player2.MinTotalHand() == 21)
            {
                winneris = string.Format("You Win!  {0} to {1} ", 21, player1.MaxTotalHand());
            }

            return(winneris);
        }