public PlayState(IPostOfficeService postOfficeService, SquirrelFactory squirrelFactory, ButtonFactory buttonFactory, TextFactory textFactory, StatsManager statsManager, MoneyManager moneyManager, Texture2D background, Rectangle bounds, Texture2D upgradebar, Texture2D stone, Gate gate) { _inWave = true; _wave = 0; _enemies = new List <Squirrel>(); _archers = new List <Archer>(); StateRegisterName = "Play"; _postOfficeService = postOfficeService; _squirrelFactory = squirrelFactory; _buttonFactory = buttonFactory; _textFactory = textFactory; _statsManager = statsManager; _moneyManager = moneyManager; _background = background; _stone = stone; _gate = gate; _bounds = new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height - 100); _upgradesBar = new UpgradesBar(new Vector2(0, _bounds.Height), new Rectangle(0, 0, _bounds.Width, 100), upgradebar); #region UpgradeButtons _upgradeButtons = new List <Button>(); // Add archer var addArcherArgs = new PostOfficeEventArgs() { SendAddress = "PlayState", MessageName = "AddArcher", Data = new byte[0] }; _upgradeButtons.Add(_buttonFactory.GenerateButton("New Archer", 30, _bounds.Height + 5, addArcherArgs)); // Increase Rate of Fire var rateOfFireArgs = new PostOfficeEventArgs() { SendAddress = "StatsManager", MessageName = "ModifyRateOfFire", Data = new byte[0] }; _upgradeButtons.Add(_buttonFactory.GenerateButton("RoF++", 230, _bounds.Height + 5, rateOfFireArgs)); // Increase damage modifier var damageArgs = new PostOfficeEventArgs() { SendAddress = "StatsManager", MessageName = "ModifyArrowDamage", Data = new byte[0] }; _upgradeButtons.Add(_buttonFactory.GenerateButton("Damage++", 430, _bounds.Height + 5, damageArgs)); #endregion #region Text // Generate the text objects _amountOfArchers = _textFactory.GenerateText($"{_archers.Count.ToString()} Archer(s)", 30, _bounds.Height + 55); _rofLevel = _textFactory.GenerateText($"Level {_statsManager.RateOfFireLevel}", 230, _bounds.Height + 55); _damageLevel = _textFactory.GenerateText($"{_statsManager.DamageModifier}x Damage", 430, _bounds.Height + 55); _money = _textFactory.GenerateText($"Current Funds: M{_moneyManager.Money}", 20, 20); _waveText = _textFactory.GenerateText($"Wave {_wave}", 20, 70); _gateHealth = _textFactory.GenerateText($"Gate Health: {_gate.Health}", 20, 120); #endregion #region Quit Button var quitArgs = new PostOfficeEventArgs() { SendAddress = "StateManager", MessageName = "ChangeState", Data = Encoding.ASCII.GetBytes("Menu") }; _quitButton = buttonFactory.GenerateButton("Quit", 600, 20, quitArgs); #endregion }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); // Load textures and fonts _font = Content.Load <SpriteFont>("BlackChancery"); _buttonTexture = Content.Load <Texture2D>("WoodButton"); var squirrel1 = Content.Load <Texture2D>("squirrel1"); var gateLevel = Content.Load <Texture2D>("gate_level"); var upgradeBar = new Texture2D(GraphicsDevice, GraphicsDevice.PresentationParameters.Bounds.Width, 100); var colorData = new Color[100 * GraphicsDevice.PresentationParameters.Bounds.Width]; for (int i = 0; i < 100 * GraphicsDevice.PresentationParameters.Bounds.Width; i++) { colorData[i] = Color.DarkSlateGray; } upgradeBar.SetData(colorData); var stone = new Texture2D(GraphicsDevice, 10, 10); var stoneColors = new Color[100]; for (int i = 0; i < 100; i++) { stoneColors[i] = Color.Black; } stone.SetData(stoneColors); // Create Objects var gate = new Gate(); // Create factories var buttonFactory = new ButtonFactory(_buttonTexture, _font, _postOffice); var textFactory = new TextFactory(_font); var squirrelFactory = new SquirrelFactory(squirrel1, gate); // Create Managers var leaderboardManager = new LeaderboardManager(); var playerMetaDataManager = new PlayerMetaDataManager(_postOffice); var moneyManager = new MoneyManager(_postOffice); var statsManager = new StatsManager(_postOffice, moneyManager); // Register states to the state manager _stateManager.RegisterState(new MenuState(buttonFactory, textFactory)); var nameInputState = new NameInputState(buttonFactory, textFactory, _postOffice, GraphicsDevice.PresentationParameters.Bounds); _stateManager.RegisterState(nameInputState); _stateManager.RegisterState(new LeaderboardState(buttonFactory, textFactory, leaderboardManager)); _stateManager.RegisterState(new ExitState(this)); var playState = new PlayState(_postOffice, squirrelFactory, buttonFactory, textFactory, statsManager, moneyManager, gateLevel, GraphicsDevice.PresentationParameters.Bounds, upgradeBar, stone, gate); _stateManager.RegisterState(playState); var loseState = new LoseState(buttonFactory, textFactory, _postOffice, leaderboardManager); _stateManager.RegisterState(loseState); var flavourText = new FlavourTextState(buttonFactory, textFactory); _stateManager.RegisterState(flavourText); // Register clients to the post office _postOffice.RegisterClient((ILetterbox)_stateManager, "StateManager"); _postOffice.RegisterClient((ILetterbox)playerMetaDataManager, playerMetaDataManager.LetterboxName); _postOffice.RegisterClient((ILetterbox)nameInputState, nameInputState.StateRegisterName); _postOffice.RegisterClient((ILetterbox)statsManager, statsManager.LetterboxName); _postOffice.RegisterClient((ILetterbox)playState, playState.LetterboxName); _postOffice.RegisterClient((ILetterbox)moneyManager, moneyManager.LetterboxName); _postOffice.RegisterClient((ILetterbox)gate, "Gate"); _postOffice.RegisterClient((ILetterbox)loseState, loseState.StateRegisterName); // Set the initial state to the menu _postOffice.SendMail("Null", new PostOfficeEventArgs() { SendAddress = "StateManager", MessageName = "SetInitialState", Data = Encoding.ASCII.GetBytes("Menu") }); // TODO: use this.Content to load your game content here }