public Warrior HumanChooseDinosaurToFight(Battlefield battlefield) { string msg; int selection; bool valid = false; do { Console.WriteLine("Choose a dinosaur: "); for (int i = 0; i < Warriors.Count; i++) { Console.WriteLine($"{i + 1}) {Warriors[i].Name} | Power Level: {Warriors[i].Stamina}"); } valid = Int32.TryParse(Console.ReadLine(), out selection); if (valid) { valid = selection > 0 && selection <= Warriors.Count; selection--; } if (valid && Warriors[selection].Stamina <= 0) { valid = false; msg = $"{Warriors[selection].Name} has no power to fight."; Console.WriteLine(msg); } if (!valid) { battlefield.UpdateStatsDisplay(); } } while (!valid); return(Warriors[selection]); }
public Warrior HumanChooseTargetRobot(Fleet fleet, Battlefield battlefield) { int selection; bool valid = false; do { Console.WriteLine("Choose a robot to attack: "); for (int i = 0; i < fleet.Warriors.Count; i++) { Console.WriteLine($"{i + 1}) {fleet.Warriors[i].Name} | Health: {fleet.Warriors[i].Health}"); } valid = Int32.TryParse(Console.ReadLine(), out selection); if (valid) { valid = (selection > 0 && selection <= fleet.Warriors.Count); selection--; } if (!valid) { battlefield.UpdateStatsDisplay(); } } while (!valid); return(fleet.Warriors[selection]); }
// Human attack consisting of choosing attack type. Calls GetHit method on target robot. public override float HumanChooseAttackType(Warrior targetWarrior, Random rng, Battlefield battlefield) { // Set to 0 in case of miss. float hitAmount = 0f; int selection; bool valid = false; // Verify input is valid before continuing. do { Console.WriteLine("Choose an Attack: "); for (int i = 0; i < attackTypes.Length; i++) { Console.WriteLine($"{i + 1}) {attackTypes[i]} Hit Chance: {attackTypeModifierHitChance[i]}% Bonus: x{attackTypesModifiers[i]} damage"); } valid = Int32.TryParse(Console.ReadLine(), out selection); if (valid) { valid = (selection > 0 && selection <= attackTypes.Length); selection--; } if (!valid) { battlefield.UpdateStatsDisplay(); } } while (!valid); // Calculate if the attack hits based on attack type hit chace. if (rng.Next(101) < attackTypeModifierHitChance[selection]) { // Calculate damage based on attack type modifier bonus. hitAmount = AttackPower * attackTypesModifiers[selection]; } return(targetWarrior.GetHit(this, hitAmount)); }