public void setUp() { tower = new Tower("basic", 10, 10, 10, 10, new Rectangle(5, 6, 1, 1)); e = new Enemy(10, 1.0f, "basic", 10, new Rectangle(7, 8, 1, 1)); c = new Castle(100, new Rectangle(8, 8, 1, 1)); }
//Places the destination castle on the map; the location cannot conflict or intersect with any of the towers already placed on the map. public void PlaceCastle(Castle c) { if (castle != null) { return; } for (int i = 0; i < towersOnMap.Count; i++) { if (c.Location.Intersects(towersOnMap[i].Location)) { return; } } foreach (Enemy e in enemiesOnMap) { e.Castle = c; } castle = c; }
//Spawns enemies off the wave stack, then adds enemies to each towers lists, then removes dead enemies (27 lines) public void Update() { updateCounter++; if (null != castle) { if (castle.Health <= 0) { gameEndCondition = true; castle = null; } } if (gameEndCondition == true) return; foreach (Enemy e in this.enemiesOnMap) { if (!rewinding) e.Move(); } if (updateCounter % UPDATE_MAX == 0) { if (wave != null) { Enemy e = wave.getEnemy(); if (e != null) { this.SpawnEnemy(e); } else { wave = null; } } } if (updateCounter % 1000 == 0) { if (StandardEnemy != null) { if (!firstWaveConstructed) { this.wave = new Wave( StandardEnemy, numberOfEnemies); firstWaveConstructed = true; } else if (updateCounter % 2000 == 0) { StandardEnemy.Health = (int)(StandardEnemy.Health * 1.2f); this.wave = new Wave( StandardEnemy, numberOfEnemies); updateCounter = 0; } else { numberOfEnemies = (int)(numberOfEnemies * 1.2f); this.wave = new Wave( StandardEnemy, numberOfEnemies); } } } foreach (Tower t in this.towersOnMap) { List<Enemy> KillEnemyList = new List<Enemy>(); t.Enemies.Clear(); foreach (Enemy e in this.enemiesOnMap) { if (e.Health <= 0) { KillEnemyList.Add(e); } else { double tCenterX = t.Location.X + t.Location.Width / 2; double eCenterX = e.Location.X + e.Location.Width / 2; double tCenterY = t.Location.Y + t.Location.Height / 2; double eCenterY = e.Location.Y + e.Location.Height / 2; double distance = Math.Sqrt((tCenterX - eCenterX) * (tCenterX - eCenterX) + (tCenterY - eCenterY) * (tCenterY - eCenterY)); if (t.Range >= distance) t.Enemies.Add(e); } } foreach (Enemy e in KillEnemyList) { KillEnemy(e); } } }
//Places the destination castle on the map; the location cannot conflict or intersect with any of the towers already placed on the map. public void PlaceCastle(Castle c) { if (castle != null) return; for (int i = 0; i < towersOnMap.Count; i++) { if (c.Location.Intersects(towersOnMap[i].Location)) return; } foreach (Enemy e in enemiesOnMap) { e.Castle = c; } if (this.difficulty == 1) c.Health *= 1.25f; if (this.difficulty == 3) c.Health *= .75f; castle = c; }
public void CastleInitTestHealthNegative() { Castle c = new Castle(-1, new Rectangle(1, 1, 1, 1)); }
public void CastleInitTestHealth0() { Castle c = new Castle(0, new Rectangle(1, 1, 1, 1)); }
public void CastleInitTestBadLocation() { Castle c = new Castle(1, new Rectangle(1, 1, 0, 0)); }
public void CastleInitTest() { Castle c = new Castle(100, new Rectangle(1, 1, 1, 1)); Assert.IsNotNull(c); }
public void addCastle(Castle c) { castle = c; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { this.IsMouseVisible = true; // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load<SpriteFont>("font"); toolTipFont = Content.Load<SpriteFont>("tooltipfont"); bigFont = Content.Load<SpriteFont>("bigFont"); gridSize = 50; gameTimer = 0; placingTower = null; map = new Map("normal", 100, 2); towerTex = Content.Load<Texture2D>("Sprites\\Eiffel"); backTex = Content.Load<Texture2D>("Sprites\\Blank"); Enemy e = new Enemy(100, 10f, "basic", 10, new Rectangle(50, 900, 50, 50)); e.Map = map; map.setStandardEnemy(e.Clone()); map.Enemies.Add(e); Castle c = new Castle(1000000000, new Rectangle(1500, 200, 40, 40)); map.PlaceCastle(c); this.menu = new Interface(this.graphics, this.spriteBatch, this.font); this.menu.Background = backTex; this.menu.TowerTex = towerTex; this.menu.ToolTipFont = toolTipFont; menus = new List<Menu>(); this.main = new Menu("Main Menu", new Point(0, 0), backTex, font, spriteBatch); this.main.Interface = menu; main.AddSubOption("Resume"); main.AddSubOption("Exit Game"); main.Game = this; this.options = new Menu("Options", new Point(0, 250), backTex, font, spriteBatch); this.options.Interface = menu; this.difficulty = new Menu("Difficulty", new Point(0, 500), backTex, font, spriteBatch); this.difficulty.Interface = menu; this.difficulty.AddSubOption("Raise Difficulty"); this.difficulty.AddSubOption("Lower Difficulty"); this.difficulty.AddSubOption("Back"); difficulty.Map = this.map; this.language = new Menu("Languages", new Point(0, 750), backTex, font, spriteBatch); this.language.Interface = menu; this.language.AddSubOption("Spanish"); this.language.AddSubOption("English"); this.language.AddSubOption("Back"); options.AddSubMenu(difficulty); options.AddSubMenu(language); this.options.AddSubOption("Back"); main.AddSubMenu(options); menus.Add(main); menus.Add(options); menus.Add(language); menus.Add(difficulty); Enemy e2 = e.Clone(); //Path creation using towers for (int i = 0; i <= Math.Abs(e2.Location.Y - c.Location.Y) / 50; i++) { Tower t = new Tower("path",10,0,0,1,new Rectangle(50, 900 - Math.Sign(e2.Location.Y - c.Location.Y) * i * 50, 50, 50)); map.PlaceTower(t); } for (int i = 0; i < Math.Abs(e2.Location.X - c.Location.X) / 50; i++) { Tower t = new Tower("path", 10, 0, 0, 1, new Rectangle(50 - Math.Sign(e2.Location.X - c.Location.X) * i * 50,c.Location.Y, 50, 50)); map.PlaceTower(t); } // TODO: use this.Content to load your game content here }
//Spawns enemies off the wave stack, then adds enemies to each towers lists, then removes dead enemies (27 lines) public void Update() { updateCounter++; if (null != castle) { if (castle.Health <= 0) { gameEndCondition = true; castle = null; } } if (gameEndCondition == true) { return; } foreach (Enemy e in this.enemiesOnMap) { if (!rewinding) { e.Move(); } } if (updateCounter % UPDATE_MAX == 0) { if (wave != null) { Enemy e = wave.getEnemy(); if (e != null) { this.SpawnEnemy(e); } else { wave = null; } } } if (updateCounter % 1000 == 0) { if (StandardEnemy != null) { if (!firstWaveConstructed) { this.wave = new Wave( StandardEnemy, numberOfEnemies); firstWaveConstructed = true; } else if (updateCounter % 2000 == 0) { StandardEnemy.Health = (int)(StandardEnemy.Health * 1.2f); this.wave = new Wave( StandardEnemy, numberOfEnemies); updateCounter = 0; } else { numberOfEnemies *= (int)(StandardEnemy.Health * 1.2f); this.wave = new Wave( StandardEnemy, numberOfEnemies); } } } foreach (Tower t in this.towersOnMap) { List <Enemy> KillEnemyList = new List <Enemy>(); t.Enemies.Clear(); foreach (Enemy e in this.enemiesOnMap) { if (e.Health <= 0) { KillEnemyList.Add(e); } else { double tCenterX = t.Location.X + t.Location.Width / 2; double eCenterX = e.Location.X + e.Location.Width / 2; double tCenterY = t.Location.Y + t.Location.Height / 2; double eCenterY = e.Location.Y + e.Location.Height / 2; double distance = Math.Sqrt((tCenterX - eCenterX) * (tCenterX - eCenterX) + (tCenterY - eCenterY) * (tCenterY - eCenterY)); if (t.Range >= distance) { t.Enemies.Add(e); } } } foreach (Enemy e in KillEnemyList) { KillEnemy(e); } } }