Esempio n. 1
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. 2
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;
        }