Пример #1
0
        /// <summary>
        /// Deal a card or reset the deck on clicking the deck.
        /// </summary>
        private void pbDeck_Click(object sender, EventArgs e)
        {
            // If the deck is empty (no image)
            if (pbDeck.Image == null)
            {
                // Reset the dealer
                ResetDealer();
            }
            else
            {   // Otherwise
                // Create a new card
                PlayingCard card = new PlayingCard();
                // Draw a card from the card dealer. If it worked...
                if (myDealer.DrawCard(ref card, true))
                {
                    // Create a new CardBox control based on the card drawn
                    CardBox aCardBox = new CardBox(card);
                    // Wire events handlers to the new control:
                    // if Click radio button is checked...
                    if (optClick.Checked)
                    {
                        // Wire CardBox_Click
                        aCardBox.Click += CardBox_Click;
                    }
                    else // otherwise...
                    {
                        // wire CardBox_MouseDown, CardBox_DragEnter, and CardBox_DragDrop
                        aCardBox.MouseDown += CardBox_MouseDown;
                        aCardBox.DragEnter += CardBox_DragEnter;
                        aCardBox.DragDrop  += CardBox_DragDrop;
                    }

                    aCardBox.MouseEnter += CardBox_MouseEnter; // wire CardBox_MouseEnter for the "POP" visual effect
                                                               // wire CardBox_MouseLeave for the regular visual effect
                    aCardBox.MouseLeave += CardBox_MouseLeave;

                    // Add the new control to the appropriate panel
                    pnlPlayer1.Controls.Add(aCardBox);
                    // Realign the controls in the panel so they appear correctly.
                    RealignCards(pnlPlayer1);
                }
            }
            // Display the number of cards remaining in the deck.
            lblCardCount.Text = myDealer.CardsRemaining.ToString();
        }