public void SetUp()
 {
     map = new Map("normal", 100000, 2);
     rec = new Rectangle(0, 0, 5, 5);
     tower = new Tower("basic", 10, 20, 30, 40, new Rectangle(5, 6, 1, 1));
     enemy = new Enemy(10, 1.0f, "basic", 20, new Rectangle(rec.X + 5, rec.Y + 5, rec.Width, rec.Height));
 }
Esempio n. 2
0
 public void towerGetsEnemy()
 {
     Enemy enemy = new Enemy(0, 0.0f, "", 0);
     tower = new Tower("", 0, 0, 0, 0);
     tower.AddNearbyEnemy(enemy);
     Assert.AreSame(enemy, tower.Enemies(0));
 }
Esempio n. 3
0
 public void SetUp()
 {
     map = new Map("normal", 0, 1);
     rec = new Rectangle(0, 0, 5, 5);
     tower = new Tower("", 10, 20, 30, 40, rec);
     enemy = new Enemy(10, 1.0f, "basic", 10, new Rectangle(30, 30, 50, 50));
 }
Esempio n. 4
0
 public void WaveReturnsAnEnemy()
 {
     Enemy e = new Enemy(10, 1.0f, "basic", 20, new Rectangle(5, 5, 1, 1));
      Wave wave = new Wave(e, 10);
     Enemy returned = wave.getEnemy();
     Assert.AreEqual(e.Type, returned.Type); //Checking to see if the types of enemies are the same
 }
        public void testTwoTowerswithTwoEnemies()
        {
            Tower t1 = new Tower("basic", 10, 1, 10, 20, new Rectangle(10, 10, 1, 1));
            Tower t2 = new Tower("basic", 10, 10, 10, 20, new Rectangle(20, 20, 1, 1));
            Enemy e1 = new Enemy(20, 1.0, "basic", 1, new Rectangle(11, 11, 1, 1)); // In range of tower and tower 2, closer to tower 1
            Enemy e2 = new Enemy(20, 1.0, "basic", 1, new Rectangle(19, 19, 1, 1)); // In range of tower and tower 2, closer to tower 2

            Map m = new Map("normal", 100, 2);
            m.PlaceTower(t1);
            m.PlaceTower(t2);
            m.SpawnEnemy(e1);
            m.SpawnEnemy(e2);
            m.Update();//adds all the approiate enemies to the towers lists
            //Assert.IsNull(t1.getCurrentTarget());
            t1.updateCounter = 59;
            t2.updateCounter = 59;
            t1.Update();
            Assert.AreEqual(2, t1.Enemies.Count);
            Assert.AreEqual(2, t2.Enemies.Count);
            Assert.AreEqual(1, t1.AttackDamage);
               // e1.Health -= 19;
            t2.Update();

            //Assert.AreEqual(19, e1.Health);
            Assert.AreEqual(e2.Health, 10);
        }
Esempio n. 6
0
        public void SlowTowerTest()
        {
            Map map = new Map("normal", 100000, 2);
            Tower t = new Tower("slow", 10, 10, 10, 1, new Rectangle(70, 70, 1, 1));
            Enemy e1 = new Enemy(100, 1, "basic", 100, new Rectangle(65, 65, 1, 1));
            Enemy e2 = new Enemy(100, 1, "basic", 100, new Rectangle(75, 75, 1, 1));
            map.PlaceTower(t);
            map.SpawnEnemy(e1);
            map.SpawnEnemy(e2);
            t.updateCounter = t.UpdateMax - 1;
            //e1.Counter = 1;
            //e2.Counter = 1;

            //map.Update();
            t.Update();
            Assert.AreEqual(new Rectangle(65, 65, 1, 1), e1.Location);

            Assert.AreEqual(new Rectangle(75, 75, 1, 1), e2.Location);

            map.Update();
            Assert.AreEqual(new Rectangle(66, 66, 1, 1), e1.Location);

            Assert.AreEqual(new Rectangle(76, 76, 1, 1), e2.Location);

            Assert.AreEqual(t.Color, Color.Blue);
        }
        public void setup()
        {
            e = new Enemy(10, 1.0f, "basic", 10, new Rectangle(7, 8, 1, 1));

            map = new Map("normal", 10000, 1);

            map.setStandardEnemy(e);//Allows the map to create waves of this enemy
        }
Esempio n. 8
0
        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));
        }
Esempio n. 9
0
 public void WaveReturnsUniqueEnemies()
 {
     Enemy e = new Enemy(10, 1.0f, "basic", 20, new Rectangle(5, 5, 1, 1));
      Wave wave = new Wave(e, 10);
     Enemy returned = wave.getEnemy();
     Enemy returned2 = wave.getEnemy();
     returned.Health -= 1;
     Assert.AreNotEqual(returned.Health,returned2.Health);
 }
Esempio n. 10
0
 public void LoadedStateHasCorrectLastEnemy()
 {
     map.SpawnEnemy(enemy);
     map.SpawnEnemy(enemy);
     map.SaveNextState();
     enemy = new Enemy(20, 30f, "basic", 30, rec);
     map.SpawnEnemy(enemy);
     map.LoadPreviousState();
     Assert.AreEqual(map.Enemies[1].Health, 10);
 }
 public void testTowerUpdatesEnemiesList()
 {
     Tower t1 = new Tower("tower", 10, 1, 10, 10, new Rectangle(0, 0, 10, 10));
     Enemy e1 = new Enemy(20, 1.0, "basic", 1, new Rectangle(150, 150, 155, 155)); //Out of t1's range
     Map m = new Map("normal", 100, 2);
     m.PlaceTower(t1);
     m.SpawnEnemy(e1);
     m.Update();//adds all the approiate enemies to the towers lists
     t1.Update();
     //Assert.AreEqual(e1, t1.getEnemyList.get(0));
     Assert.AreEqual(0, t1.Enemies.Count);
 }
        public void EnemyMoveOutofRange()
        {
            //enemy can move out of range
            Enemy enemy2 = new Enemy(10, 1.0f, "basic", 10, new Rectangle(3, 3, 1, 1));
            map.SpawnEnemy(enemy2);
            map.Update();

            Assert.AreEqual(2, tower.Enemies.Count);
            enemy.moveTo(500, 500);
            map.Update();
            Assert.AreEqual(tower.Enemies.Count, 1);
        }
Esempio n. 13
0
 //Initializes the wave, which contains a stack of enemies of the same type, haveing "count" enemies in the stack to start with (8 lines)
 public Wave(Enemy enemy, int count)
 {
     updateTimer = 0;
     waveEnemies = new Stack<Enemy>();
     if(null == enemy)
        throw new ArgumentNullException();
     if (count <= 0)
         throw new ArgumentOutOfRangeException();
     for (int i = 0; i < count; i++)
     {
         waveEnemies.Push(new Enemy(enemy.Health,enemy.Speed,enemy.Type,enemy.Gold,enemy.Location));
     }
 }
 public void mapUpdatesDamageEnemiesWithTowers()
 {
     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);
 }
Esempio n. 15
0
 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 testTowerChangesTarget()
        {
            Tower t1 = new Tower("tower", 10, 1, 10, 100, new Rectangle(0, 0, 1, 11));
            Enemy e1 = new Enemy(20, 1.0, "basic", 1, new Rectangle(30, 30, 1, 1));
            Enemy e2 = new Enemy(20, 1.0, "basic", 1, new Rectangle(110, 110, 1, 1));

            Map m = new Map("normal", 100, 2);
            m.PlaceTower(t1);
            m.SpawnEnemy(e1);
            m.SpawnEnemy(e2);
            m.Update();//adds all the approiate enemies to the towers lists
            t1.Update();
            Assert.AreEqual(e1, t1.getCurrentTarget());

            e2.moveTo(25,25);
            m.Update();
            Assert.AreEqual(e2, t1.getCurrentTarget());
        }
        public void EnemyDestroyed()
        {
            //testing that towers can destroy enemies and that they are removed from list of the enemies in the tower's range
            enemy.moveTo(40, 40); //Move the enemy away from the tower for this test

            Enemy enemy2 = new Enemy(1, 1.0f, "basic", 10, new Rectangle(3, 3, 1, 1));
            map.SpawnEnemy(enemy2);

            map.Update();

            Assert.AreEqual(2, tower.Enemies.Count);
            for (int i = 0; i < tower.UpdateMax; i++)
            {
                tower.Update();
            }

            map.Update();

            Assert.AreEqual(1, tower.Enemies.Count);
        }
Esempio n. 18
0
        public void RedTowerTest()
        {
            Map map = new Map("normal", 100000, 2);
            Tower t = new Tower("dot", 10, 10, 10, 30, new Rectangle(70, 70, 1, 1));
            Enemy e1 = new Enemy(30000, 1, "basic", 100, new Rectangle(65, 65, 1, 1));
            map.PlaceTower(t);
            map.SpawnEnemy(e1);
            t.updateCounter = t.UpdateMax - 1;
            map.Update();
            t.Update();
            Assert.True(e1.BurnStop > e1.Counter);
            Assert.AreEqual(30000f, e1.Health);
            map.Update();
            e1.Update();
            Assert.AreEqual(29999f, e1.Health);
            for (int i = 0; i < 200; i++)
                e1.Update();

            Assert.False(e1.BurnStop > e1.Counter);

            Assert.AreEqual(t.Color, Color.Red);
        }
Esempio n. 19
0
File: Map.cs Progetto: mellinja/TD2
        public void SaveNextState()
        {
            if (saveStates.Count > 1000)
                saveStates.RemoveAt(0);
            SaveState nextState = new SaveState();
            nextState.enemies = new List<Enemy>();
            nextState.towers = new List<Tower>();
            nextState.counter = this.updateCounter;

            if (this.wave != null)
            {
                nextState.wave = new Wave(this.wave.Enemy,0);

                for (int i = 0; i < this.wave.Enemies.Count; i++)
                {
                    nextState.wave.Enemies.Push(this.wave.Enemies.Peek().Clone());
                }
            }

            for (int i = 0; i < this.Towers.Count; i++)
            {
                nextState.towers.Add(this.Towers[i]);
            }
            for (int i = 0; i < this.Enemies.Count; i++)
            {
                Enemy temp = this.Enemies[i];
                Enemy enemy = new Enemy(temp.MaxHealth, temp.Speed, temp.Type, temp.Gold, temp.Location);
                enemy.Health = temp.Health;
                nextState.enemies.Add(enemy);
            }
            nextState.score = this.Score;
            nextState.money = this.Money;
            saveStates.Add(nextState);
        }
Esempio n. 20
0
File: Cell.cs Progetto: mellinja/TD2
 //sets the cell to occupied status, holding enemy e (2 lines)
 public void Occupy(Enemy e)
 {
     Occupied = true;
     enemy = e;
 }
Esempio n. 21
0
 //Attacks enemy e (1 line)
 public void AttackEnemy(Enemy e)
 {
     e.Health -= this.attackDamage;
 }
 public void SetUp()
 {
     towerRange = 5;
     towerPosition = new Rectangle(0, 1, 1, 1);
     enemyPosition = new Rectangle(1, 1, 1, 1);
     enemy = new Enemy(10, 1.0f, "basic", 10, enemyPosition);
     tower = new Tower("Tower", 1, 1, 1, 100, towerPosition);
     map = new Map("normal", 100, 1);
     map.PlaceTower(tower);
     map.SpawnEnemy(enemy);
 }
Esempio n. 23
0
 public void AddNearbyEnemy(Enemy enemy)
 {
     nearbyEnemies.Add(enemy);
 }
Esempio n. 24
0
        /// <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");
            gridSize = 50;
            gameTimer = 0;
            placingTower = null;
            map = new Map("normal", 100, 1);

            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);
            map.PlaceCastle(new Castle(1000000000, new Rectangle(1500, 200, 40, 40)));
            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("Back");

            this.options = new Menu("Options", new Point(300, 0), backTex, font, spriteBatch);
            this.options.Interface = menu;
            this.options.AddSubOption("Back");

            this.difficulty = new Menu("Difficulty", new Point(300, 300), backTex, font, spriteBatch);
            this.difficulty.Interface = menu;
            this.difficulty.AddSubOption("Raise Difficulty");
            this.difficulty.AddSubOption("Lower Difficulty");

            difficulty.Map = this.map;

            this.language = new Menu("Languages", new Point(600, 0), 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);
            main.AddSubMenu(options);

            menus.Add(main);
            menus.Add(options);
            menus.Add(language);
            menus.Add(difficulty);

            // TODO: use this.Content to load your game content here
        }
Esempio n. 25
0
File: Map.cs Progetto: mellinja/TD2
 //Adds an Enemy to that map (1 line)
 public void SpawnEnemy(Enemy enemy)
 {
     if (difficulty == 3)
     {
         enemy.MaxHealth *= HARD_MULTIPLIER_ENEMY;
         enemy.Health *= HARD_MULTIPLIER_ENEMY;
     }
     else if (difficulty == 1)
     {
         enemy.MaxHealth *= EASY_MULTIPLIER_ENEMY;
         enemy.Health *= EASY_MULTIPLIER_ENEMY;
     }
     enemy.Map = this;
     enemy.Castle = this.castle;
     enemiesOnMap.Add(enemy);
 }
Esempio n. 26
0
File: Map.cs Progetto: mellinja/TD2
 public void setStandardEnemy(Enemy e)
 {
     this.StandardEnemy = e;
 }
        public void SetUp()
        {
            map = new Map("normal", 100000, 1);
            rec = new Rectangle(0, 0, 5, 5);
            tower = new Tower("basic", 10, 20, 30, 40, new Rectangle(1, 0, 1, 1));
            enemy = new Enemy(10, 1.0f, "basic", 20, new Rectangle(rec.X + 5, rec.Y + 5, rec.Width, rec.Height));

            wave = new Wave(new Enemy(10, 1.0f, "basic", 20, new Rectangle(rec.X + 5, rec.Y + 5, rec.Width, rec.Height)), 5);
            map.newWave(wave);
            map.PlaceTower(tower);
        }
Esempio n. 28
0
File: Map.cs Progetto: mellinja/TD2
        public void LoadPreviousState()
        {
            if (saveStates.Count == 0)
                return;
            SaveState previousState = new SaveState();
            previousState = this.saveStates[saveStates.Count - 1];
            this.Money = previousState.money;
            this.Score = previousState.score;
            this.Towers = new List<Tower>();
            this.Enemies = new List<Enemy>();
            this.updateCounter = previousState.counter;

            if (previousState.wave != null)
            {
                this.wave = new Wave(previousState.wave.Enemy, 0);
                for (int i = 0; i < previousState.wave.Enemies.Count; i++)
                {
                    this.wave.Enemies.Push(previousState.wave.Enemies.Peek().Clone());
                }
            }
            for (int i = 0; i < previousState.towers.Count; i++)
                this.Towers.Add(previousState.towers[i]);
            for (int i = 0; i < previousState.enemies.Count; i++)
            {
                Enemy temp = previousState.enemies[i];
                Enemy enemy = new Enemy(temp.MaxHealth, temp.Speed, temp.Type, temp.Gold, temp.Location);
                enemy.Castle = this.castle;
                enemy.Health = temp.Health;
                enemy.Map = this;
                this.Enemies.Add(enemy);
            }
            this.saveStates.RemoveAt(saveStates.Count - 1);
        }
Esempio n. 29
0
File: Map.cs Progetto: mellinja/TD2
        //Removes an enemy, giveing the user its money (2 lines)
        public void KillEnemy(Enemy enemy)
        {
            enemiesOnMap.Remove(enemy);

            if (this.difficulty == 1)
                score += (int) (enemy.Gold * 7.5);

            if (this.difficulty == 2)
                score += enemy.Gold * 10;

            if (this.difficulty == 3)
            score += (int)(enemy.Gold * 12.5);
            money += enemy.Gold;
        }
Esempio n. 30
0
        public void DisplayToolTip(Enemy enemy, Vector2 position)
        {
            Rectangle tipBackground = new Rectangle((int)position.X, (int)position.Y - 70, 140, 80);
            spriteBatch.Draw(backgroundTexture, tipBackground, new Color(0, 0, 0, 100));

            spriteBatch.DrawString(tipFont, enemy.Type + " " + lm.getTranslation("enemy", language), new Vector2(tipBackground.X, tipBackground.Y), Color.White);
            spriteBatch.DrawString(tipFont, lm.getTranslation("Health", language) + ": " + enemy.HealthPercentage * 100 + "%" + "\n" + lm.getTranslation("Speed", language) + ": " + enemy.Speed, new Vector2(tipBackground.X, tipBackground.Y + 15), Color.White);
            //spriteBatch.DrawString(tipFont, "Speed: " + enemy.Speed, new Vector2(tipBackground.X, tipBackground.Y + 30), Color.White);
        }