Exemple #1
0
        public void TestShipDoesNotRegenerateShieldWhenHit()
        {
            fleet1 = new Fleet("Federation", CreateSpaceShips(15), CommonRandom);
            fleet1.NewBattleCommencing(3);
            TargetingMissile missile = new TargetingMissile(15, 1); // shield down
            TargetingMissile missile2 = new TargetingMissile(15, 10); // shield down
            TargetingMissile missile3 = new TargetingMissile(150, 8); // kill
            TargetingMissile missile4 = new TargetingMissile(2, 1);

            fleet1.RecieveFireFromEnemyFleet(missile);
            fleet1.RecieveFireFromEnemyFleet(missile2);
            fleet1.RecieveFireFromEnemyFleet(missile3);
            fleet1.RecieveFireFromEnemyFleet(missile4);

            Assert.That(fleet1.TotalNumberOfLosses, Is.EqualTo(0)); // should not be updated yet
            Assert.That(fleet1.SizeofActiveFleet, Is.EqualTo(15));

            Assert.That(fleet1.SpaceShipsInService[1].IsShieldDown());
            Assert.That(fleet1.SpaceShipsInService[10].IsShieldDown());
            Assert.That(fleet1.SpaceShipsInService[8].IsShieldDown());
            Assert.That(fleet1.SpaceShipsInService[8].IsDestroyed()); // should still be in service

            fleet1.Ceasefire();
            // shields should not regen
            Assert.That(fleet1.SpaceShipsInService[1].IsShieldDown());
            Assert.That(fleet1.SpaceShipsInService[9].IsShieldDown());
            Assert.That(fleet1.TotalNumberOfLosses, Is.EqualTo(1));
            Assert.That(fleet1.SizeofActiveFleet, Is.EqualTo(14));
        }
Exemple #2
0
        public void TestMissileHitsRightTarget()
        {
            TargetingMissile missile = new TargetingMissile(15, 1);
            fleet1.NewBattleCommencing(3);
            fleet1.RecieveFireFromEnemyFleet(missile);
            Assert.That(fleet1.TotalNumberOfLosses, Is.EqualTo(0)); // should not be updated yet
            Assert.That(fleet1.SizeofActiveFleet, Is.EqualTo(2));

            // ship two should have been hit, and shields should be down
            Assert.That(fleet1.SpaceShipsInService[1].IsShieldDown());
            // ship two should not have been hit
            Assert.That(!fleet1.SpaceShipsInService[0].IsShieldDown());
        }
 public void TestMissileConfigurationCanNotBeChanged()
 {
     TargetingMissile missile = new TargetingMissile(10, 2);
     Assert.That(missile.DamageAmount, Is.EqualTo(10));
     Assert.That(missile.TargetShipPosition, Is.EqualTo(2));
 }
Exemple #4
0
        /// <summary>
        /// Recives a incomming missile from the enemy fleet. The missile will
        /// deal it's specified damage to the target ship in this 
        /// fleet. This Fleet will also update it's battle information on the 
        /// ship that has been hit. Will have no effect if missile targets invalid ship
        /// </summary>
        /// <param name="incommingMissile"></param>
        public void RecieveFireFromEnemyFleet(TargetingMissile incommingMissile)
        {
            if (incommingMissile.TargetShipPosition > SpaceShipsInService.Length ||
                incommingMissile.TargetShipPosition < 0)
            {
                return;
            }
            SpaceShip spaceShipUnderAttack =
                SpaceShipsInService[incommingMissile.TargetShipPosition];

            spaceShipUnderAttack.RecieveDamage(incommingMissile.DamageAmount);
            UpdateBattleInformation(incommingMissile.TargetShipPosition);
        }
Exemple #5
0
 /// <summary>
 /// Recives an array of incomming missile from the enemy fleet.
 /// The missiles will deal their specified damage to the target ships 
 /// in this fleet. This Fleet will also update it's battle information on the 
 /// ships that have been hit. Will have no effect if missile targets invalid ships
 /// </summary>
 /// <param name="incommingMissiles"></param>
 public void RecieveFireFromEnemyFleet(TargetingMissile[] incommingMissiles)
 {
     foreach (TargetingMissile targetingMissile in incommingMissiles)
     {
         RecieveFireFromEnemyFleet(targetingMissile);
     }
 }
Exemple #6
0
 /// <summary>
 /// Fires the fleet's targeting missiles. 
 /// </summary>
 /// <returns></returns>
 public TargetingMissile[] FireTargetingMissiles()
 {
     TargetingMissile[] attackMissiles = new TargetingMissile[SpaceShipsInService.Length];
     for (int index = 0; index < SpaceShipsInService.Length; index++)
     {
         SpaceShip spaceShip = SpaceShipsInService[index];
         int damagePayload = spaceShip.FireWeapons();
         int enemyTargetPosition = DetermineEnemyTargetPosition();
         attackMissiles[index] = new TargetingMissile(damagePayload, enemyTargetPosition);
     }
     return attackMissiles;
 }
Exemple #7
0
 public void TestTargetAndReciveDamageToFleet()
 {
     TargetingMissile missile = new TargetingMissile(1000, 0);
     fleet1.RecieveFireFromEnemyFleet(missile);
     Assert.That(fleet1.TotalNumberOfLosses, Is.EqualTo(0)); // should not be updated yet
     Assert.That(fleet1.SizeofActiveFleet, Is.EqualTo(2));
     fleet1.Ceasefire();
     Assert.That(fleet1.TotalNumberOfLosses, Is.EqualTo(1));
     Assert.That(fleet1.SizeofActiveFleet, Is.EqualTo(1));
     Assert.That(fleet1.IsFleetOperational(), Is.EqualTo(true));
 }