コード例 #1
0
        public static string GetAttackResult(Warrior warriorA, Warrior warriorB)
        {
            double warriorAattack = warriorA.Attack();
            double warriorBblock  = warriorB.Block();

            double dmg2warriorB = warriorAattack - warriorBblock;

            if (dmg2warriorB > 0)
            {
                warriorB.Health = warriorB.Health - dmg2warriorB;
            }
            else
            {
                dmg2warriorB = 0;
            }

            Console.WriteLine("{0} Attacks {1} and Deals {2} Damage", warriorA.Name, warriorB.Name, dmg2warriorB);

            Console.WriteLine("{0} Has {1} Health \n", warriorB.Name, warriorB.Health);
            if (warriorB.Health <= 0)
            {
                Console.WriteLine("{0} has Died and {1} is Victorious\n", warriorA.Name, warriorB.Name);
                return("Game Over");
            }
            else
            {
                return("Fight Again");
            }
        }
コード例 #2
0
        // Get AttackResult
        // WarriorA, WarriorB
        // Calculate 1 warriors attack and the other block
        // Subtrack block from attack
        // If there was damage subtract that from the health
        // Print out info on who attacked who and for how much damage
        public static string GetAttackResult(Warrior warriorA, Warrior warriorB)
        {
            double warAAttackAmount = warriorA.Attack();
            double warBBlockAmount  = warriorB.Block();
            double damage2WarB      = warAAttackAmount - warBBlockAmount;

            if (damage2WarB > 0)
            {
                warriorB.Health = warriorB.Health - damage2WarB;
            }
            else
            {
                damage2WarB = 0;
            }
            Console.WriteLine($"{warriorA.Name} Attack {warriorB.Name} and Deals {damage2WarB} Domage");
            Console.WriteLine($"{warriorB.Name} Has {warriorB.Health} Health");

            if (warriorB.Health <= 0)
            {
                Console.WriteLine($"{warriorB.Name} has Died and {warriorA.Name} is Victorius");
                return("Game Over");
            }
            else
            {
                return("Fight Again");
            }
        }