public void NormalTowerTest() { Map map = new Map("normal", 100000, 2); Tower t = new Tower("basic", 10, 10, 10, 500, new Rectangle(70, 70, 1, 1)); Enemy special = new Enemy(20, 1.0f, "basic", 20, new Rectangle(1, 1, 1, 1)); map.SpawnEnemy(special); map.SellTower(t); map.PlaceTower(t); for (int i = 0; i <= 60; i++) { map.Update(); t.Update(); } Assert.AreEqual(special, t.getCurrentTarget());//Special should be the closest to the tower Assert.AreEqual(10, t.getCurrentTarget().Health); Assert.AreEqual(Color.White, t.Color); }
public void MoneyIncreasesWhenTowerIsSold() { Map map = new Map("normal", 0, 1); Tower tower = new Tower("normal", 10, 20, 30, 40, rec); map.SellTower(tower); Assert.AreEqual(22, map.Money); }
public void TowersGetRemovedFromListWhenSold() { Tower tower = new Tower("tower", 10, 20, 30, 40, rec); Map map = new Map("normal", 0, 1); map.PlaceTower(tower); map.SellTower(tower); Assert.AreEqual(map.Towers, new List<Tower>()); }
public void UpdateInput() { mouseState = Mouse.GetState(); boardState = Keyboard.GetState(); if (placingTower != null) { placingTower.Location = new Rectangle(mouseState.X - (mouseState.X % gridSize), mouseState.Y - (mouseState.Y % gridSize), placingTower.Location.Width, placingTower.Location.Height); if (mouseState.LeftButton == ButtonState.Pressed && previousMouseState.LeftButton == ButtonState.Released) { for (int i = 0; i < map.Towers.Count; i++) { } map.PlaceTower(new Tower(placingTower.Name, placingTower.Health, placingTower.AttackDamage, placingTower.Cost, placingTower.Range, placingTower.Location)); placingTower = null; } } else { if (mouseState.LeftButton == ButtonState.Pressed && previousMouseState.LeftButton == ButtonState.Released) { foreach (Tower tower in menu.Towers) { if (tower.Location.Contains(mouseState.X, mouseState.Y)) { placingTower = tower.Clone(); } } } } if (mouseState.RightButton == ButtonState.Pressed && previousMouseState.RightButton == ButtonState.Released) { for (int i = 0; i < map.Towers.Count; i++) { if (map.Towers[i].Location.Contains(mouseState.X, mouseState.Y)) { map.SellTower(map.Towers[i]); } } } #region Selecting towers with Keyboard Input if (boardState.IsKeyDown(Keys.D1) && previousKeyboardState.IsKeyUp(Keys.D1)) { Tower temp = menu.Towers[0]; placingTower = new Tower(temp.Name, temp.Health, temp.AttackDamage, temp.Cost, temp.Range, new Rectangle(mouseState.X - (mouseState.X % gridSize), mouseState.Y - (mouseState.Y % gridSize), 50, 50)); } if (boardState.IsKeyDown(Keys.D2) && previousKeyboardState.IsKeyUp(Keys.D2)) { Tower temp = menu.Towers[1]; placingTower = new Tower(temp.Name, temp.Health, temp.AttackDamage, temp.Cost, temp.Range, new Rectangle(mouseState.X - (mouseState.X % gridSize), mouseState.Y - (mouseState.Y % gridSize), 50, 50)); } #endregion if (boardState.IsKeyUp(Keys.LeftAlt)) { rewindingTime = false; map.Rewinding = false; map.SaveNextState(); } if (boardState.IsKeyDown(Keys.LeftAlt)) { map.Rewinding = true; rewindingTime = true; map.LoadPreviousState(); } #region Menu interaction if (boardState.IsKeyDown(Keys.Escape) && previousKeyboardState.IsKeyUp(Keys.Escape)) { main.Visible = !main.Visible; } if (mouseState.LeftButton == ButtonState.Pressed && previousMouseState.LeftButton == ButtonState.Released) { foreach (Menu item in menus) { if (item.Visible) { item.RegisterClick(new Point(mouseState.X, mouseState.Y)); } } } #endregion previousMouseState = mouseState; previousKeyboardState = boardState; }