예제 #1
0
        public Hand NewHand()
        {
            var newHand = new Hand(this);
            Hands = new List<Hand> { newHand };

            return newHand;
        }
예제 #2
0
        public void Split()
        {
            var rank = Cards.First().Rank;
            if (rank == Rank.Jack || rank == Rank.Queen || rank == Rank.King)
            {
                rank = Rank.Ten;
            }

            if (Cards.Count == 2 && Cards.All(card => {
                var adjustedRank = card.Rank;

                if (card.Rank == Rank.Jack || card.Rank == Rank.Queen || card.Rank == Rank.King)
                {
                    adjustedRank = Rank.Ten;
                }

                return adjustedRank == rank;
            }))
            {
                var splitCard = Cards.First();
                var splitHand = new Hand(Player);

                splitHand.Cards.Add(splitCard);
                Player.Hands.Add(splitHand);

                Cards.Remove(splitCard);

                splitHand.IncreaseBet(Bet);
                Player.Balance = Player.Balance - (splitHand.Bet / 2);
            }
            else
            {
                throw new Exception("Cards must be of equal value to split.");
            }
        }
예제 #3
0
        private static void DisplayHand(Hand hand, string name)
        {
            var handString = string.Format("{0} Hand: {1}", name, string.Join(" ", hand.Cards.Select(CardString)));
            var betString = string.Empty;
            var totalString = string.Empty;

            if (hand.Bet > 0)
            {
                betString = string.Format("Bet: {0}", hand.Bet);
                totalString = string.Format("Total: {0}", hand.GetSumOfHand());
            }

            Console.WriteLine("{0} {1} {2}", handString, betString, totalString);
        }
예제 #4
0
        private static void GetPlayerInput(Hand hand)
        {
            try
            {
                var key = Console.ReadKey();
                Console.WriteLine();

                switch (key.Key)
                {
                    case ConsoleKey.H:
                        hand.Hit();
                        if (!hand.HasBust())
                            PlayHand(hand);
                        break;
                    case ConsoleKey.S:
                        break;
                    case ConsoleKey.D:
                        hand.DoubleDown();
                        if (!hand.HasBust())
                            PlayHand(hand);
                        break;
                    case ConsoleKey.P:
                        hand.Split();
                        PlayHand(hand);
                        break;
                    case ConsoleKey.Escape:
                        break;
                }

                Console.WriteLine();

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine();
                GetPlayerInput(hand);
            }
        }
예제 #5
0
        private static void PlayHand(Hand playerHand)
        {
            Console.WriteLine();
            DisplayHand(playerHand, "Player");
            Console.WriteLine();

            Console.WriteLine("[H]it [S]tand [D]ouble-Down s[P]lit");
            GetPlayerInput(playerHand);
        }