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();
        }