예제 #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));
 }
예제 #2
0
        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;
        }
예제 #3
0
파일: GameScene.cs 프로젝트: tryparse/snake
        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;
        }