예제 #1
0
        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.");
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
            }
        }