Ejemplo n.º 1
0
        void player_ActionRequested(Player player, BlackJackHand hand)
        {
            bool blnInvalidInput = false;
            do
            {
                PrintToConsole(String.Format("Please Select Action:\n\t 1. Hit\n\t 2. Stand\n\t 3. Double{0}\n\t 9. Surrender", (hand.IsSplittingAllowed ? "\n\t 4. Split" : "")), null);

                Console.Write("Input : ");

                string strInput = Console.ReadLine();
                int intInput = 0;

                Int32.TryParse(strInput, out intInput);

                blnInvalidInput = false;

                switch (intInput)
                {
                    case 1:
                        player.Hit(hand);
                        break;
                    case 2:
                        player.Stand(hand);
                        break;
                    case 3:
                        player.Double(hand);
                        break;
                    case 4:
                        player.Split(hand);
                        break;
                    case 9:
                        player.Surrender(hand);
                        break;
                    default:
                        // Either non-numeric input or invalid option.
                        {
                            PrintToConsole("Invalid Option. Please enter valid option.\n", ConsoleColor.Red);

                            blnInvalidInput = true;
                        }
                        break;
                }
            } while (blnInvalidInput);

            ////Update score on screen if player's turn is not getting over.
            ////When player's turn is over, dealer will trigger score updated trigger.
            //if (hand.HandStatus == BlackJackHand.HandStatusTypes.None || (hand != player.SplittedHand && player.SplittedHand != null))
            //{
            //    PrintToConsole(dealer.GetScoreCard(), null);
            //}
        }
Ejemplo n.º 2
0
        public void NewGameTest()
        {
            Player player = new Player("Test Player");

            dealer.RegisterPlayer(player);
            Player[] players = dealer.GetPlayers();
            Assert.AreEqual(players.Length, 1);
            Assert.AreSame(players[0], player);
            Assert.AreSame(players[0].GetDealer(), dealer);

            dealer.NewGame();
            Assert.AreEqual(dealer.Hand.GetCards().Length, 0);
            Assert.AreEqual(player.Hand.GetCards().Length, 0);
            Assert.AreEqual(dealer.Hand.HandStatus, BlackJackHand.HandStatusTypes.None);
            Assert.AreEqual(player.Hand.HandStatus, BlackJackHand.HandStatusTypes.None);
            Assert.AreEqual(dealer.Hand.HandValue, 0);
            Assert.AreEqual(player.Hand.HandValue, 0);

            Assert.IsNull(player.SplittedHand);
        }
Ejemplo n.º 3
0
        void PlayGame()
        {
            try
            {
                dealer = new Dealer();
                dealer.UpdateScoreBoard += dealer_UpdateScoreBoard;
                dealer.GameOver += dealer_GameOver;

                player = new Player("Rumit");
                player.ActionRequested += player_ActionRequested;
                dealer.RegisterPlayer(player);

                bool blnReplay = false;
                do
                {
                    dealer.NewGame();

                    dealer.StartPlay();

                    Console.Write("Want to replay? ('y' to replay, any other character to exit.) : ");
                    string strReplayInput = Console.ReadLine();
                    blnReplay = (strReplayInput.Equals("y", StringComparison.InvariantCultureIgnoreCase));
                } while (blnReplay);
            }
            catch (Exception ex)
            {
                PrintExceptionTrace(ex);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Registers player with dealer.
 /// </summary>
 public void RegisterPlayer(Player player)
 {
     if (!players.Contains(player))
     {
         players.Add(player);
         player.RegisterToDealer(this);
     }
     else
     {
         throw new PlayerRegistrationFailedException("Player already registered for this game.");
     }
 }