Example #1
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
 }
Example #2
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);
 }
Example #3
0
 public void WaveThrowsOnNullEnemy()
 {
     Wave wave = new Wave(null, 1);
 }
Example #4
0
 public void WaveThrowsOnNegativeCount()
 {
     Wave wave = new Wave(new Enemy(10, 1.0f, "basic", 20, new Rectangle(5, 5, 1, 1)), -1);
 }
Example #5
0
File: Map.cs Project: mellinja/TD2
        //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);
                }

            }
        }
Example #6
0
 public void WaveInitializes()
 {
     Wave wave = new Wave(new Enemy(10, 1.0f, "basic", 20, new Rectangle(5, 5, 1, 1)), 1);
     Assert.IsNotNull(wave);
 }
Example #7
0
File: Map.cs Project: mellinja/TD2
 //sets Wave w to the current wave of enemies (1 line)
 public void newWave(Wave w)
 {
     this.wave = w;
 }
Example #8
0
File: Map.cs Project: 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);
        }
        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);
        }
Example #10
0
        //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);
                }
            }
        }
Example #11
0
 //sets Wave w to the current wave of enemies (1 line)
 public void newWave(Wave w)
 {
     this.wave = w;
 }