private void buttonBoardSquare_Click(object sender, EventArgs e) { ComplexPictureBoxButton currentButton = sender as ComplexPictureBoxButton; if (sourceClickedButton == null) { if (checkRecapture(currentButton) == true || (m_PlayerSolderStillAbleToCapture == null && isPlayerSoldier(currentButton) == true)) { currentButton.BackColor = Color.DodgerBlue; sourceClickedButton = currentButton; } else { MessageBox.Show(string.Format(k_IllegalSquareChoice, Environment.NewLine), k_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (currentButton.BackColor == Color.DodgerBlue) { currentButton.BackColor = Color.White; sourceClickedButton = null; } else if (sourceClickedButton != null) { gameMove(currentButton); } }
private void initialOtherLinesInBoard() { for (int i = 1; i < r_BoardSize; ++i) { for (int j = 0; j < r_BoardSize; ++j) { r_BoardSquares[i, j] = new ComplexPictureBoxButton(); r_BoardSquares[i, j].Width = k_SquareSize; r_BoardSquares[i, j].Height = k_SquareSize; if ((i + j) % 2 == 0) { r_BoardSquares[i, j].BackColor = Color.Black; r_BoardSquares[i, j].Enabled = false; } else { r_BoardSquares[i, j].BackColor = Color.White; } if (j == 0) { r_BoardSquares[i, j].Location = new Point(k_SquareLeftMargin, r_BoardSquares[i - 1, j].Bottom); } else { r_BoardSquares[i, j].Location = new Point(r_BoardSquares[i, j - 1].Right, r_BoardSquares[i - 1, j].Bottom); } r_BoardSquares[i, j].X = j; r_BoardSquares[i, j].Y = i; Controls.Add(r_BoardSquares[i, j]); } } }
private void initialFirstLineInBoard() { for (int i = 0; i < r_BoardSize; ++i) { r_BoardSquares[0, i] = new ComplexPictureBoxButton(); r_BoardSquares[0, i].Width = k_SquareSize; r_BoardSquares[0, i].Height = k_SquareSize; if (i % 2 == 0) { r_BoardSquares[0, i].BackColor = Color.Black; r_BoardSquares[0, i].Enabled = false; } else { r_BoardSquares[0, i].BackColor = Color.White; } if (i == 0) { r_BoardSquares[0, i].Location = new Point(k_SquareLeftMargin, r_PlayersScore[0].Bottom + k_PlayerLabelYCordinate); } else { r_BoardSquares[0, i].Location = new Point(r_BoardSquares[0, i - 1].Right, r_PlayersScore[0].Bottom + k_PlayerLabelYCordinate); } r_BoardSquares[0, i].X = i; r_BoardSquares[0, i].Y = 0; Controls.Add(r_BoardSquares[0, i]); } }
private void restartGame() { m_Turn = 0; sourceClickedButton = null; m_PlayerSolderStillAbleToCapture = null; initialPlayersSoliders(); cleanBoard(); setSoldierOnBoard(); initialCheckersLogicalPlayer(); }
private bool isPlayerSoldier(ComplexPictureBoxButton i_CurrentButton) { bool isLegal = false; if (i_CurrentButton.Text == r_Players[m_Turn].PlayerSignOnBoard(new Point(i_CurrentButton.X, i_CurrentButton.Y))) { isLegal = true; } return(isLegal); }
private void reportPlayerValidation(Point i_SourcePoint, Point i_DestinationPoint, bool i_IsCaptureOption, bool i_IsLegalMove) { if (i_IsLegalMove == true) { ComplexPictureBoxButton currentButton = r_BoardSquares[i_DestinationPoint.Y, i_DestinationPoint.X]; operation(i_SourcePoint, ref i_DestinationPoint, i_IsCaptureOption); currentButton.Text = sourceClickedButton.Text; currentButton.BackgroundImage = sourceClickedButton.BackgroundImage; currentButton.BackgroundImageLayout = ImageLayout.Stretch; sourceClickedButton.Text = string.Empty; sourceClickedButton.BackgroundImage = null; sourceClickedButton = null; checkEndGame(); } }
private void updateComputerMoveOnBoard(Soldier i_CurrentSoldier, Point i_SourcePoint, ref Point io_DestinationPoint, bool i_IsCaptureOption) { Point destinationPointBeforeChange; destinationPointBeforeChange = io_DestinationPoint; i_SourcePoint.X = i_CurrentSoldier.X; i_SourcePoint.Y = i_CurrentSoldier.Y; sourceClickedButton = r_BoardSquares[i_SourcePoint.Y, i_SourcePoint.X]; m_Engine.LogicOperationNotifier -= updateComputerMoveOnBoard; m_Engine.LogicOperationNotifier += deleteEnemyAndChangeTurn; operation(i_SourcePoint, ref io_DestinationPoint, i_IsCaptureOption); m_Engine.LogicOperationNotifier -= deleteEnemyAndChangeTurn; updateComputerButtons(i_SourcePoint, destinationPointBeforeChange); checkEndGame(); if (m_PlayerSolderStillAbleToCapture != null) { m_Engine.LogicOperationNotifier += updateComputerMoveOnBoard; computerOperation(i_CurrentSoldier, ref io_DestinationPoint, i_SourcePoint); } }
private void gameMove(ComplexPictureBoxButton i_CurrentButton) { Point sourcePoint = new Point(sourceClickedButton.X, sourceClickedButton.Y); Point destinationPoint = new Point(i_CurrentButton.X, i_CurrentButton.Y); sourceClickedButton.BackColor = Color.White; if (r_Players[m_Turn].IsComputer == false) { m_Engine.LogicOperationNotifier += deleteEnemyAndChangeTurn; m_Engine.PlayerValidation(r_Players[m_Turn], sourcePoint, destinationPoint); m_Engine.LogicOperationNotifier -= deleteEnemyAndChangeTurn; } if (r_Players[m_Turn].IsComputer == true) { Soldier currentSoldier = null; m_Engine.LogicOperationNotifier += updateComputerMoveOnBoard; computerOperation(currentSoldier, ref destinationPoint, sourcePoint); } sourceClickedButton = null; }
private bool checkRecapture(ComplexPictureBoxButton i_CurrentButton) { return(m_PlayerSolderStillAbleToCapture != null && i_CurrentButton.X == m_PlayerSolderStillAbleToCapture.X && i_CurrentButton.Y == m_PlayerSolderStillAbleToCapture.Y); }