Esempio n. 1
0
 public GameLoop(IInputOutput inputOutput,
                 CancellationToken cancellation,
                 IActionStrategy actionStrategy,
                 GameGrid gameGrid)
 {
     _gameGrid       = gameGrid ?? throw new ArgumentNullException(nameof(gameGrid));
     _actionStrategy = actionStrategy ?? throw new ArgumentNullException(nameof(actionStrategy));
     _cancellation   = cancellation;
     _inputOutput    = inputOutput ?? throw new ArgumentNullException(nameof(_inputOutput));
 }
Esempio n. 2
0
        public NextAction NextAction(GameGrid grid, CancellationToken cancellation)
        {
            var nextAction = CurrentStrategy.Next(this, cancellation);

            if (nextAction is MoveAction moveAction)
            {
                LastMoveAction = moveAction;
            }

            return(nextAction);
        }
Esempio n. 3
0
        public void Run(CancellationToken cancellation)
        {
            string[] inputs;
            var      gridSizeInput = _consoleInputOutput.ReadLine();

            inputs = gridSizeInput.Split(' ');
            int width  = int.Parse(inputs[0]); // size of the grid
            int height = int.Parse(inputs[1]); // top left corner is (x=0, y=0)

            var grid = new GameGrid();

            grid.StoreGrid(ReadGrid(height));

            var strategy = _actionStrategyFactory(grid);

            // game loop
            var loop = new GameLoop(_consoleInputOutput,
                                    cancellation,
                                    strategy,
                                    grid);

            loop.Run();
        }