public void initUIBoard(int i_BoardSize) { Point anchor = new Point(k_SquareSize / 2, k_SquareSize); m_BoardButtons = new BoardButton[i_BoardSize, i_BoardSize]; for (int i = 0; i < i_BoardSize; i++) { for (int j = 0; j < i_BoardSize; j++) { m_BoardButtons[i, j] = new BoardButton(i, j); BoardButton currentButton = m_BoardButtons[i, j]; currentButton.Location = new Point( anchor.X + (j * currentButton.Width), anchor.Y + (i * currentButton.Height)); this.Controls.Add(currentButton); currentButton.Click += new EventHandler(currentButton_Click); } } m_Engine.Checkers.Board.ClearLogicBoard(); m_Engine.ResetGame(); }
private void updateDestinationButtonsAvailability(BoardButton i_BoardButton) { foreach (BoardButton button in m_SquareButtons) { if (button.Active) { button.Enabled = true; } } }
private void currentButton_Click(object sender, EventArgs e) { bool enable = true; BoardButton button = sender as BoardButton; m_Engine.SourceCoordinate = button.Coordinate; if (button.Enabled) { // Unselect the current Coin if (m_Engine.SourceCoordinate.Equals(m_Engine.LastCoordinate)) { button.BackColor = Color.White; ChangeAvailableCoordinatesColor(button, Color.White); changeOtherCoinsAvailability(button, enable); m_Engine.ResetCoordinates(); } else { if (m_Engine.LastCoordinate == null) { m_Engine.LastCoordinate = m_Engine.SourceCoordinate; button.BackColor = Color.LightBlue; ChangeAvailableCoordinatesColor(button, Color.Chocolate); changeOtherCoinsAvailability(button, !enable); } else { m_Engine.TargetCoordinate = button.Coordinate; BoardButton sourceButton = getButtonFromBoard(m_Engine.LastCoordinate); ChangeAvailableCoordinatesColor(sourceButton, Color.White); changeOtherCoinsAvailability(sourceButton, enable); sourceButton.BackColor = Color.White; if (!m_Engine.GameOver() && !(m_Engine.CurrentPlayer is Computer)) { MakeCurrentPlayerCoinsDisabled(); m_Engine.TakeMoveFromPlayer(); m_Engine.SwitchTurnsIfNecessary(); m_Engine.ResetCoordinates(); } if (!m_Engine.GameOver() && m_Engine.CurrentPlayer is Computer) { MakeCurrentPlayerCoinsDisabled(); m_Engine.TakeMoveFromPlayer(); m_Engine.SwitchTurnsIfNecessary(); m_Engine.ResetCoordinates(); m_Engine.GameOver(); } } } } }
private void handleProgressiveMove(BoardButton i_BoardButton) { i_BoardButton.BackColor = System.Drawing.Color.LightGoldenrodYellow; m_SquareButtons[m_SourceSquare.Position.y, m_SourceSquare.Position.x].BackColor = System.Drawing.Color.LightGoldenrodYellow; m_SourceSquare = null; assignMenToButtons(); updateSourceButtonsAvailability(); chooseDestinationSquare(i_BoardButton); i_BoardButton.BackColor = System.Drawing.Color.Firebrick; i_BoardButton.Enabled = false; }
private void handleMoveRequest(BoardButton i_BoardButton) { if (m_Game.IsLegalMove(m_SourceSquare, m_Game.Board.GetSquare(i_BoardButton.Position.y, i_BoardButton.Position.x))) { makeAMoveProcess(i_BoardButton); } else { MessageBox.Show("Illegal Move."); } }
private void addSquare(int i_RowPosition, int i_ColPosition) { BoardButton button = new BoardButton(i_RowPosition, i_ColPosition); button.Left = 6 + (i_ColPosition * 62); button.Top = 32 + (i_RowPosition * 62); button.Size = new System.Drawing.Size(62, 62); button.Click += new System.EventHandler(boardButton_Click); button.Enabled = false; this.Controls.Add(button); m_SquareButtons[i_RowPosition, i_ColPosition] = button; }
private void endUserChoise(BoardButton i_BoardButton) { i_BoardButton.BackColor = System.Drawing.Color.LightGoldenrodYellow; m_SquareButtons[m_SourceSquare.Position.y, m_SourceSquare.Position.x].BackColor = System.Drawing.Color.LightGoldenrodYellow; m_SourceSquare = null; assignMenToButtons(); updateSourceButtonsAvailability(); if (m_Game.ActiveTeam.Type == Team.eTeamType.Computer) { makeComputerMove(); } }
// $G$ CSS-013 (-5) Bad input variable name (should be in the form of i_PascalCased) private void changeOtherCoinsAvailability( BoardButton button, bool isEnable) { foreach (Coin coin in m_Engine.CurrentPlayer.CoinsList) { Coordinate coordinate = coin.Coordinates; if (!coordinate.Equals(button.Coordinate)) { getButtonFromBoard(coordinate).Enabled = isEnable; } } }
private void boardButton_Click(object sender, EventArgs e) { BoardButton button = sender as BoardButton; if (m_SourceSquare == null) { chooseDestinationSquare(button); } else if (m_SourceSquare.Position.Equals(m_SquareButtons[button.Position.y, button.Position.x].Position)) { cancelChoise(button); } else { handleMoveRequest(button); } }
private void makeAMoveProcess(BoardButton i_BoardButton) { Move requestedMove = moveCreation(m_SourceSquare, m_Game.Board.GetSquare(i_BoardButton.Position.y, i_BoardButton.Position.x)); m_Game.MakeAMoveProcess(requestedMove); if (m_Game.IsProgressiveMoveAvailable(requestedMove)) { handleProgressiveMove(i_BoardButton); } else { if (m_Game.IsEndOfRound()) { handleEndOfRound(); } else { m_Game.SwapActiveTeam(); endUserChoise(i_BoardButton); } } }
private void ChangeAvailableCoordinatesColor(BoardButton i_Button, Color i_Color) { Coin coin = m_Engine.Checkers.GetCoinFromBoard(i_Button.Coordinate); if (coin != null) { foreach (Coordinate coordinate in coin.AvailableCoordinates) { BoardButton currentButton = getButtonFromBoard(coordinate); if (i_Color == Color.White) { currentButton.Enabled = false; } else { currentButton.Enabled = true; } currentButton.BackColor = i_Color; } } }
private void m_Engine_Board_SetCoinOnButton(object sender, EventArgs e) { Coin coin = sender as Coin; int row = coin.Coordinates.Row; int col = coin.Coordinates.Column; BoardButton button = m_BoardButtons[row, col]; switch (coin.CoinType) { case (eCoinType.O): button.Enabled = true; button.Text = coin.Sign + ""; break; case (eCoinType.X): button.Enabled = false; button.Text = coin.Sign + ""; break; default: break; } }
private void cancelChoise(BoardButton i_BoardButton) { i_BoardButton.BackColor = System.Drawing.Color.LightGoldenrodYellow; m_SourceSquare = null; updateSourceButtonsAvailability(); }
private void chooseDestinationSquare(BoardButton i_BoardButton) { m_SourceSquare = m_Game.Board.GetSquare(i_BoardButton.Position.y, i_BoardButton.Position.x); i_BoardButton.BackColor = System.Drawing.Color.PaleTurquoise; updateDestinationButtonsAvailability(i_BoardButton); }
private void resetActiveButton(BoardButton i_BoardButton) { i_BoardButton.BackgroundImage = null; i_BoardButton.Enabled = false; i_BoardButton.BackColor = System.Drawing.Color.LightGoldenrodYellow; }