public SnakeGraphicsComponent(ISnakeEntity snake, IGraphicsSystem graphicsSystem, ISnakeMovementComponent movement, IGameFieldEntity gameField) { _snake = snake ?? throw new ArgumentNullException(nameof(snake)); _graphicsSystem = graphicsSystem ?? throw new ArgumentNullException(nameof(graphicsSystem)); _movement = movement ?? throw new ArgumentNullException(nameof(movement)); _gameField = gameField ?? throw new ArgumentNullException(nameof(gameField)); }
public SnakeGameComponent(ISnakeEntity snake, IGraphics2DComponent graphicsComponent, ISnakeMovementComponent snakeMovement, IGameLogger logger) { _snake = snake ?? throw new ArgumentNullException(nameof(snake)); _graphicsComponent = graphicsComponent ?? throw new ArgumentNullException(nameof(graphicsComponent)); _snakeMovementComponent = snakeMovement ?? throw new ArgumentNullException(nameof(snakeMovement)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); Enabled = true; }
public SnakeMovementSmoothComponent(ISnakeEntity snakeEntity, IGameFieldComponent gameFieldComponent, IGameSettings gameSettings, SnakeControlKeys snakeControlKeys, IMovingCalculator movingCalculator) { _snakeEntity = snakeEntity ?? throw new ArgumentNullException(nameof(snakeEntity)); _gameFieldComponent = gameFieldComponent ?? throw new ArgumentNullException(nameof(gameFieldComponent)); _gameSettings = gameSettings ?? throw new ArgumentNullException(nameof(gameSettings)); _snakeControlKeys = snakeControlKeys ?? throw new ArgumentNullException(nameof(snakeControlKeys)); _movingCalculator = movingCalculator ?? throw new ArgumentNullException(nameof(movingCalculator)); _unitVector = Vector2.Multiply(Vector2.UnitX, _gameSettings.TileSize); _movingInterval = TimeSpan.FromMilliseconds(_gameSettings.DefaultMoveIntervalTime); }
public SnakeMovementTurnBased(ISnakeEntity snake, IGameFieldEntity gameField, IGameSettings gameSettings, SnakeControlKeys controls) { _snake = snake; _gameField = gameField; _gameSettings = gameSettings; _controls = controls; _movingInterval = TimeSpan.FromMilliseconds(_gameSettings.DefaultMoveIntervalTime); _unitVector = Vector2.Multiply(Vector2.UnitX, _gameSettings.TileSize); }
public FoodManager(Game game, IGameFieldEntity field, IGameSettings gameSettings, IGraphicsSystem graphicsSystem, IGameLogger logger, ISnakeEntity snake) { _game = game ?? throw new ArgumentNullException(nameof(game)); _gameField = field ?? throw new ArgumentNullException(nameof(field)); _gameSettings = gameSettings ?? throw new ArgumentNullException(nameof(gameSettings)); _graphicsSystem = graphicsSystem ?? throw new ArgumentNullException(nameof(graphicsSystem)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _snake = snake ?? throw new ArgumentNullException(nameof(snake)); _foods = new List <IFoodGameComponent>(); }
public GameManager(IGameLogger logger, IFoodManager foodManager, ISnakeGameComponent snake, IGameFieldEntity gameField, IGameSettings gameSettings, IGamePoints gamePoints, ISnakeEntity snakeEntity, ISceneManager sceneManager, Game game, IGraphicsSystem graphicsSystem, IGameKeys gameKeys) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _foodManager = foodManager ?? throw new ArgumentNullException(nameof(foodManager)); _snakeComponent = snake ?? throw new ArgumentNullException(nameof(snake)); _gameField = gameField ?? throw new ArgumentNullException(nameof(gameField)); _gameSettings = gameSettings ?? throw new ArgumentNullException(nameof(gameSettings)); _gamePoints = gamePoints ?? throw new ArgumentNullException(nameof(gamePoints)); _snakeEntity = snakeEntity ?? throw new ArgumentNullException(nameof(snakeEntity)); _sceneManager = sceneManager ?? throw new ArgumentNullException(nameof(sceneManager)); _game = game ?? throw new ArgumentNullException(nameof(game)); _graphicsSystem = graphicsSystem ?? throw new ArgumentNullException(nameof(graphicsSystem)); _gameKeys = gameKeys ?? throw new ArgumentNullException(nameof(gameKeys)); Initialize(); }
public ICell GetRandomCellWithoutSnake(ISnakeEntity snake) { var segments = new List <ISnakeSegment>(snake.Tail) { snake.Head }; var snakeCells = segments .Select(x => GetCellByCoordinates(x.Position)) .Where(x => x != null) .ToList(); var cells = (from ICell c in Cells where !snakeCells.Contains(c) select c).ToList(); var index = _random.Next(0, cells.Count); return(cells[index]); }
private async Task LoadAsync() { var tasks = new List <Task> { Task.Run(() => { _randomGenerator = new RandomGenerator(2); _gameFieldFactory = new GameFieldFactory(GameSettings, _randomGenerator); _gameField = _gameFieldFactory.GetRandomField(GameSettings.MapWidth, GameSettings.MapHeight, 0.9d); _gameFieldComponent = new GameFieldComponent(_gameField, new GameFieldGraphicsComponent(_gameField, GraphicsSystem.GraphicsSettings, GraphicsSystem, GameSettings)); _snakeEntity = new SnakeEntity(Logger, _gameField, GameSettings); _snakeEntity.Grow(); _snakeMovementComponent = new SnakeMovementTurnBased(_snakeEntity, _gameField, GameSettings, new SnakeControlKeys(Keys.Up, Keys.Down, Keys.Left, Keys.Right)); _snakeGameComponent = new SnakeGameComponent(_snakeEntity, new SnakeGraphicsComponent(_snakeEntity, GraphicsSystem, _snakeMovementComponent, _gameField), _snakeMovementComponent, Logger); _foodManager = new FoodManager(Game, _gameField, GameSettings, GraphicsSystem, Logger, _snakeEntity); _foodManager.Add(_foodManager.GenerateRandomFood()); #region Common _gamePoints = new GamePoints(GameSettings.RemainingLives); _gameManager = new GameManager(Logger, _foodManager, _snakeGameComponent, _gameField, GameSettings, _gamePoints, _snakeEntity, SceneManager, Game, GraphicsSystem, GameKeys) { Enabled = true }; #endregion Common grayScaleEffect = Game.Content.Load <Effect>("Effects/grayscale"); shadeEffect = Game.Content.Load <Effect>("Effects/dark"); #region UI components _fpsCounter = new FpsCounter(new Vector2(Game.GraphicsDevice.Viewport.Width - 50, 0), GraphicsSystem.SpriteFont, Color.Black); var pointsCounterPosition = Vector2.Add(new Vector2(_gameField.Bounds.Right, _gameField.Bounds.Top), new Vector2(10, 0)); _pointsCounterComponent = new PointsCounterComponent(pointsCounterPosition, GraphicsSystem, _gamePoints); var remainingLivesPosition = Vector2.Add(new Vector2(_gameField.Bounds.Right, _gameField.Bounds.Top), new Vector2(10, 25)); _remainingLivesComponent = new RemainingLivesComponent(remainingLivesPosition, GraphicsSystem, _gamePoints); _debugInfoPanelComponent = new DebugInfoPanelComponent(GraphicsSystem, GameSettings, _gameManager); #endregion UI components }), Task.Delay(500) }; await Task.WhenAll(tasks.ToArray()); IsLoaded = true; }