示例#1
0
        // Private Methods
        // Setup first time board settings
        private void initBoardSettings(Board i_Board)
        {
            m_SquareButtons = new SquareButton[i_Board.Size, i_Board.Size];
            for (int row = 0; row < i_Board.Size; row++)
            {
                for (int col = 0; col < i_Board.Size; col++)
                {
                    m_SquareButtons[row, col] = new SquareButton(row, col)
                    {
                        Width = 60, Height = 60, Left = col * 60, Top = (row + 1) * 60, TabStop = false, Font = new Font("Arial", 24, FontStyle.Bold)
                    };
                    if ((row % 2 == 0 && col % 2 != 0) || (row % 2 != 0 && col % 2 == 0))
                    {
                        m_SquareButtons[row, col].SquareClicked += squareClicked;
                        m_SquareButtons[row, col].BackColor      = Color.BurlyWood;
                        m_Game.Board.GameBoard[row, col].CurrentPieceChanged += updateSquareSymbol;
                    }
                    else
                    {
                        m_SquareButtons[row, col].BackColor = Color.SaddleBrown;
                        m_SquareButtons[row, col].Enabled   = false;
                    }

                    this.Controls.Add(m_SquareButtons[row, col]);
                }
            }
        }
示例#2
0
        // Starts building a move according to chosen square
        private void squareClicked(SquareButton i_SquareButton)
        {
            string currentSquareLocationString;
            Square square        = m_Game.Board.GameBoard[i_SquareButton.RowIndex, i_SquareButton.ColIndex];
            Piece  pieceAtSquare = square.CurrentPiece;

            // First click- build the move's starting position
            if (m_CurrentMove.ToString() == string.Empty && pieceAtSquare != null)
            {
                if (pieceAtSquare.Side == m_Game.CurrentPlayer.Side)
                {
                    i_SquareButton.BackColor    = Color.Cyan;
                    currentSquareLocationString = MoveValidator.ConvertLocationToString(
                        i_SquareButton.RowIndex,
                        i_SquareButton.ColIndex);
                    m_CurrentMove.Append(currentSquareLocationString);
                    m_SelectedSquare = i_SquareButton;
                }
            }
            // Second click- add the move's ending position and execute it
            else if (m_CurrentMove.ToString() != string.Empty && pieceAtSquare == null)
            {
                m_SelectedSquare.BackColor  = Color.BurlyWood;
                currentSquareLocationString = MoveValidator.ConvertLocationToString(
                    i_SquareButton.RowIndex,
                    i_SquareButton.ColIndex);
                m_CurrentMove.Append(">");
                m_CurrentMove.Append(currentSquareLocationString);
                Move selectedMove = MoveValidator.ConvertStringToMove(m_CurrentMove.ToString());
                m_Game.ExecuteMove(selectedMove);
                m_CurrentMove.Clear();
            }
            // Second click on the same square- cancel the chosen square (reset the move)
            else if (pieceAtSquare != null && pieceAtSquare == m_Game.Board.GameBoard[m_SelectedSquare.RowIndex, m_SelectedSquare.ColIndex].CurrentPiece)
            {
                m_SelectedSquare.BackColor = Color.BurlyWood;
                m_SelectedSquare           = null;
                m_CurrentMove.Clear();
            }
        }