Example #1
0
        private void Populate()
        {
            CardFace[] faces = { CardFace.Ace,  CardFace.King,  CardFace.Queen, CardFace.Jack, CardFace.Ten,
                                 CardFace.Nine, CardFace.Eight, CardFace.Seven, CardFace.Six,  CardFace.Five,
                                 CardFace.Four, CardFace.Three, CardFace.Two };
            CardSuit[] suits = { CardSuit.Clubs, CardSuit.Diamonds, CardSuit.Hearts, CardSuit.Spades };

            int topPosition  = 0;
            int leftPosition = 0;

            foreach (CardSuit suit in suits)
            {
                foreach (CardFace face in faces)
                {
                    CardButton button = CreateCardButton(face, suit);
                    button.Location = new System.Drawing.Point(leftPosition, topPosition);

                    this.Controls.Add(button);

                    topPosition += BUTTON_SIZE;
                }

                leftPosition += BUTTON_SIZE;
                topPosition   = 0;
            }
        }
        private void Populate()
        {
            CardFace[] faces = { CardFace.Ace,  CardFace.King,  CardFace.Queen, CardFace.Jack, CardFace.Ten,
                                 CardFace.Nine, CardFace.Eight, CardFace.Seven, CardFace.Six,  CardFace.Five,
                                 CardFace.Four, CardFace.Three, CardFace.Two };
            int        topPosition  = 0;
            int        leftPosition = 0;

            for (int i = 0; i < faces.Count <CardFace>(); i++)
            {
                CardFace f1 = faces[i];

                // Save the top and left position of the current line being created
                int lineTopPosition  = topPosition;
                int lineLeftPosition = leftPosition;

                for (int j = i; j < faces.Count <CardFace>(); j++)
                {
                    CardFace f2 = faces[j];

                    // Suited
                    CardButton suitedButton = CreateCardButton(f1, f2, true);
                    suitedButton.Location = new System.Drawing.Point(leftPosition, topPosition);

                    // Moving to the right
                    leftPosition += BUTTON_SIZE;

                    if (f1 == f2)
                    {
                        suitedButton.BackColor = System.Drawing.Color.LightBlue;
                    }
                    else
                    {
                        suitedButton.BackColor = System.Drawing.Color.LightGreen;
                    }
                    this.Controls.Add(suitedButton);
                }

                leftPosition = lineLeftPosition;

                for (int j = i; j < faces.Count <CardFace>(); j++)
                {
                    CardFace f2 = faces[j];

                    // Offsuit
                    CardButton offsuitedButton = CreateCardButton(f1, f2, false);
                    offsuitedButton.Location = new System.Drawing.Point(leftPosition, topPosition);

                    // Moving to the bottom
                    topPosition += BUTTON_SIZE;

                    offsuitedButton.BackColor = System.Drawing.Color.LightSalmon;
                    this.Controls.Add(offsuitedButton);
                }

                topPosition  = lineTopPosition + BUTTON_SIZE;
                leftPosition = lineLeftPosition + BUTTON_SIZE;
            }
        }
        private CardButton CreateCardButton(CardFace f1, CardFace f2, bool suited)
        {
            CardButton button = new CardButton();

            button.HoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
            button.Selected = false;
            button.SelectedColor = System.Drawing.Color.Yellow;
            button.Size = new System.Drawing.Size(BUTTON_SIZE, BUTTON_SIZE);
            button.TabIndex = 0;

            String value;
            if (suited) value = HoldemHand.ConvertToString(f1, CardSuit.Clubs, f2, CardSuit.Clubs);
            else value = HoldemHand.ConvertToString(f1, CardSuit.Clubs, f2, CardSuit.Diamonds);

            button.Name = "btn" + value;
            button.Value = value;

            return button;
        }
Example #4
0
        private CardButton CreateCardButton(CardFace face, CardSuit suit)
        {
            CardButton button = new CardButton();

            button.HoverColor    = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
            button.Selected      = false;
            button.SelectedColor = System.Drawing.Color.Yellow;
            button.Size          = new System.Drawing.Size(BUTTON_SIZE, BUTTON_SIZE);
            button.TabIndex      = 0;

            // Make sure the suit is lower cased
            String value = Card.CardFaceToChar(face) + new String(Card.CardSuitToChar(suit), 1).ToLower();

            button.Name   = "btn" + value;
            button.Value  = value;
            button.Click += new EventHandler(button_Click);

            return(button);
        }
Example #5
0
        void button_Click(object sender, EventArgs e)
        {
            CardButton button = (CardButton)sender;

            if (button.Selected)
            {
                if (CardSelected != null)
                {
                    CardSelected(button.Value);
                }
            }
            else
            {
                if (CardDeselected != null)
                {
                    CardDeselected(button.Value);
                }
            }
        }
Example #6
0
        private CardButton CreateCardButton(CardFace face, CardSuit suit)
        {
            CardButton button = new CardButton();

            button.HoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
            button.Selected = false;
            button.SelectedColor = System.Drawing.Color.Yellow;
            button.Size = new System.Drawing.Size(BUTTON_SIZE, BUTTON_SIZE);
            button.TabIndex = 0;

            // Make sure the suit is lower cased
            String value = Card.CardFaceToChar(face) + new String(Card.CardSuitToChar(suit), 1).ToLower();
            button.Name = "btn" + value;
            button.Value = value;
            button.Click += new EventHandler(button_Click);

            return button;
        }