Exemple #1
0
        public void TestEnemyCreation()
        {
            Splitter splitter = new Splitter(0, 0);

            Assert.AreEqual(splitter.Speed, 2);
            Assert.AreEqual(splitter.Health, 1);
            Assert.AreEqual(splitter.Size, 5);

            Rusher rusher = new Rusher(0, 0);

            Assert.AreEqual(rusher.Speed, 5);
            Assert.AreEqual(rusher.Health, 1);
            Assert.AreEqual(rusher.Size, 10);

            Spiked spiked = new Spiked(0, 0);

            Assert.AreEqual(spiked.Speed, 2);
            Assert.AreEqual(spiked.Health, 1);
            Assert.AreEqual(spiked.Size, 10);

            Regen regen = new Regen(0, 0);

            Assert.AreEqual(regen.Speed, 1);
            Assert.AreEqual(regen.Health, 5);
            Assert.AreEqual(regen.Size, 15);

            Carrier carrier = new Carrier(0, 0);

            Assert.AreEqual(carrier.Speed, 1);
            Assert.AreEqual(carrier.Health, 20);
            Assert.AreEqual(carrier.Size, 50);
        }
Exemple #2
0
        // Check if projectile hits an enemy
        public void EnemyHitbyProjectile()
        {
            _projRemove  = new List <Projectile>();
            _enemyRemove = new List <Enemy>();

            List <Enemy> enemiesAdd = new List <Enemy>();
            Enemy        carrier    = null;

            foreach (Projectile proj in _projectiles)
            {
                List <Enemy> enemiesHitByProjectile = new List <Enemy>();            // List of enemies hit by projectile
                foreach (Enemy enemy in _enemies)
                {
                    if (enemy.EntityDistance(enemy.X, enemy.Y, proj.X, proj.Y) < 15)
                    {
                        _projRemove.Add(proj);
                        enemy.Damaged();
                        if (enemy.Health <= 0)
                        {
                            enemiesHitByProjectile.Add(enemy);
                            _points += 10;
                        }
                        if (enemy.GetType() == typeof(Carrier) && enemy.Health <= 0)
                        {
                            carrier = enemy;
                            Rusher rusher = new Rusher(enemy.X + 20, enemy.Y + 20);
                            enemiesAdd.Add(rusher);
                            rusher = new Rusher(enemy.X, enemy.Y + 20);
                            enemiesAdd.Add(rusher);
                            rusher = new Rusher(enemy.X - 25, enemy.Y + 20);
                            enemiesAdd.Add(rusher);
                            Regen regen = new Regen(enemy.X - 15, enemy.Y - 15);
                            enemiesAdd.Add(regen);
                            Spiked spiked = new Spiked(enemy.X - 20, enemy.Y + 20);
                            enemiesAdd.Add(spiked);
                            Splitter splitter = new Splitter(enemy.X + 15, enemy.Y - 15);
                            enemiesAdd.Add(splitter);
                        }
                    }
                }
                foreach (Enemy enemy in enemiesAdd)
                {
                    enemy.PointsReached = carrier.PointsReached;
                    _enemies.Add(enemy);
                }
                if (enemiesHitByProjectile.Count > 0)
                {
                    _enemies.Remove(enemiesHitByProjectile[0]);                          // Only one enemy dies from one projectile
                }
            }
            foreach (Projectile proj in _projRemove)
            {
                _projectiles.Remove(proj);
            }                                                                        // remove proj
        }