private void WriteLastStatus(LivingThings fighter1, LivingThings fighter2) { LivingThings aliveOne = fighter1.IsAlive ? fighter1 : fighter2; LivingThings deadOne = fighter1.IsAlive ? fighter2 : fighter1; Console.WriteLine($"{aliveOne.Name} defeated {deadOne.Name} with {aliveOne.Health} HP remaining."); }
public void Hit(LivingThings fighter1, LivingThings fighter2) { int roundCount = CalculateRoundCount(fighter1, fighter2); fighter1.Health -= fighter2.AttackPower * roundCount; fighter2.Health -= fighter1.AttackPower * roundCount; WriteLastStatus(fighter1, fighter2); }
private int CalculateRoundCount(LivingThings fighter1, LivingThings fighter2) { int roundCount1 = (fighter2.Health % fighter1.AttackPower == 0) ? fighter2.Health / fighter1.AttackPower : (fighter2.Health / fighter1.AttackPower) + 1; int roundCount2 = (fighter1.Health % fighter2.AttackPower == 0) ? fighter1.Health / fighter2.AttackPower : (fighter1.Health / fighter2.AttackPower) + 1; if (roundCount1 <= roundCount2) { return(roundCount1); } else { return(roundCount2); } }