// Accept 2 Warriors public static string GetAttackResult(Warrior warriorA, Warrior warriorB) { // Calculate one Warriors attack and the others block double warAAttkAmt = warriorA.Attack(); double warBBlkAmt = warriorB.Block(); // Subtract block from attack double dmg2WarB = warAAttkAmt - warBBlkAmt; // If there was damage subtract that from the health if (dmg2WarB > 0) { warriorB.Health = warriorB.Health - dmg2WarB; } else { dmg2WarB = 0; } // Print out info on who attacked who and for how // much damage Console.WriteLine("{0} Attacks {1} and Deals {2} Damage", warriorA.Name, warriorB.Name, dmg2WarB); // Provide output on the change to health Console.WriteLine("{0} Has {1} Health\n", warriorB.Name, warriorB.Health); // Check if the warriors health fell below // zero and if so print a message and send // a response that will end the loop if (warriorB.Health <= 0) { Console.WriteLine("{0} has Died and {1} is Victorious\n", warriorB.Name, warriorA.Name); return("Game Over"); } else { return("Fight Again"); } }
public static void Attack(Warrior warriorA, Warrior warriorB) { int attack = warriorA.Attack(); int block = warriorB.Block(); int damage; if ((attack - block) < 0) { damage = 0; } else { damage = attack - block; } warriorB.Health -= damage; Console.WriteLine($"{warriorA.Name} attacked {warriorB.Name} dealing {damage} damage"); Console.WriteLine($"{warriorB.Name} has {warriorB.Health} Health"); Console.WriteLine(); }
public static string GetAttackResult(Warrior warriorA, Warrior warriorB) { // calculate one warriors attack and the others block double warriorAAttack = warriorA.Attack(); double warriorBBlock = warriorB.Block(); // subtract block from attack double damageToB = warriorAAttack - warriorBBlock; // if there was damage subtract that from the health of the defender if (damageToB > 0) { warriorB.HealthMax = warriorB.HealthMax - damageToB; } else { damageToB = 0; } // Print out who attacked who and for how much damage Console.WriteLine("{0} deals a blow to {1} with the damage of {2}", warriorA.Name, warriorB.Name, damageToB); // provide info on change in health Console.WriteLine("{0} has {1} health \n", warriorB.Name, warriorB.HealthMax); // check if the warriors heath fell bellow zero if so then print message and stop loop if (warriorB.HealthMax <= 0) { Console.WriteLine("{0} has died and {1} is the victor", warriorB.Name, warriorA.Name); return("Game Over"); } else { return("Fight again"); } }
private static int AttackRound(Warrior gladiator) { return(gladiator.Attack()); }