private void ShowHand(Panel aPanel, Hand aHand) { aPanel.Controls.Clear(); Card aCard; Button aButton; for (int i = 0; i < aHand.Count; i++) { aCard = aHand[i]; //Make the button and add it to the form. aButton = new Button(); aPanel.Controls.Add(aButton); //Modify the appearance. aButton.Image = (Image)m_icons[aCard.Suit]; aButton.Text = aCard.FaceValue.ToString(); aButton.TextAlign = ContentAlignment.BottomCenter; aButton.ForeColor = Color.Red; aButton.ImageAlign = ContentAlignment.TopCenter; aButton.FlatStyle = FlatStyle.Flat; aButton.Height = 40; //Locate the button on the panel. aButton.Top = 45 * i; //Save the associated card. aButton.Tag = aCard; //Add a MouseDown event to the new button. aButton.MouseDown += new System.Windows.Forms.MouseEventHandler(ButtonMouseDown); } }
public void Deal(Hand[] hands) { int handIndex = 0; while (m_cards.Count > 0) { hands[handIndex].Add((Card)m_cards[0]); m_cards.RemoveAt(0); handIndex = (handIndex == hands.Length - 1 ? 0 : handIndex + 1); } }
private void SetUp() { Deck aDeck = new Deck(new Suit[] {Suit.Clubs, Suit.Diamonds}, new FaceValue[] {FaceValue.King, FaceValue.Queen, FaceValue.Jack, FaceValue.Ten}); aDeck.Shuffle(); m_Hand1 = new Hand(); m_Hand2 = new Hand(); aDeck.Deal(new Hand[]{m_Hand1, m_Hand2}); ShowHand(panel1, m_Hand1); ShowHand(panel2, m_Hand2); }