Esempio n. 1
0
 public GraphicsTracker(GameBus bus)
 {
     bus.Subscribe <MessageWindowResized>(m => DisplayRectangle = m.DisplayRectangle);
     bus.Subscribe <MessageMouseDragged>(m =>
     {
         _mapOffset.X += m.ChangeX;
         _mapOffset.Y += m.ChangeY;
     });
 }
        public GameWindow(GamePhaseManager phaseManager, InputManager inputManager, GameBus bus,
                          ApplicationLogger applicationLogger, LogsOverlay logsOverlay)
        {
            _phaseManager      = phaseManager;
            _bus               = bus;
            _applicationLogger = applicationLogger;
            _logsOverlay       = logsOverlay;
            _inputManager      = inputManager;
            _inputManager.SetMousePointFunction(() => PointToClient(Cursor.Position));

            _bus.Subscribe <MessageWindowResized>(a => { InitBackBuffer(a.DisplayRectangle); });

            InitializeComponent();
            Show();
        }
Esempio n. 3
0
        public LogsOverlay(ApplicationLogger applicationLogger, FontsAndColors fontsAndColors, GameBus bus)
        {
            _applicationLogger = applicationLogger;
            _fontsAndColors    = fontsAndColors;

            bus.Subscribe <KeyReleased>(message =>
            {
                switch (message.Key)
                {
                case Keys.L:
                    _showLogs = !_showLogs;
                    break;
                }
            });
        }
        public GamePhaseManager(MapGenerator mapGenerator, GameLevelFactory gameLevelFactory,
                                LevelLayoutLoader layoutLoader, GameBus bus)
        {
            _mapGenerator     = mapGenerator;
            _gameLevelFactory = gameLevelFactory;
            _layoutLoader     = layoutLoader;
            bus.Subscribe <GameStateChange>(change =>
            {
                switch (change.GameState)
                {
                case GameState.Lost:
                    LevelEndedPlayerLost();
                    break;

                case GameState.Won:
                    LevelEndedPlayerWon();
                    break;
                }
            });
        }
Esempio n. 5
0
        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;
                    }
                }
            });
        }