Esempio n. 1
0
        public void MakeMove(UserMove move)
        {
            var cell = _gameBoard.GetCell(move.Row, move.Col);

            if (cell == null || cell.IsFlipped)
            {
                return;
            }
            if (move.IsFlag)
            {
                if (!cell.IsFlagged)
                {
                    if (cell.IsBomb)
                    {
                        _correctFlags++;
                    }
                    _numFlags++;
                    cell.IsFlagged = true;
                }
                else
                {
                    if (cell.IsBomb)
                    {
                        _correctFlags--;
                    }
                    _numFlags--;
                    cell.IsFlagged = false;
                }
            }
            else
            {
                if (cell.IsFlagged)
                {
                    _numFlags--;
                    cell.IsFlagged = false;
                }
                if (cell.IsBomb)
                {
                    GameState      = GameState.Loss;
                    cell.IsFlipped = true;
                    return;
                }
                if (cell.Number == 0)
                {
                    RevealEmptyCells(cell);
                }
                else
                {
                    cell.IsFlipped = true;
                    _numFlips     += 1;
                }
            }
            if (!IsWin())
            {
                return;
            }
            GameState = GameState.Win;
            RevealAllCells();
        }
Esempio n. 2
0
 /// <summary>
 /// Make move and send to engine
 /// </summary>
 /// <param name="row">move row</param>
 /// <param name="col">move col</param>
 /// <param name="isFlag">true if move is a flag, o.w. flase</param>
 public static void MakeMove(int row, int col, bool isFlag)
 {
     if (isFlag && NumFlags != 0 || !isFlag)
     {
         var move = new UserMove(row, col, isFlag);
         _gameEngine.MakeMove(move);
         SetMinesText();
         UpdateTable();
     }
 }
Esempio n. 3
0
 public void MakeMove(UserMove move)
 {
     var cell = _gameBoard.GetCell(move.Row, move.Col);
     if (cell == null || cell.IsFlipped)
     {
         return;
     }
     if (move.IsFlag)
     {
         if (!cell.IsFlagged)
         {
             if (cell.IsBomb)
             {
                 _correctFlags++;
             }
             _numFlags++;
             cell.IsFlagged = true;
         }
         else
         {
             if (cell.IsBomb)
             {
                 _correctFlags--;
             }
             _numFlags--;
             cell.IsFlagged = false;
         }
     }
     else
     {
         if (cell.IsFlagged)
         {
             _numFlags--;
             cell.IsFlagged = false;
         }
         if (cell.IsBomb)
         {
             GameState = GameState.Loss;
             cell.IsFlipped = true;
             return;
         }
         if (cell.Number == 0)
         {
             RevealEmptyCells(cell);
         }
         else
         {
             cell.IsFlipped = true;
             _numFlips += 1;
         }
     }
     if (!IsWin()) return;
     GameState = GameState.Win;
     RevealAllCells();
 }
Esempio n. 4
0
 /// <summary>
 /// Console version of mine sweeper
 /// </summary>
 /// <param name="args"></param>
 static void Main(string[] args)
 {
     var height = 4;
     var width = 4;
     var numbumbs = 4;
     var engine = new Engine(height, width, numbumbs);
     while (engine.GameState == GameState.Running)
     {
         var board = engine.GetBoardAs2DArray();
         PrintBoard(board, height, width);
         Console.WriteLine("Row: ");
         var row = Convert.ToInt32(Console.ReadLine());
         Console.WriteLine("Col: ");
         var col = Convert.ToInt32(Console.ReadLine());
         var userMove = new UserMove(row, col, false);
         engine.MakeMove(userMove);
     }
     PrintBoard(engine.GetBoardAs2DArray(), height, width);
     Console.WriteLine(engine.GameState == GameState.Win ? "YOU WIN!!!" : "YOU LOSE!!!");
     Console.ReadKey();
 }