public GameLevel(GameLevelSettings settings, EnemyFactory enemyFactory, GamePhaseManager gamePhaseManager, InputManager inputManager, TowerFactory towerFactory) { _settings = settings; _enemyFactory = enemyFactory; _gamePhaseManager = gamePhaseManager; _inputManager = inputManager; _towerFactory = towerFactory; inputManager.OnKeyReleased += InputManagerOnOnKeyReleased; inputManager.OnClick += InputManagerOnOnClick; }
public GameLevel CreateLevel(GameLevelSettings levelSettings) { return(_container.With("settings").EqualTo(levelSettings).GetInstance <GameLevel>()); }
public GameLevel( GameLevelSettings settings, InputManager inputManager, TowerFactory towerFactory, GraphicsTracker graphicsTracker, MouseDragControl mouseDragControl, FontsAndColors fontsAndColors, GameBus bus, GameMapOverlay gameMapOverlay, ApplicationLogger logger, EnemyFactory enemyFactory) { _settings = settings; _towerFactory = towerFactory; _graphicsTracker = graphicsTracker; _fontsAndColors = fontsAndColors; _gameMapOverlay = gameMapOverlay; _logger = logger; _enemyFactory = enemyFactory; _stringFormatCenter = new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center }; _gameMapOverlay.SetMap(settings.Map); inputManager.OnMouseDragged += mouseDragControl.InputManagerOnMouseDrag; inputManager.OnMouseReleased += mouseDragControl.InputManagerOnMouseRelease; _enemySpawner = new EnemySpawner(_time, settings.SpawnFrequency); bus.Subscribe <EnemyReachedGoal>(message => { if (IsVisible) { _gameState = GameState.Lost; } }); bus.Subscribe <GameStateChange>(message => { if (IsVisible && message.GameLevel == this) { _gameState = message.GameState; } }); bus.Subscribe <EnemyDespawned>(message => { if (IsVisible) { CurrentEnemiesNew.Remove(message.Enemy); if (CurrentEnemiesNew.Count == 0 && _monstersLeftToSpawn.Count == 0) { _gameState = GameState.Won; } } }); bus.Subscribe <MouseClicked>(message => { if (IsVisible && message.EventArgs.Button == MouseButtons.Left) { if (_towerBeingPlaced != null) { // There is a tower being placed and mouse was clicked => place it. PlaceTower(_towerBeingPlaced); } } }); bus.Subscribe <KeyReleased>(message => { if (IsVisible) { if (_gameState == GameState.Won) { bus.Publish(new GameStateChange(GameState.Won, this)); CurrentEnemiesNew.Clear(); return; } if (_gameState == GameState.Lost) { bus.Publish(new GameStateChange(GameState.Lost, this)); CurrentEnemiesNew.Clear(); return; } switch (message.Key) { case Keys.Space: TogglePause(); break; case Keys.D1: StartPlacingTower(); break; } } }); }