Example #1
0
        private void initializeButtonBoard()
        {
            for (int row = 0; row < m_ControlPanel.BoardSize; row++)
            {
                for (int col = 0; col < m_ControlPanel.BoardSize; col++)
                {
                    m_ButtonBoard[row, col]        = new SquareButton(row, col);
                    m_ButtonBoard[row, col].Click += squareButton_Click;
                    m_ButtonBoard[row, col].Font   = new Font("Consolas", 12.0F);

                    if ((row + col) % 2 == 0)
                    {
                        m_ButtonBoard[row, col].BackColor    = Color.Gray;
                        m_ButtonBoard[row, col].DefaultColor = Color.Gray;
                        m_ButtonBoard[row, col].Enabled      = false;
                    }
                    else
                    {
                        m_ControlPanel.Board.GetSquareByPosition(row, col).SquarePawnChanged += setButton_SquarePawnChanged;
                        m_ButtonBoard[row, col].BackColor    = Color.White;
                        m_ButtonBoard[row, col].DefaultColor = Color.White;
                    }

                    if (!m_ControlPanel.Board.GetSquareByPosition(row, col).IsEmpty())
                    {
                        setButtonTextByPlayerID(m_ButtonBoard[row, col]);
                    }
                }
            }
        }
Example #2
0
        private void squareButton_Click(object sender, EventArgs e)
        {
            SquareButton buttonClicked = sender as SquareButton;

            if (buttonClicked == lastClickedButton)
            {
                onSameButtonClicked(buttonClicked);
            }
            else
            {
                if (m_isPawnOnBoardSelected)
                {
                    bool isValidJump = m_ControlPanel.TryToExecuteJump(
                        lastClickedButton.Row,
                        lastClickedButton.Col,
                        buttonClicked.Row,
                        buttonClicked.Col);

                    if (!isValidJump)
                    {
                        MessageBox.Show("Invalid jump", "Error", MessageBoxButtons.OK);
                    }

                    m_isPawnOnBoardSelected = false;
                    lastClickedButton       = null;
                    gameManager();
                }
                else
                {
                    onPawnSelect(buttonClicked);
                }
            }
        }
Example #3
0
 private void computerTurnDelay_Tick(object sender, EventArgs e)
 {
     m_ComputerTurnDelay.Stop();
     m_ControlPanel.ComputerJump();
     gameManager();
     lastClickedButton = null;
 }
Example #4
0
        private void setButtonTextByPlayerID(SquareButton i_SquareButton)
        {
            ePawnType pawnType = m_ControlPanel.Board.GetPawnByPosition(i_SquareButton.Row, i_SquareButton.Col).Type;
            ePlayerID playerID = m_ControlPanel.Board.GetPawnByPosition(i_SquareButton.Row, i_SquareButton.Col).Belong;

            if (playerID == ePlayerID.Player1)
            {
                if (pawnType == ePawnType.Regular)
                {
                    i_SquareButton.Text = "O";
                }
                else
                {
                    i_SquareButton.Text = "U";
                }
            }
            else
            {
                if (pawnType == ePawnType.Regular)
                {
                    i_SquareButton.Text = "X";
                }
                else
                {
                    i_SquareButton.Text = "K";
                }
            }
        }
Example #5
0
 private void setPlayerPawnButtonsEnabled(ePlayerID i_PlayerID, bool i_Enabled)
 {
     foreach (Square square in m_ControlPanel.GetPawnListSquares(i_PlayerID))
     {
         SquareButton button = m_ButtonBoard[square.Row, square.Col];
         setButton(button, i_Enabled);
     }
 }
Example #6
0
        private void onSameButtonClicked(SquareButton i_ButtonClicked)
        {
            ePlayerID notActivePlayer = getNotActivePlayer();

            setAllButtonsEnabled(true);
            i_ButtonClicked.BackColor = i_ButtonClicked.DefaultColor;
            setPlayerPawnButtonsEnabled(notActivePlayer, false);
            m_isPawnOnBoardSelected = false;
            lastClickedButton       = null;
        }
Example #7
0
 private void onPawnSelect(SquareButton i_ButtonClicked)
 {
     lastClickedButton = i_ButtonClicked;
     setAllButtonsEnabled(true);
     setPlayerPawnButtonsEnabled(m_ControlPanel.ActivePlayer.ID, false);
     i_ButtonClicked.Enabled   = true;
     i_ButtonClicked.BackColor = Color.CornflowerBlue;
     m_isPawnOnBoardSelected   = true;
     setPawnPossibleButtonsColored(m_ControlPanel.Board.GetPawnByPosition(i_ButtonClicked.Row, i_ButtonClicked.Col));
 }
Example #8
0
        private void setButton_SquarePawnChanged(Square i_Square)
        {
            SquareButton button = m_ButtonBoard[i_Square.Row, i_Square.Col];

            if (i_Square.IsEmpty())
            {
                button.Text = string.Empty;
            }
            else
            {
                setButtonTextByPlayerID(button);
            }
        }
Example #9
0
        private void setButton_PawnTypeChanged(Pawn i_Pawn)
        {
            SquareButton button = m_ButtonBoard[i_Pawn.OnSquare.Row, i_Pawn.OnSquare.Col];

            if (i_Pawn.Belong == ePlayerID.Player1)
            {
                button.Text = "U";
            }
            else
            {
                button.Text = "K";
            }
        }
Example #10
0
 private void setButton(SquareButton i_Button, bool i_Enabled)
 {
     i_Button.Enabled   = i_Enabled;
     i_Button.BackColor = i_Button.DefaultColor;
     i_Button.Font      = new Font("Consolas", 12.0F, i_Enabled ? FontStyle.Bold : FontStyle.Regular);
 }