Esempio n. 1
0
        public void TestDealerPlayerStrategy()
        {
            Player p1 = new BJPlayer("Player1", new BJThresholdPlayerStrategy());
            Player p2 = new BJPlayer("Player2", new BJThresholdPlayerStrategy());
            Player p3 = new BJPlayer("Player3", new BJThresholdPlayerStrategy());

            List <Player> list = new List <Player>();

            list.Add(p1);
            list.Add(p2);

            Table table = new BJTable(list, p3);

            PlayerStrategy strategy = new BJDealerPlayerStrategy();

            Assert.AreEqual(true, strategy.IsWaitingForCard(p1, table), "Bad dealer strategy when 0.");

            p1.TakeCard(new Card(CardSuit.CLUBS, CardValue.ACE));

            Assert.AreEqual(false, strategy.IsWaitingForCard(p1, table), "Bad dealer strategy when 11.");

            p1.TakeCard(new Card(CardSuit.CLUBS, CardValue.ACE));

            Assert.AreEqual(false, strategy.IsWaitingForCard(p1, table), "Bad dealer strategy when 22");
        }
Esempio n. 2
0
        /// <summary>
        /// Calls Hit method and updates card image. Updates score. Calls CheckWin method.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnHit_Click(object sender, EventArgs e)
        {
            hitCounter = (int)ViewState["hitCounter"];

            pPanel.Visible = true;
            human          = (BJPlayer)Session["human"];
            deck           = (Deck)Session["deck"];
            blackjack      = (Blackjack)Session["game"];

            if (human.Hit(deck) == 1)
            {
                string imagePath = human.PlayerHand.CardsInHand.Last().Image;

                switch (hitCounter)
                {
                case 3:
                    pCard3.ImageUrl = imagePath;
                    hitCounter++;
                    pCard3.Visible = true;
                    break;

                case 4:
                    pCard4.ImageUrl = imagePath;
                    hitCounter++;
                    pCard4.Visible = true;
                    break;

                case 5:
                    pCard5.ImageUrl = imagePath;
                    hitCounter++;
                    pCard5.Visible = true;
                    break;

                default:
                    Response.Write("default case hit");
                    break;
                }

                ViewState["hitCounter"] = hitCounter;
            }
            else
            {
                lblResultMsg.Text    = "You can't hit anymore!";
                lblResultMsg.Visible = true;
            }
            pScore.Text = human.PlayerHand.HandValue.ToString();

            string message = blackjack.CheckWin(human.PlayerID);

            if (message != null)
            {
                lblResultMsg.Text    = message;
                lblResultMsg.Visible = true;
                btnHit.Enabled       = false;
                btnStand.Enabled     = false;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Enables hit/stand buttons, shows default blue for dealers 2nd card, deals new hand to both players, and
        /// updates the images associated with the cards dealt. Shows the score.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnNewGame_Click(object sender, EventArgs e)
        {
            btnHit.Enabled       = true;
            btnStand.Enabled     = true;
            lblResultMsg.Visible = false;
            pCard3.Visible       = false;
            pCard4.Visible       = false;
            pCard5.Visible       = false;

            dCard2.ImageUrl = "../images/cards/Card_Blue_Ver.png";
            dCard3.Visible  = false;
            dCard4.Visible  = false;
            dCard5.Visible  = false;

            deck            = new Deck();
            Session["deck"] = deck;

            dealer            = new Dealer("AI", null);
            Session["dealer"] = dealer;

            string playerName = playerDAO.GetNamebyEmail(Session["currentEmail"].ToString());
            int    pid        = playerDAO.GetIdByEmail(Session["currentEmail"].ToString());

            human            = new BJPlayer(pid, playerName, Session["currentEmail"].ToString());
            Session["human"] = human;

            blackjack       = new Blackjack(deck, dealer, human);
            Session["game"] = blackjack;

            ViewState["hitCounter"] = hitCounter;

            human.PlayerHand = blackjack.DealNewHand();
            human.PlayerHand.CheckAceAfterHit(human.PlayerHand.CardsInHand.Last());

            dealer.PlayerHand = blackjack.DealNewHand();
            dealer.PlayerHand.CheckAceAfterHit(dealer.PlayerHand.CardsInHand.Last());

            pCard1.ImageUrl = human.PlayerHand.CardsInHand.First().Image;
            pCard2.ImageUrl = human.PlayerHand.CardsInHand.ElementAt(1).Image;

            dCard1.ImageUrl = dealer.PlayerHand.CardsInHand.First().Image;

            pPanel.Visible = true;
            dPanel.Visible = true;

            dScore.Text = dealer.PlayerHand.CardsInHand.First().Number.ToString();
            pScore.Text = human.PlayerHand.HandValue.ToString();
        }
Esempio n. 4
0
 void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else if (Instance != this)
     {
         Destroy(gameObject);
     }
     if (Player.Instance != null)
     {
         DataBase = Player.Instance.BJDataBase;
     }
     //DontDestroyOnLoad(gameObject);
 }
Esempio n. 5
0
        /// <summary>
        /// Will trigger the dealer to call their Hit method. Updates score and image(s). Calls CheckWin method.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnStand_Click(object sender, EventArgs e)
        {
            deck               = (Deck)Session["deck"];
            dealer             = (Dealer)Session["dealer"];
            blackjack          = (Blackjack)Session["game"];
            human              = (BJPlayer)Session["human"];
            human.Stand        = true;
            human.TurnComplete = true;

            dealer.Hit(deck);
            dScore.Text = dealer.PlayerHand.HandValue.ToString();

            dCard2.ImageUrl = dealer.PlayerHand.CardsInHand.ElementAt(1).Image;

            if (dealer.PlayerHand.CardsInHand.Count > 2)
            {
                dCard3.ImageUrl = dealer.PlayerHand.CardsInHand.ElementAt(2).Image;
                dCard3.Visible  = true;
            }

            if (dealer.PlayerHand.CardsInHand.Count > 3)
            {
                dCard4.ImageUrl = dealer.PlayerHand.CardsInHand.ElementAt(3).Image;
                dCard4.Visible  = true;
            }

            if (dealer.PlayerHand.CardsInHand.Count > 4)
            {
                dCard5.ImageUrl = dealer.PlayerHand.CardsInHand.ElementAt(4).Image;
                dCard5.Visible  = true;
            }

            string message = blackjack.CheckWin(human.PlayerID);

            lblResultMsg.Text    = message;
            lblResultMsg.Visible = true;
            btnHit.Enabled       = false;
            btnStand.Enabled     = false;
        }
Esempio n. 6
0
 public static string PlaceBet(int value, BlackJackPlayer player, BlackJackDealer dealer, bool inGame)
 {
     currentMenu    = new Menu(new string[] { "Hit", "Stand", "Surrender" }, Draw.gameMenu, new Style(ConsoleColor.White, ConsoleColor.Black));
     BJDealer.Wager = value;
     BJDealer.HandleMoney(-value, BJPlayer);
     player.IsGaming = true;
     PutInBetBox(value);            // display the bet in the top right box
     dealer.ShuffleCards();         // the dealer shuffeles the card deck
     // display the current status
     inGame = player.CanBet(value); // chec to see if player has that amount of cache
     if (inGame)
     {
         dealer.DealCardToPlayer(player);                                                                                                         // dealer gives card to the player first card
         dealer.DealCardToPlayer(player);                                                                                                         // dealer gives card to the player second card
         BJDealer.DealCardHimself(false, BJPlayer.CountScore());                                                                                  // dealer deals himselfe one card
         Draw.ClearFrame(Draw.statusDisplay, new Style(ConsoleColor.White, ConsoleColor.Black));
         Draw.DrawTextInFrame(new string[] { "Money:" + BJPlayer.Money }, Draw.statusDisplay, new Style(ConsoleColor.White, ConsoleColor.Black)); // update the status
         //Draw.DrawHandResult(); // TODO: must be done
         int startScore = player.CountScore();
         if (startScore == int.MaxValue) // TODO fix bug when 21 on first hand
         {
             BJDealer.DealCardHimself(true, BJPlayer.CountScore());
             Control = dealer.CheckScore(BJPlayer);
             if (Control == "Player win")
             {
                 currentMenu.Position = 0;
                 currentMenu          = new Menu(new string[] { "Play Again", "To Main" }, Draw.gameMenu, new Style(ConsoleColor.White, ConsoleColor.Black));
                 Draw.ClearFrame(currentMenu.MenuFrame, new Style(ConsoleColor.White, ConsoleColor.Black));
                 Draw.ClearFrame(Draw.statusDisplay, new Style(ConsoleColor.White, ConsoleColor.Black));
                 Draw.DrawTextInFrame(new string[] { "Money:" + BJPlayer.Money }, Draw.statusDisplay, new Style(ConsoleColor.White, ConsoleColor.Black));
                 Draw.DrawMenu(currentMenu);
                 BJPlayer.ClearHand();
                 BJDealer.ClearHand();
                 Draw.DrawTextInFrame(Draw.youWon, Draw.table, new Style(ConsoleColor.Red, ConsoleColor.Black));
             }
         }
         inGame = player.CountScore() != -1;     // check for valid score
         if (inGame)
         {
             Draw.ClearFrame(currentMenu.MenuFrame, new Style(ConsoleColor.Black, ConsoleColor.Black));
             Draw.DrawMenu(currentMenu);
             return(currentMenu.CheckInput());
         }
         else
         {
             //TODO: clear the game
             player.ClearHand();
             dealer.ClearHand();
             Draw.ClearFrame(Draw.statusDisplay, new Style(ConsoleColor.White, ConsoleColor.Black));
             Draw.DrawTextInFrame(new string[] { "Money:" + BJPlayer.Money }, Draw.statusDisplay, new Style(ConsoleColor.White, ConsoleColor.Black));
             Draw.ClearFrame(Draw.betBox, new Style(ConsoleColor.Black, ConsoleColor.Black));
             Draw.DrawTextInFrame(Draw.youWon, Draw.betBox, new Style(ConsoleColor.White, ConsoleColor.Black));
             Draw.ClearFrame(currentMenu.MenuFrame, new Style(ConsoleColor.Black, ConsoleColor.Black));
             player.IsGaming = false;
             Draw.DrawMenu(currentMenu);
             return(currentMenu.CheckInput());
         }
     }
     else // here is a bug if wager is bigger than curent money, the game must clear and return to betting menu again to choose smaller bet, currently it draws the ingame menu.
     {
         Draw.ClearFrame(currentMenu.MenuFrame, new Style(ConsoleColor.Black, ConsoleColor.Black));
         Draw.DrawMenu(currentMenu);
         return(currentMenu.CheckInput());  // get control string from betting menu
     }
 }