public async Task <IActionResult> InitializeBoard()
        {
            var board = _boardGenerator.GenerateBoard();

            var id = _boardRepository.AddBoard(board);

            await _boardUpdater.UpdateBoard(id, board);

            return(Accepted());
        }
示例#2
0
 /// <summary>
 ///     Initializes the game engine. Needs to be called before the game starts.
 /// </summary>
 /// <param name="ships"></param>
 public void Initialize(IList <ShipType> ships)
 {
     for (var i = 0; i < gameState.GetLength(0); i++)
     {
         gameState[i] = generator.GenerateBoard(size, ships);
     }
 }
示例#3
0
        public void Start(BoardOptions boardOptions)
        {
            _gameFinished = false;
            _board        = _boardGenerator.GenerateBoard(boardOptions);
            _user.ReadUserName();

            var gameStart = DateTime.UtcNow;

            while (!_gameFinished)
            {
                try
                {
                    // Clear the screen
                    MineSweeperConsole.Clear();

                    // Print the board
                    _boardPrinter.PrintBoardWithCoords(_board);

                    // Print the available options
                    MineSweeperConsole.WriteLine(_menuOptions);

                    // Get the user input
                    var input = _user.ReadUserAction();
                    MineSweeperConsole.WriteLine(input);

                    // Parse the action
                    var action = _actionParser.ParseAction(input);

                    // Process the action
                    ProcessAction(action);
                }
                catch (MineFoundException)
                {
                    _gameFinished = true;

                    // Clear the screen
                    MineSweeperConsole.Clear();

                    // Print the board
                    _boardPrinter.PrintBoardWithCoords(_board);
                    MineSweeperConsole.WriteLine("YOU LOOSE");
                }
                catch (Exception)
                {
                    // ignored
                }
            }

            var elapsedTime = DateTime.UtcNow - gameStart;
            var score       = Score.GenerateScore(TimeSpan.FromSeconds(elapsedTime.TotalSeconds), UserWon(), _user, _board);

            _scoreManager.AddRow(score);
            _scoreManager.PrintScore();
        }
示例#4
0
        private Domain.Models.Board GenerateNewBoard()
        {
            var board = boardGenerator.GenerateBoard();
            var ships = shipsGenerator.GenerateShips();

            boardGenerator.InsertShips(board, ships);

            boardCache.Set(board);

            return(board);
        }
        public void GenerateBoard_ShouldHaveExpectedNumberOfShips(params ShipType[] ships)
        {
            var expectedShipCells = ships.Sum(s => s.ShipSize());
            var board             = boardGenerator.GenerateBoard(10, ships.ToList());
            var flattenedBoard    = board.Flatten().OfType <ShipCell>().ToList();

            flattenedBoard.Count().ShouldBe(expectedShipCells);
            foreach (var shipType in ships)
            {
                flattenedBoard.ShouldContain(c => c.Type == shipType);
            }
        }
示例#6
0
文件: Game.cs 项目: lukegeor/netwalk
 public void StartGame()
 {
     (SolvedBoard, PlayingBoard) = _boardGenerator.GenerateBoard(_gameConfig);
     StartTime = DateTime.UtcNow;
 }
示例#7
0
 public void SetupGame(int maxXBoardSize, int maxYBoardSize, double mineProportion)
 {
     GameState.GameIsActive = true;
     GameState.GameBoard    = BoardGenerator.GenerateBoard(maxXBoardSize, maxYBoardSize, mineProportion);
     UserInterface.WelcomePlayer();
 }