Ejemplo n.º 1
0
        internal void Button_Cliked(object sender, EventArgs e)
        {
            BoardButton currentButton = sender as BoardButton;

            if (currentButton != null)
            {
                if (currentButton.BackColor != Color.CornflowerBlue)
                {
                    currentButton.BackColor = Color.CornflowerBlue;
                    if (m_SourceCell == null)
                    {
                        m_SourceCell = currentButton.BoardLocation;
                    }
                }
                else
                {
                    currentButton.BackColor = Color.Empty;
                    m_SourceCell            = null;
                }

                if (m_SourceCell != null && !m_SourceCell.Value.Equals(currentButton.BoardLocation))
                {
                    m_DestnationCell = currentButton.BoardLocation;
                    OnBoardMove(m_SourceCell.Value, m_DestnationCell.Value);
                }
            }
        }
Ejemplo n.º 2
0
        internal void InitializeBoardButtons()
        {
            int ButtonSize  = m_BoardForm.ClientSize.Width / r_SizeOfBoard;
            int LabelsSpace = m_LabelPlayer1.Top + m_LabelPlayer1.Height;

            m_BoardButtons = new BoardButton[r_SizeOfBoard, r_SizeOfBoard];

            for (int i = 0; i < r_SizeOfBoard; i++)
            {
                for (int j = 0; j < r_SizeOfBoard; j++)
                {
                    if (i < ((r_SizeOfBoard / 2) - 1) && (i + j) % 2 != 0)
                    {
                        BoardButton player1Button = new BoardButton(new Location(i, j));
                        player1Button.Width  = ButtonSize;
                        player1Button.Height = ButtonSize;
                        player1Button.Left   = j * ButtonSize;
                        player1Button.Top    = (i * ButtonSize) + LabelsSpace;
                        player1Button.Click += Button_Cliked;
                        player1Button.Image  = Resources.Pawn__Black_;
                        m_BoardForm.Controls.Add(player1Button);
                        m_BoardButtons[i, j] = player1Button;
                    }
                    else if (i >= ((r_SizeOfBoard / 2) + 1) && (i + j) % 2 != 0)
                    {
                        BoardButton player2Button = new BoardButton(new Location(i, j));
                        player2Button.Width  = ButtonSize;
                        player2Button.Height = ButtonSize;
                        player2Button.Left   = j * ButtonSize;
                        player2Button.Top    = (i * ButtonSize) + LabelsSpace;
                        player2Button.Click += Button_Cliked;
                        player2Button.Image  = Resources.Pawn__Red_;
                        m_BoardForm.Controls.Add(player2Button);
                        m_BoardButtons[i, j] = player2Button;
                    }
                    else
                    {
                        BoardButton buttonOfEmptyPlace = new BoardButton(new Location(i, j));
                        buttonOfEmptyPlace.Text   = string.Empty;
                        buttonOfEmptyPlace.Width  = ButtonSize;
                        buttonOfEmptyPlace.Height = ButtonSize;
                        buttonOfEmptyPlace.Left   = j * ButtonSize;
                        buttonOfEmptyPlace.Top    = (i * ButtonSize) + LabelsSpace;

                        if ((i + j) % 2 == 0)
                        {
                            buttonOfEmptyPlace.BackColor = Color.Gray;
                            buttonOfEmptyPlace.Enabled   = false;
                        }
                        else
                        {
                            buttonOfEmptyPlace.Click += Button_Cliked;
                        }

                        m_BoardForm.Controls.Add(buttonOfEmptyPlace);
                        m_BoardButtons[i, j] = buttonOfEmptyPlace;
                    }
                }
            }
        }