public void RevealSquare(int row, int col) { if (gameOver || board[row, col].IsRevealed) { return; } board[row, col].IsRevealed = true; if (board[row, col].IsFlagged) { UnflagSquare(row, col); } if (board[row, col].IsMine) { MineRevealed.Raise(this, new SquareEventArgs(row, col)); gameOver = true; timer.Stop(); GameLost.Raise(this, EventArgs.Empty); } else { SafeSquareRevealed.Raise(this, new SquareEventArgs(row, col, board[row, col].AdjacentMines)); if (board[row, col].AdjacentMines == 0) { RevealEmptySquares(row, col); } } if (CheckGameWon()) { OnGameWon(); } }
public void RecreateBoard() { for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { if (board[i, j].IsFlagged) { SquareFlagged.Raise(this, new SquareEventArgs(i, j)); } else if (board[i, j].IsRevealed && !board[i, j].IsMine) { SafeSquareRevealed.Raise(this, new SquareEventArgs(i, j, board[i, j].AdjacentMines)); } else if (board[i, j].IsRevealed) { MineRevealed.Raise(this, new SquareEventArgs(i, j)); } } } }