private static void ExecuteAttack(Tank tankA, Tank tankB) { while (tankB.Health > 0) { tankA.Shoot(tankB); } }
public void Shoot(Tank enemy) { if (this.Shells == 0) { throw new TankException("Not enough shells to shoot"); } enemy.Health -= ShellDamage; this.Shells--; Console.WriteLine("Left enemy Health after the shoot: {0}, left shells: {1}", enemy.Health,this.Shells); }
static void Main() { try { var germanTank = new Tank(300); var russianTank = new Tank(200); ExecuteAttack(germanTank, russianTank); } catch (TankException ex) { Console.WriteLine(ex.Message); } }