コード例 #1
0
 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();
     }
 }
コード例 #2
0
 private bool RevealEmptySquare(int row, int col)
 {
     if (board[row, col].IsRevealed)
     {
         return(false);
     }
     board[row, col].IsRevealed = true;
     if (board[row, col].IsFlagged)
     {
         board[row, col].IsFlagged = false;
         SquareUnflagged.Raise(this, new SquareEventArgs(row, col));
     }
     SafeSquareRevealed.Raise(this, new SquareEventArgs(row, col, board[row, col].AdjacentMines));
     if (board[row, col].AdjacentMines == 0)
     {
         return(true);
     }
     return(false);
 }
コード例 #3
0
 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));
             }
         }
     }
 }