示例#1
0
        private void Button1_Click(object sender, EventArgs e)                   //button click of fsw picture "deal button"
        {
            aCard = deckOfCards.GetNextCard();                                   //gets the next card from the deck with getter method
            dealer.DealACardtoMe(aCard);                                         //puts the card into the dealers hand with the deal a card method
            button2.Image = aCard.getCardImage();                                //gets the image for the card drawn from the deck and places it on button 2
            label2.Text   = "" + aCard.GetCardValue();                           //displays the value of the card drawn into the label 2
            label13.Text  = "Dealers total showing = " + dealer.GetTotalValue(); // shows the total of all cards, in this case just the first card

            aCard = deckOfCards.GetNextCard();                                   // this block repeats the same as the first just leaving out the total value to avoid
            dealer.DealACardtoMe(aCard);                                         //showing the player the dealers hand
            aCardBack       = aCard.getCardImage();                              //this stores the card for button 5 till the end of the game
            label1.Text     = "" + aCard.GetCardValue();
            button5.Visible = true;
            //updateDealerGraphics(dealer.GetNumberofCards());

            aCard = deckOfCards.GetNextCard(); // repeats process of dealer cards
            player.DealACardtoMe(aCard);
            button3.Image = aCard.getCardImage();
            label8.Text   = "" + aCard.GetCardValue();

            aCard = deckOfCards.GetNextCard();
            player.DealACardtoMe(aCard);
            button6.Image = aCard.getCardImage();
            label9.Text   = "" + aCard.GetCardValue();
            label5.Text   = "Your total = " + player.GetTotalValue(); //shows players total
            gameLoaded();
            button1click++;                                           //counter for the button to reset game if purple "deal" button is hit again
            checkBlackJack();
            if (player.checkBlackJack() || dealer.checkBlackJack())
            {
                button5.Image  = aCardBack;
                label1.Visible = true;
                label13.Text   = "Dealers total = " + dealer.GetTotalValue();
                if (player.checkBlackJack())
                {
                    if (betamt > 0)
                    {
                        money.WonBet();
                        money.GetTotalMoney();
                        label19.Text = money.GetTotalMoney().ToString();
                    }
                    playerWinMessage();
                }
                else if (dealer.checkBlackJack())
                {
                    if (betamt > 0)
                    {
                        money.GetTotalMoney();
                        label19.Text = money.GetTotalMoney().ToString();
                    }
                    dealerWinMessage();
                }
                else
                {
                    if (betamt > 0)
                    {
                        money.setdraw();
                        money.GetTotalMoney();
                        label19.Text = money.GetTotalMoney().ToString();
                    }
                    drawMessage();
                }
            }


            switch (button1click) //switch statement to reset the game
            {
            case 1:
                break;     //ignores first click

            case 2:
                reset();
                Button1_Click(null, null);
                break;
            }
        }