Question: Add a method called battle. This method takes, as parameters, 2 heroes and a number of rounds to fight. Your battle method should use a

Add a method called battle. This method takes, as parameters, 2 heroes and a number of rounds to fight. Your battle method should use a loop to run the round methods, with the heroes as input to round. Battleshould return the hero with the most health after all rounds have completed. Handle ties either with a tie-breaker that adds another round to the battle or by prompting each hero user to roll the 12-sided die picking the winner by highest roll.

Add a method called tournament. This method takes, as parameters, an array of heroes. This method runs a single elimination tournament on all the heroes. The method should call the battle method for pairs of heroes in the array. Each battle in the tournament lasts for 3 rounds. After the tournament has completed, return the hero object that is the winner of the entire tournament

Test your changes to the battle manager by creating a main class that:

- Creates a battle manager

- Creates 2 heroes and battles tehm for 5 rounds. using the battle method.

- Creates an array of 5 hero objects

- Calls the tournament method with your array

- Below is a sample class with a main method that generates an array of heroes which can be used in the code

Add a method called battle. This method takes, as parameters, 2 heroes

Modify this Battle_Manager class:

import java.util.Scanner;

public class Battle_Manager

{

public static void main(String[] args) {

}

public Hero setupHero(String name)

{

Hero h = new Hero(name);

return h;

}

public void round(Hero h1, Hero h2) {

// takes two hero objects, prompts user to select moves, performs moves with damage

int choice;

do {

System.out.println("Enter thy move by number: ");

System.out.println("1. Allow " + h1.getName() + " to attack " + h2.getName());

System.out.println("2. Allow " + h1.getName() + " to defend thyself");

System.out.println("3. Allow " + h2.getName() + " to attack " + h1.getName());

System.out.println("4. Alow " + h2.getName() + " to defend thyself");

System.out.println("5. Add health");

System.out.println("6. Remove health");

System.out.println("7. Stop thy game if completed");

Scanner sc = new Scanner(System.in);

choice = sc.nextInt();

switch (choice)

{

case 1:

h1.attack();

break;

case 2:

h1.defend();

break;

case 3:

h2.attack();

break;

case 4:

h2.defend();

break;

case 5:

System.out.println("1. Give to " + h1.getName());

System.out.println("2. Give to " + h2.getName());

int x = sc.nextInt();

// adds health to hero

System.out.println("Enter thy health value");

int health = sc.nextInt();

if (x == 1)

{

h1.addHealth(health);

}

else

{

h2.addHealth(health);

}

break;

case 6:

// removes health to particlar hero

System.out.println("1. Remove from " + h1.getName());

System.out.println("2. Remove from " + h2.getName());

int y = sc.nextInt();

System.out.println("Enter thy health value to remove");

int health1 = sc.nextInt();

if (y == 1)

{

h1.removeHealth(health1);

}

else

{

h2.removeHealth(health1);

}

break;

case 7:

return;

default:

System.out.println("ERROR, enter a correct input");

}

}

while (choice != 7);

}

}

public class Hero

{

// value constructor

public Hero(int strength, int agility, String name)

{

this.strength = strength;

this.agility = agility;

this.name = name;

this.health = defaultHealth;

this.stamina = defaultStamina;

}

public Hero(String name)

{

this.name = name;

this.health = defaultHealth;

this.stamina = defaultStamina;

this.strength = defaultStrength;

this.agility = defaultAgility;

}

// gets strength

public int getStrength()

{

return strength;

}

// sets strength

public void setStrength(int strength)

{

if (strength

{

System.out.println("ERROR, thy strength cannot be negative");

}

this.strength = strength;

}

// returns agility

public int getAgility()

{

return agility;

}

// sets agility value

public void setAgility(int agility)

{

if (agility

{

System.out.println("ERROR, thy agility cannot be negative");

}

this.agility = agility;

}

// gets health

public int getHealth()

{

return health;

}

// sets health

public void setHealth(int health)

{

this.health = health;

}

// returns stamina

public int getStamina()

{

return stamina;

}

// sets stamina

public void setStamina(int stamina)

{

if (stamina

{

System.out.println("ERROR, thy strength cannot be negative");

}

this.stamina = stamina;

}

public String getName()

{

return name;

}

// returns name

public void setName(String name)

{

this.name = name;

}

private int strength, agility, health, stamina;

private String name;

public static final int attacking = 6, defending = 4;

public static final int defaultHealth = 50, defaultStamina = 25, defaultStrength = 5, defaultAgility = 5;

// adds health

public void addHealth(int health)

{

if (health

{

System.out.println("ERROR, thy value being added cannot be negative");

}

else

{

this.health += health;

}

}

// removes health

public void removeHealth(int health)

{

if (health

{

System.out.println("ERROR, thy value being substracted cannot be negative");

}

else

{

this.health -= health;

}

}

// prints the hero's name, strength, agility, stamina, and health stats

public void printStats()

{

System.out.println(" Hero: ");

System.out.println("Thy hero's name is: " + name + " Strength: " + strength + " Agility: " + agility + " Stamina: " + stamina + " Health: " + health + " ");

}

// returns the defend value

public int defend()

{

int defendValue;

if (stamina

{

defendValue = 0;

System.out.println(name + " has rested");

rest();

}

// decreases hero's stamina after defending

else

{

Die dii = new Die(20);

dii.roll();

defendValue = agility + dii.getValue();

setStamina(stamina - this.defending);

}

return defendValue;

}

// returns the attack value

public int attack()

{

int attackValue;

if (stamina

{

attackValue = 0;

System.out.println(name + " has rested");

rest();

}

// decreases hero's stamina after attacking

else

{

Die d = new Die(20);

d.roll();

attackValue = strength + d.getValue();

setStamina(stamina - this.attacking);

}

return attackValue;

}

// adds to strength and agility triggered by attack/defend

private void rest()

{

Die twelve = new Die(12);

Die eight = new Die(8);

Die ten = new Die(10);

// rolls all the die

twelve.roll();

eight.roll();

ten.roll();

// gets die value

int x = twelve.getValue();

int y = eight.getValue();

int z = ten.getValue();

// assigns maximum value to strength and other die's sum to agility

if (x > y && x > z)

{

setStrength(x);

setAgility(y + z);

}

else if (y > x && y > z)

{

setStrength(y);

setAgility(x + z);

}

else

{

setAgility(x + y);

setStrength(z);

}

}

}

public class Main public static final int INITIAL SIZE = 12; public static void main (String[ args) BattleManager manager = new BattleManager); //an array of names to be used when creating heroes final Stringi names "Hiro Protagonist", "Bruce Lee", "Chuck Norris","Luke Cage", "Frank Castle", "Danny Rand", "Jessica Jones", "Mathew Murdock" "Wilson Fisk", "victor Von Doom", "Jean Grey", "Elektra Natchios", "Steven Rogers", "James Howlett", "Wade Wilson", "Bruce Banner", "Peter Parker","Tony Stark","Susan Storm-Richards" //create an array of heroes Hero[i 11st new HeroINITIALSIZE] for (int i = 0; ?? 113t.length; i++) //using mod to cycle through array names could be randomly selected String name-names[4 names. length]; list [1] = manager.setup (name); //Use the array and the battlemanager to run a tournament. Hero winner - manager.tournament (list) System.out.println ("Winner of heroes is "+ winner.getName)) public class Main public static final int INITIAL SIZE = 12; public static void main (String[ args) BattleManager manager = new BattleManager); //an array of names to be used when creating heroes final Stringi names "Hiro Protagonist", "Bruce Lee", "Chuck Norris","Luke Cage", "Frank Castle", "Danny Rand", "Jessica Jones", "Mathew Murdock" "Wilson Fisk", "victor Von Doom", "Jean Grey", "Elektra Natchios", "Steven Rogers", "James Howlett", "Wade Wilson", "Bruce Banner", "Peter Parker","Tony Stark","Susan Storm-Richards" //create an array of heroes Hero[i 11st new HeroINITIALSIZE] for (int i = 0; ?? 113t.length; i++) //using mod to cycle through array names could be randomly selected String name-names[4 names. length]; list [1] = manager.setup (name); //Use the array and the battlemanager to run a tournament. Hero winner - manager.tournament (list) System.out.println ("Winner of heroes is "+ winner.getName))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!