コード例 #1
0
        private void initializeButtons()
        {
            m_ButtonBoard = new CheckersButton[m_GameSettingsForm.BoardSize, m_GameSettingsForm.BoardSize];
            CheckersButton checkersButton;
            bool           aLeagalSquare;

            for (int i = 0; i < m_GameSettingsForm.BoardSize; i++)
            {
                for (int j = 0; j < m_GameSettingsForm.BoardSize; j++)
                {
                    checkersButton          = new CheckersButton(i, j);
                    checkersButton.Size     = new Size(50, 50);
                    checkersButton.Location = new Point(50 + j * 50, 50 + i * 50);
                    aLeagalSquare           = (checkersButton.RowInBoard + checkersButton.ColInBoard) % 2 == 1;
                    if (!aLeagalSquare)
                    {
                        checkersButton.BackColor = Color.Gray;
                    }
                    else
                    {
                        checkersButton.BackColor = Color.Empty;
                    }

                    checkersButton.Click += new EventHandler(buttonFromBoard_Click);
                    m_ButtonBoard[i, j]   = checkersButton;
                    Controls.Add(checkersButton);
                }
            }
        }
コード例 #2
0
        private void buttonFromBoard_Click(object sender, EventArgs e)
        {
            CheckersButton clickedButton = sender as CheckersButton;

            if (clickedButton != null)
            {
                if (clickedButton.BackColor == Color.Gray)
                {
                    goto End;
                }

                if (!m_AButttonIsPressed)
                {
                    m_AButttonIsPressed     = true;
                    clickedButton.BackColor = Color.SkyBlue;
                    m_ButtonPressed         = clickedButton;
                    goto End;
                }

                if (m_ButtonPressed == clickedButton)
                {
                    clickedButton.BackColor = Color.Empty;
                    m_AButttonIsPressed     = false;
                    goto End;
                }

                Move move = twoButtonsToAMove(clickedButton);
                if (!m_Board.Play(move))
                {
                    MessageBox.Show("Illegal Move!");
                }

                handleGameOverAndRematch();

                m_AButttonIsPressed       = false;
                m_ButtonPressed.BackColor = Color.Empty;
                if (!m_GameSettingsForm.MultiplayerMode)
                {
                    if (m_Board.Turn == Square.O)
                    {
                        m_Board.ComputerPlay();
                    }
                }

                handleGameOverAndRematch();
                syncButtonBoardWithLogicalBoard();
            }

            End :;
        }
コード例 #3
0
 private Move twoButtonsToAMove(CheckersButton i_Button)
 {
     return(new Move(m_ButtonPressed.RowInBoard, m_ButtonPressed.ColInBoard, i_Button.RowInBoard, i_Button.ColInBoard));
 }