Exemple #1
0
        /// <summary>
        /// Calculare the player's hand score and if goes bust then changes his status to loose
        /// </summary>
        /// <param name="player">state context</param>
        /// <returns>player's hand score</returns>
        public override int CalculateScore(Player player)
        {
            var score = base.CalculateScore(player);
            if (score > 21)
            {
                player.Status = new Lost(string.Format("{0} went bust",player.Name));
            }

            return score;
        }
        private static string GetPlayerName(Player player)
        {
            var playerName = player.Name;

            if (string.IsNullOrWhiteSpace(playerName))
            {
                playerName = player.GetType().Name;
            }
            return playerName;
        }
Exemple #3
0
        private static void DisplayCardsFor(Player player)
        {
            var prefix = GetPlayerName(player);
            Console.ResetColor();
            Console.WriteLine("{0} cards:", prefix);
            Console.ForegroundColor = ConsoleColor.Yellow;


            foreach (var card in player.Hand.VisibleCards)
            {
                Console.WriteLine(card);
            }

            Console.WriteLine("");
        }
Exemple #4
0
        private static string DisplayScoreAndTakePlayerAction(Player player)
        {
            Console.ResetColor();
            Console.WriteLine("{0} score is {1}, would you like to Take (H)it or (S)tay:",
                              GetPlayerName(player),
                              player.Score);

            var playerAction = Console.ReadLine();
            Console.WriteLine("");
            return playerAction;
        }
Exemple #5
0
 private static string GetPlayerName(Player player)
 {
     var prefix = "Dealer's";
     if (player is HumanPlayer)
     {
         prefix = "Your";
         if (!string.IsNullOrWhiteSpace(player.Name))
         {
             prefix = player.Name + "'s";
         }
     }
     return prefix;
 }