Exemple #1
0
 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));
 }
Exemple #2
0
 public GameFieldGraphicsComponent(IGameFieldEntity gameField, IGraphicsSettings graphicsSettings, IGraphicsSystem graphicsSystem, IGameSettings gameSettings)
 {
     _gameFieldEntity  = gameField ?? throw new ArgumentNullException(nameof(gameField));
     _graphicsSettings = graphicsSettings ?? throw new ArgumentNullException(nameof(graphicsSettings));
     _graphicsSystem   = graphicsSystem ?? throw new ArgumentNullException(nameof(graphicsSystem));
     _gameSettings     = gameSettings ?? throw new ArgumentNullException(nameof(gameSettings));
 }
Exemple #3
0
        public SnakeEntity(IGameLogger logger, IGameFieldEntity gameField, IGameSettings gameSettings)
        {
            _logger       = logger;
            _gameField    = gameField;
            _gameSettings = gameSettings;

            Initialize();
        }
        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);
        }
Exemple #5
0
        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>();
        }
Exemple #6
0
        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();
        }
Exemple #7
0
        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;
        }
Exemple #8
0
 public GameFieldComponent(IGameFieldEntity gameField, IGameFieldGraphicsComponent gameFieldGraphicsComponent)
 {
     _gameFieldGraphicsComponent = gameFieldGraphicsComponent;
 }
Exemple #9
0
 public MovingCalculator(IGameLogger logger, IGameFieldEntity gameField)
 {
     _logger    = logger;
     _gameField = gameField;
 }