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; } }
public override void Execute(string[] commandArgs) { string shipName = commandArgs[1]; IStarship ship = this.GetStarshipByName(shipName); System.Console.WriteLine(ship.ToString()); }
public void TravelTo(IStarship ship, StarSystem destination) { if (ship.Health <= 0) { throw new ShipException("Ship is destroyed!"); } var startLocation = ship.Location; if (!startLocation.NeighbourStarSystems.ContainsKey(destination)) { throw new LocationOutOfRangeException(string.Format( "Cannot travel directly from {0} to {1}", startLocation.Name, destination.Name)); } if (ship.Location.Name.Equals(destination.Name)) { throw new ShipException(string.Format(Messages.ShipAlreadyInStarSystem, destination.Name)); } double requiredFuel = startLocation.NeighbourStarSystems[destination]; if (ship.Fuel < requiredFuel) { throw new InsufficientFuelException(string.Format( "Not enough fuel to travel to {0} - {1}/{2}", destination.Name, ship.Fuel, requiredFuel)); } ship.Fuel -= requiredFuel; ship.Location = destination; }
protected void ValidateAlive(IStarship ship) { if (ship.Health <= 0) { throw new ShipException(Messages.ShipAlreadyDestroyed); } }
protected void ValidateAlive(IStarship ship) { if (ship.Health <= 0) { throw new ShipException("Ship is Destroyed!"); } }
public override void Execute(string[] commandArgs) { string shipName = commandArgs[1]; string starSystemName = commandArgs[2]; IStarship starShip = base.GameEngine .Starships .Where(ship => ship.Name == shipName) .First(); if (starShip.Location.Name == starSystemName) { throw new ShipException(string.Format(Messages.ShipAlreadyInStarSystem, starSystemName)); } StarSystem oldLocation = starShip.Location; StarSystem destination = base.GameEngine .Galaxy .GetStarSystemByName(starSystemName); base.GameEngine.Galaxy.TravelTo(starShip, destination); destination.Starships.Add(starShip); oldLocation.Starships.Remove(starShip); Console.WriteLine( string.Format( Messages.ShipTraveled, starShip.Name, oldLocation.Name, destination.Name)); }
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 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); } }
public override void Execute(string[] commandArgs) { string shipType = commandArgs[1]; string shipName = commandArgs[2]; string shipLocation = commandArgs[3]; bool isShipCreatedAlready = GameEngine.Starships.Any(s => s.Name == shipName); if (isShipCreatedAlready) { throw new ShipException(Messages.DuplicateShipName); } StarshipType type = (StarshipType)Enum.Parse(typeof(StarshipType), shipType); StarSystem location = GameEngine.Galaxy.GetStarSystemByName(shipLocation); IStarship starship = GameEngine.ShipFactory.CreateShip(type, shipName, location); GameEngine.Starships.Add(starship); for (int i = 4; i < commandArgs.Length; i++) { EnhancementType enhancementType = (EnhancementType)Enum.Parse(typeof(EnhancementType), commandArgs[i]); Enhancement enhancement = GameEngine.EnhancementFactory.Create(enhancementType); starship.AddEnhancement(enhancement); } Console.WriteLine(string.Format(Messages.CreatedShip, shipType, shipName)); }
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 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) { 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 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); } }
public void ValidateAlive(IStarship ship) { if (ship.Health <= 0) { throw new ShipException(Messages.ShipAlreadyDestroyed); } }
public void ValidateStarSystem(IStarship ship, IStarship otherShip) { if (ship.Location.Name != otherShip.Location.Name) { throw new LocationOutOfRangeException("Ships not from the same Star system!"); } }
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); } }
protected void ValidateAreShipInTheSameStarSystem(IStarship attackShip, IStarship targetShip) { if (attackShip.Location != targetShip.Location) { throw new ShipException(Messages.NoSuchShipInStarSystem); } }
protected void ValidateAlive(IStarship ship) { if (ship.Health <= 0) { throw new ShipException(string.Format(Messages.ShipDestroyed, ship.Name)); } }
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); } }
public override void Execute(string[] commandArgs) { //create {shipType} {shipName} {starSystem} {enhancement1 enhancements2 ...} StarshipType starshipType = CastStringToStarshipType(commandArgs[1]); string starshipName = commandArgs[2]; if (GetStarshipByName(starshipName) != null) { Console.WriteLine(Messages.DuplicateShipName); } string starshipLocation = commandArgs[3]; var ship = new ShipFactory(); IStarship starship = ship.CreateShip(starshipType, starshipName, this.GameEngine.Galaxy.GetStarSystemByName(starshipLocation)); if (commandArgs.Length > 3) { var enhancementFactory = new EnhancementFactory(); for (int i = 4; i < commandArgs.Length; i++) { starship.AddEnhancement( enhancementFactory .Create(CastStringToEnhancementType(commandArgs[i]))); } } this.GameEngine.Starships.Add(starship); Console.WriteLine(Messages.CreatedShip, starshipType, starshipName); }
public override void Execute(string[] commandArgs) { string shipName = commandArgs[1]; IStarship ship = this.GameEngine.Starships.First(s => s.Name == shipName); Console.WriteLine(ship.ToString()); }
public void TravelTo(IStarship ship, StarSystem destination) { var startLocation = ship.Location; if (!startLocation.NeighbourStarSystems.ContainsKey(destination)) { throw new LocationOutOfRangeException( string.Format( "Cannot travel directly from {0} to {1}", startLocation.Name, destination.Name)); } double requiredFuel = startLocation.NeighbourStarSystems[destination]; if (ship.Fuel < requiredFuel) { throw new InsufficientFuelException( string.Format( "Not enough fuel to travel to {0} - {1}/{2}", destination.Name, ship.Fuel, requiredFuel)); } ship.Fuel -= requiredFuel; ship.Location = destination; }
public void TravelTo(IStarship ship, StarSystem destination) { var startLocation = ship.Location; if (!startLocation.NeighbourStarSystems.ContainsKey(destination)) { throw new LocationOutOfRangeException( string.Format("Cannot travel directly from {0} to {1}", startLocation.Name, destination.Name)); } double requiredFuel = startLocation.NeighbourStarSystems[destination]; if (ship.Fuel < requiredFuel) { throw new InsufficientFuelException( string.Format( "Not enough fuel to travel to {0} - {1}/{2}", destination.Name, ship.Fuel, requiredFuel)); } ship.Fuel -= requiredFuel; ship.Location = destination; }
private void ValidateIsInTheSameStarSystem(IStarship attackingShip, IStarship targetShip) { if (attackingShip.Location != targetShip.Location) { throw new ShipException(Messages.NoSuchShipInStarSystem); } }
/// <summary> /// The validate alive. /// </summary> /// <param name="ship"> /// The ship. /// </param> /// <exception cref="ShipException"> /// </exception> protected void ValidateAlive(IStarship ship) { if (ship.Health <= 0) { throw new ShipException(Messages.ShipDestroyed); } }
public override void Hit(IStarship ship) { ship.Shields -= this.Damage; if (this.Damage - ship.Shields > 0) { ship.Health -= this.Damage - ship.Shields; } }
private void LoadEnhancements(IStarship currentShip, string[] commandArgs) { for (int i = 4; i < commandArgs.Length; i++) { EnhancementType currentType = GetEnhancementType(commandArgs[i]); currentShip.AddEnhancement(this.GameEngine.EnhancementFactory.Create(currentType)); } }
public override void Hit(IStarship targetShip) { targetShip.Shields -= this.Damage; if (this.Damage > targetShip.Shields) { targetShip.Health -= this.Damage - targetShip.Shields; } }
public override void Execute(string[] commandArgs) { string attackerName = commandArgs[1]; string targetName = commandArgs[2]; IStarship attackingShip = GetStarshipByName(attackerName), targetShip = GetStarshipByName(targetName); this.ProcessStarshipBattle(attackingShip, targetShip); }
private bool ShipsInSameStarSystem(IStarship ship1, IStarship ship2) { if (ship1.Location.Name == ship2.Location.Name) { return true; } else return false; }
public override void Hit(IStarship ship) { ship.Shields -= this.Damage; if (ship.Shields < 0) { ship.Health += ship.Shields; } }
public void testConsumptionDetailUOMDay() { IStarship starshipbase = starship; IStarshipMeasures starshipmeasures = starship; starshipbase.consumables = "1 Day"; Assert.AreEqual(starshipmeasures.consumptiondetail.uom, Swapi.Program.Enums.UOM.Day); }
public void testConsumptionDetailWrongUom() { IStarship starshipbase = starship; IStarshipMeasures starshipmeasures = starship; starshipbase.consumables = "1 dd"; Assert.AreEqual(starshipmeasures.consumptiondetail.uom, Swapi.Program.Enums.UOM.Invalid); }
public void testMgltConversion() { IStarship starshipbase = starship; IStarshipMeasures starshipmeasures = starship; starshipbase.MGLT = "100"; Assert.AreEqual(starshipmeasures.MGLTConverted, 100); }
public void testConsumptionDetailInvalidConsumableForTime() { IStarship starshipbase = starship; IStarshipMeasures starshipmeasures = starship; starshipbase.consumables = ""; Assert.AreEqual(starshipmeasures.consumptiondetail.Time, -1); }
public override void Hit(IStarship ship) { if (this.Damage > ship.Shields) { var damageFromHealth = this.Damage - ship.Shields; ship.Health -= damageFromHealth; } ship.Shields -= this.Damage; }
public override void Hit(IStarship ship) { if (ship.Health <= 0) { throw new ShipException("Ship is destroyed"); } ship.Health -= this.Damage; }
public override void Hit(IStarship ship) { int healthDamage = this.Damage - ship.Shields; ship.Shields -= this.Damage; if (healthDamage > 0) { ship.Health -= healthDamage; } }
public void Setup() { calculatorService = container.GetInstance <ICalculator>(); parserService = container.GetInstance <IParser>(); redisService = container.GetInstance <IRedis>(); starshipService = container.GetInstance <IStarship>(); mapperService = container.GetInstance <IMapper>(); logger = Substitute.For <ILogger>(); }
public override void Hit(IStarship ship) { ship.Shields -= this.Damage; if (ship.Shields < 0) { ship.Health += ship.Shields; // damageLeft is minus value ship.Shields = 0; } }
public override void Execute(string[] commandArgs) { string attackerName = commandArgs[1]; string targetName = commandArgs[2]; IStarship attackingShip = this.GameEngine.Starships.First(s => s.Name == attackerName); IStarship targetShip = this.GameEngine.Starships.First(s => s.Name == targetName); this.ProcessStarshipbattle(attackingShip, targetShip); }
public override void Hit(IStarship ship) { int damageLeft = this.Damage - ship.Shields; ship.Shields -= this.Damage; if (damageLeft>0) { ship.Health -= damageLeft; } }
public void testMgltUnknown() { IStarship starshipbase = starship; IStarshipMeasures starshipmeasures = starship; starshipbase.MGLT = "Unknown"; Assert.AreEqual(starshipmeasures.MGLTConverted, 0); }
public override void Hit(IStarship targetShip) { targetShip.Shields -= Damage; if (Damage > targetShip.Shields) { int healthTotTake = Damage - targetShip.Shields; targetShip.Health -= healthTotTake; } }
public override void Execute(string[] commandArgs) { string attackingShipName = commandArgs[1]; string defendingShipName = commandArgs[2]; IStarship attackerShip = this.GameEngine.Starships.FirstOrDefault(s => s.Name == attackingShipName); IStarship defenderShip = this.GameEngine.Starships.FirstOrDefault(s => s.Name == defendingShipName); this.ProcessStarshipBattle(attackerShip, defenderShip); }
/// <summary> /// The hit. /// </summary> /// <param name="ship"> /// The ship. /// </param> public override void Hit(IStarship ship) { int remainder = this.Damage - ship.Shields; ship.Shields -= this.Damage; if (remainder > 0) { ship.Health -= remainder; } }
public override void Hit(IStarship targetShip) { int remainderDamage = this.Damage - targetShip.Shields; targetShip.Shields -= this.Damage; if (remainderDamage > 0) { targetShip.Health -= remainderDamage; } }
public override void Hit(IStarship ship) { int diff = this.Damage - ship.Shields; ship.Shields -= this.Damage; if (diff > 0) { ship.Health -= diff; } }
public override void Hit(IStarship ship) { int remainderDamage = ship.Shields - this.Damage; ship.Shields -= this.Damage; if (remainderDamage < 0) { ship.Health += remainderDamage; } }
private void Validate(IStarship ship) { if (ship == null) { throw new ShipException("Ship is null"); } if (ship.Health <= 0) { throw new ShipException(string.Format(Messages.ShipAlreadyDestroyed)); } }
public override void Execute(string[] commandArgs) { string shipName = commandArgs[1]; IStarship starship = base.GameEngine .Starships .Where(ship => ship.Name == shipName) .FirstOrDefault(); System.Console.WriteLine(starship); }
public override void Hit(IStarship ship) { if (ship.Health- base.Damage < 0) { ship.Health = 0; } else { ship.Health -= base.Damage; } }
public override void Hit(IStarship ship) { if (this.Damage > ship.Shields) { ship.Health -= this.Damage - ship.Shields; ship.Shields = 0; } else { ship.Shields -= this.Damage; } }
public override void Hit(IStarship targetShip) { if (targetShip.Shields >= this.Damage) { targetShip.Shields -= this.Damage; } else { targetShip.Health -= this.Damage - targetShip.Shields; targetShip.Shields = 0; } }
// Removes shields from the ship equal to the projectile's damage. // If the damage is more than the ship's shields, it also takes health equal to the damage left. // (e.g. 50 shields and 100 health - a laser of 80 damage would remove 50 shields and 30 health, // resulting in 0 shields and 70 health for the ship). public override void Hit(IStarship ship) { var excessDamage = ship.Shields - this.Damage; if (excessDamage < 0) { ship.Shields = 0; ship.Health += excessDamage; } else { ship.Shields -= this.Damage; } }