/// <summary> /// Initializes a new instance of the <see cref="PlayerManager"/> class. /// </summary> /// <param name="resolutionManager"> /// The resolution manager. /// </param> /// <param name="randomNumberGenerator"> /// The random number generator. /// </param> /// <param name="inputManager"> /// The input manager. /// </param> /// <param name="shotManager"> /// The shot manager. /// </param> /// <param name="isHost"> /// The is host. /// </param> public PlayerManager( ResolutionManager resolutionManager, IRandomNumberGenerator randomNumberGenerator, InputManager inputManager, ShotManager shotManager, bool isHost) { this.resolutionManager = resolutionManager; this.randomNumberGenerator = randomNumberGenerator; this.inputManager = inputManager; this.shotManager = shotManager; this.isHost = isHost; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here this.networkManager.Connect(); var randomNumberGenerator = new MersenneTwister(); this.inputManager = new InputManager(this, this.resolutionManager); this.soundManager = new SoundManager(randomNumberGenerator); this.shotManager = new ShotManager(this.resolutionManager, this.soundManager); this.shotManager.ShotFired += (sender, e) => this.networkManager.SendMessage(new ShotFiredMessage(e.Shot)); this.asteroidManager = new AsteroidManager(this.resolutionManager, randomNumberGenerator, this.IsHost); if (this.IsHost) { this.asteroidManager.AsteroidStateChanged += (sender, e) => this.networkManager.SendMessage(new UpdateAsteroidStateMessage(e.Asteroid)); } this.playerManager = new PlayerManager( this.resolutionManager, randomNumberGenerator, this.inputManager, this.shotManager, this.IsHost); this.playerManager.PlayerStateChanged += (sender, e) => this.networkManager.SendMessage(new UpdatePlayerStateMessage(e.Player)); this.enemyManager = new EnemyManager( randomNumberGenerator, this.shotManager, this.playerManager, this.IsHost); if (this.IsHost) { this.enemyManager.EnemySpawned += (sender, e) => this.networkManager.SendMessage(new EnemySpawnedMessage(e.Enemy)); } this.explosionManager = new ExplosionManager(this.soundManager, randomNumberGenerator); this.collisionManager = new CollisionManager(this.asteroidManager, this.playerManager, this.enemyManager, this.explosionManager, this.shotManager); this.Components.Add(this.inputManager); base.Initialize(); }