private void initBoard(int i_SizeOfBoard) { m_BoardGame = new BoardButton[i_SizeOfBoard, i_SizeOfBoard]; for (int i = 0; i < i_SizeOfBoard; i++) { for (int j = 0; j < i_SizeOfBoard; j++) { m_BoardGame[i, j] = new BoardButton(); setBoardButton(m_BoardGame[i, j], i, j); if ((i + j) % 2 == 0) { m_BoardGame[i, j].Enabled = false; m_BoardGame[i, j].BackColor = Color.Black; } else { if (Game.Board.BoardAcceser[i, j] != null) { m_BoardGame[i, j] = new BoardButton(Game.Board.BoardAcceser[i, j]); } m_BoardGame[i, j].Click += new System.EventHandler(this.boardButton_OnClick); } Controls.Add(m_BoardGame[i, j]); } } }
private void boardButton_OnClick(object sender, EventArgs e) { BoardButton clickedButton = sender as BoardButton; string winner; if (checkIfAnotherPlayerSquareIsMarked()) { if (Game.CurrentPlayer.Tools.ContainsKey(clickedButton.Name)) { clickedButton.BackColor = Color.White; } else { string playerWantedMove = m_ToolToMove.Name + ">" + clickedButton.Name; if (Game.CheckAvailableMove(playerWantedMove)) { m_Checkers.Move(playerWantedMove); m_ToolToMove.BackColor = Color.White; this.updateBoard(); while (Game.CurrentPlayer.Name == "Computer" && m_Checkers.GameEnded == false) { if ((m_FormSettings.NumberOfPlayers == 1) && (Game.CurrentPlayer.Name == "Computer")) { m_Checkers.ComputerMove(); this.updateBoard(); } if (m_FormSettings.NumberOfPlayers == 2) { break; } } turnLabel.Text = Game.CurrentPlayer.Name + "'s turn"; player1Label.Text = string.Format(@"{0}{1}Game score: {2}{3}Tournament score: {4}", m_Player1Name, "\n", Game.FirstPlayer.Score, "\n", Game.FirstPlayer.TournamentScore); player2Label.Text = string.Format(@"{0}{1}Game score: {2}{3}Tournament score: {4}", m_Player2Name, "\n", Game.SecondPlayer.Score, "\n", Game.SecondPlayer.TournamentScore); if (m_Checkers.StatusOfTheGame == Game.GameStatus.WIN) { winner = m_Checkers.WhoWins(); DialogResult dialogResult = MessageBox.Show(string.Format(@"{0} has won!{1}{2}", winner, "\n", "Another round?"), "Damka - Game Over!", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.No) { Application.Exit(); } else if (dialogResult == DialogResult.Yes) { foreach (BoardButton button in this.m_BoardGame) { this.Controls.Remove(button); } FormGame.m_Checkers.RestartNewGame(); FormGame.m_BoardInterface.initBoard(Game.Board.BoardSize); turnLabel.Text = m_Player1Name + "'s turn"; player1Label.Text = string.Format(@"{0}{1}Game score: {2}{3}Tournament score: {4}", m_Player1Name, "\n", Game.FirstPlayer.Score, "\n", Game.FirstPlayer.TournamentScore); player2Label.Text = string.Format(@"{0}{1}Game score: {2}{3}Tournament score: {4}", m_Player2Name, "\n", Game.SecondPlayer.Score, "\n", Game.SecondPlayer.TournamentScore); } } } } } else { if (Game.CurrentPlayer.Tools.ContainsKey(clickedButton.Name)) { if (clickedButton.BackColor == Color.White && Game.CheckIfThisMySquares(clickedButton.Tool.ColPosition, clickedButton.Tool.RowPosition)) { clickedButton.BackColor = Color.LightBlue; m_ToolToMove = clickedButton; } } } }