private void ProcessStarshipBattle(IStarship attackingShip, IStarship targetShip)
        {
            this.ValidateAlive(attackingShip);
            this.ValidateAlive(targetShip);

            var battleLocation = attackingShip.Location;
            if (targetShip.Location != battleLocation)
            {
                throw new ShipException(Messages.NoSuchShipInStarSystem);
            }

            var attack = attackingShip.ProduceAttack();
            targetShip.RespondToAttack(attack);
            Console.WriteLine(Messages.ShipAttacked, attackingShip.Name, targetShip.Name);

            if (targetShip.Shields < 0)
            {
                targetShip.Shields = 0;
            }

            if (targetShip.Health <= 0)
            {
                targetShip.Health = 0;
                Console.WriteLine(Messages.ShipDestroyed, targetShip.Name);
            }
        }
        private void ProcessStarshipBattle(IStarship attackerShip, IStarship targetShip)
        {
            base.ValidateAlive(attackerShip);
            base.ValidateAlive(targetShip);

            if (attackerShip.Location != targetShip.Location)
            {
                throw new ShipException(Messages.NoSuchShipInStarSystem);
            }

            IProjectile attack = attackerShip.ProduceAttack();

            targetShip.RespondToAttack(attack);

            Console.WriteLine(Messages.ShipAttacked, attackerShip.Name, targetShip.Name);

            if (targetShip.Shields < 0)
            {
                targetShip.Shields = 0;
            }

            if (targetShip.Health <= 0)
            {
                targetShip.Health = 0;
                Console.WriteLine(Messages.ShipDestroyed, targetShip.Name);
            }
        }
Beispiel #3
0
        private void ProcessStarshipBattle(IStarship attackerShip, IStarship defenderShip)
        {
            if (attackerShip.Health <= 0 || defenderShip.Health <= 0)
            {
                throw new ShipException(Messages.ShipAlreadyDestroyed);
            }
            if (attackerShip.Location.Name != defenderShip.Location.Name)
            {
                throw new ShipException(Messages.NoSuchShipInStarSystem);
            }

            IProjectile attack = attackerShip.ProduceAttack();

            defenderShip.RespondToAttack(attack);

            Console.WriteLine(string.Format(Messages.ShipAttacked, attackerShip.Name, defenderShip.Name));
            if (defenderShip.Shields < 0)
            {
                defenderShip.Shields = 0;
            }
            if (defenderShip.Health <= 0)
            {
                defenderShip.Health = 0;
                Console.WriteLine(Messages.ShipDestroyed, defenderShip.Name);
            }
        }
        private void ProcessStarShipBattle(IStarship attackingShip, IStarship targetShip)
        {
            base.ValidateAlive(attackingShip);
            base.ValidateAlive(targetShip);

            if (attackingShip.Location.Name != targetShip.Location.Name)
            {
                throw new LocationOutOfRangeException(String.Format("{0} and {1} are not in the same galaxy!",
                                                                    attackingShip.Name, targetShip.Name));
            }

            IProjectile attack = attackingShip.ProduceAttack();

            targetShip.RespondToAttack(attack);

            Console.WriteLine(Messages.ShipAttacked, attackingShip.Name, targetShip.Name);

            if (targetShip.Shields < 0)
            {
                targetShip.Shields = 0;
            }

            if (targetShip.Health <= 0)
            {
                targetShip.Health = 0;
                Console.WriteLine(Messages.ShipDestroyed, targetShip.Name);
            }
        }
        private void ProcessStarShipBattle(IStarship attackShip, IStarship defenceShip)
        {
            base.ValidateAlive(attackShip);
            base.ValidateAlive(defenceShip);

            if (attackShip.Location.Name != defenceShip.Location.Name)
            {
                throw new LocationOutOfRangeException(Messages.NoSuchShipInStarSystem);
            }

            IProjectile attack = attackShip.ProduceAttack();
            defenceShip.RespondToAttack(attack);

            Console.WriteLine(Messages.ShipAttacked, attackShip.Name, defenceShip.Name);

            if (defenceShip.Shields < 0)
            {
                defenceShip.Shields = 0;
            }

            if (defenceShip.Health < 0)
            {
                defenceShip.Health = 0;
                Console.WriteLine(Messages.ShipDestroyed, defenceShip.Name);
            }
        }
        private void ProcessStarShipBattle(IStarship attackingShip, IStarship targetShip)
        {
            base.ValidateAlive(attackingShip);
            base.ValidateAlive(targetShip);

            if (attackingShip.Location.Name != targetShip.Location.Name)
                throw new LocationOutOfRangeException(String.Format("{0} and {1} are not in the same galaxy!",
                    attackingShip.Name, targetShip.Name));

            IProjectile attack = attackingShip.ProduceAttack();
            targetShip.RespondToAttack(attack);

            Console.WriteLine(Messages.ShipAttacked, attackingShip.Name, targetShip.Name);

            if (targetShip.Shields < 0)
            {
                targetShip.Shields = 0;
            }

            if (targetShip.Health <= 0)
            {
                targetShip.Health = 0;
                Console.WriteLine(Messages.ShipDestroyed, targetShip.Name);
            }
        }
Beispiel #7
0
        private void ProcessStartShipBattle(IStarship attackingShip, IStarship targetShip)
        {
            this.ValidateShipExistance(attackingShip);//проверка дали не са разрушени, т.е. не съществуват
            this.ValidateShipExistance(targetShip);

            var battleLocation = attackingShip.Location;

            if (targetShip.Location != battleLocation)
            {
                throw new ShipException(Messages.NoSuchShipInStarSystem);
            }

            //сблъсък!!!

            // създаваме обект от тип интерфейс, който има в себе си int Damage { get; set; } и  void Hit(IStarship ship);
            IProjectile attack = attackingShip.ProduceAttack();

            targetShip.RespondToAttack(attack);                                            //мишената е ударена и има поражения

            Console.WriteLine(Messages.ShipAttacked, attackingShip.Name, targetShip.Name); //обратна връзка


            if (targetShip.Health < 0)//дали е разрушен кораба при атаката
            {
                targetShip.Health = 0;
                Console.WriteLine(Messages.ShipDestroyed, targetShip.Name);
            }

            if (targetShip.Shields < 0)
            {
                targetShip.Shields = 0;
            }
        }
Beispiel #8
0
        public override void Execute(string[] commandArgs)
        {
            string attackerShip = commandArgs[1];
            string targetShip   = commandArgs[2];

            IStarship attacker = base.GameEngine
                                 .Starships
                                 .Where(ship => ship.Name == attackerShip)
                                 .First();
            IStarship target = base.GameEngine
                               .Starships
                               .Where(ship => ship.Name == targetShip)
                               .First();

            if (attacker.Health == 0 || target.Health == 0)
            {
                throw new ShipException(Messages.ShipAlreadyDestroyed);
            }

            if (!attacker.Location.NeighbourStarSystems.ContainsKey(target.Location) &&
                attacker.Location != target.Location)
            {
                throw new ShipException(Messages.NoSuchShipInStarSystem);
            }

            target.RespondToAttack(attacker.ProduceAttack());

            Console.WriteLine(string.Format(Messages.ShipAttacked, attackerShip, targetShip));

            if (target.Health == 0)
            {
                Console.WriteLine(string.Format(Messages.ShipDestroyed, targetShip));
            }
        }
        private void ProcessStartShipBattle(IStarship attackingShip, IStarship targetShip)
        {
            this.ValidateShipExistance(attackingShip);//проверка дали не са разрушени, т.е. не съществуват
            this.ValidateShipExistance(targetShip);

            var battleLocation = attackingShip.Location;
            if (targetShip.Location != battleLocation)
            {
                throw new ShipException(Messages.NoSuchShipInStarSystem);
            }

            //сблъсък!!!

            // създаваме обект от тип интерфейс, който има в себе си int Damage { get; set; } и  void Hit(IStarship ship);
            IProjectile attack = attackingShip.ProduceAttack();

            targetShip.RespondToAttack(attack);//мишената е ударена и има поражения

            Console.WriteLine(Messages.ShipAttacked, attackingShip.Name, targetShip.Name);//обратна връзка

            if (targetShip.Health < 0)//дали е разрушен кораба при атаката
            {
                targetShip.Health = 0;
                Console.WriteLine(Messages.ShipDestroyed, targetShip.Name);
            }

            if (targetShip.Shields < 0)
            {
                targetShip.Shields = 0;
            }
        }
        private void ProcessStarshipBattle(IStarship attackingShip, IStarship targetShip)
        {
            base.ValidateAlive(attackingShip);
            base.ValidateAlive(targetShip);

            IProjectile attack = attackingShip.ProduceAttack();
            targetShip.RespondToAttack(attack);

            Console.WriteLine(Messages.ShipAttacked, attackingShip.Name, targetShip.Name);

            if (targetShip.Shields < 0)
            {
                targetShip.Shields = 0;
            }

            if (targetShip.Health <= 0)
            {
                targetShip.Health = 0;
                Console.WriteLine(Messages.ShipDestroyed, targetShip.Name);
            }
        }
Beispiel #11
0
 private void ProcessShipBattle(IStarship attackingShip, IStarship targetShip)
 {
     base.ValidateAlive(attackingShip);
     base.ValidateAlive(targetShip);
     if (!ShipsInSameStarSystem(attackingShip, targetShip))
     {
         throw new LocationOutOfRangeException(Messages.NoSuchShipInStarSystem);
     }
     IProjectile attack = attackingShip.ProduceAttack();
     targetShip.RespondToAttack(attack);
     System.Console.WriteLine(Messages.ShipAttacked, attackingShip.Name, targetShip.Name);
     if (targetShip.Shields < 0)
     {
         targetShip.Shields = 0;
     }
     if (targetShip.Health <= 0)
     {
         targetShip.Health = 0;
         System.Console.WriteLine(Messages.ShipDestroyed, targetShip.Name);
     }
 }
        private void ProcessStarShipBattle(IStarship attackerShip, IStarship targetShip)
        {
            base.ValidateAlive(attackerShip);
            base.ValidateAlive(targetShip);

            base.ValidateAreShipInTheSameStarSystem(attackerShip, targetShip);

            var attack = attackerShip.ProduceAttack();
            targetShip.RespondToAttack(attack);

            Console.WriteLine(Messages.ShipAttacked, attackerShip.Name, targetShip.Name);

            if (targetShip.Shields < 0)
            {
                targetShip.Shields = 0;
            }

            if (targetShip.Health < 0)
            {
                targetShip.Health = 0;
                Console.WriteLine(Messages.ShipDestroyed, targetShip.Name);
            }
        }
Beispiel #13
0
        private void ProcessStarshipBattle(IStarship attackingShip, IStarship targetShip)
        {
            this.ValidateAlive(attackingShip);
            this.ValidateAlive(targetShip);

            this.ValidateIsInTheSameStarSystem(attackingShip, targetShip);

            IProjectile attack = attackingShip.ProduceAttack();

            targetShip.RespondToAttack(attack);

            Console.WriteLine(Messages.ShipAttacked, attackingShip.Name, targetShip.Name);

            if (targetShip.Shields < 0)
            {
                targetShip.Shields = 0;
            }

            if (targetShip.Health < 0)
            {
                targetShip.Health = 0;
                Console.WriteLine(Messages.ShipDestroyed, targetShip.Name);
            }
        }
Beispiel #14
0
        private void ProcessStarshipBattle(IStarship attackShip, IStarship targetShip)
        {
            ValidateAlive(attackShip);
            ValidateAlive(targetShip);

            if (attackShip.Location != targetShip.Location)
            {
                throw new LocationOutOfRangeException("The ships are in the different star systems!");
            }

            IProjectile attack = attackShip.ProduceAttack();
            targetShip.RespondToAttack(attack);
            Console.WriteLine(Messages.ShipAttacked, attackShip, targetShip);

            if (targetShip.Shields < 0)
            {
                targetShip.Shields = 0;
            }
            if (targetShip.Health < 0)
            {
                targetShip.Health = 0;
                Console.WriteLine(Messages.ShipDestroyed, targetShip.Name);
            }
        }
Beispiel #15
0
 public void Hit(IStarship ship)
 {
     ship.RespondToAttack(this);
 }