Question: Part 1 General Combat Scenario [ 5 0 % ] To make things simple, you first stimulate a general combat scenario between two characters by

Part 1 General Combat Scenario [50%]
To make things simple, you first stimulate a general combat scenario between two characters by implementing two classes:
The Character class, which represents any game character.
The Weapon class, which represents any game weapon.
The OfficeCombat1 class is provided to simulate the fighting event. Both characters will hold a weapon and take turns to combat with each other. They have specific energy level at the beginning and lose energy upon being attacked by the weapon. The character loses if his energy level drops equal to or smaller than 0.
Implementation
The Character class:
Properties
String characterName: Name of the character
int skillLevel: Weapon skill level of the character
int energyLevel: Remaining energy of the character. The character loses when this value drops to zero or below.
Methods (all methods must be public)
Character(String name, int energyLevel, int skillLevel): Constructor, which setup the three properties accordingly
String getName(): Return the name of the character
int getSkillLevel(): Return the skill level of the character
int getEnergyLevel(): Return the remaining energy level of the character
int hurt(int attackAmount): Reduce the energy level of the character by the specific amount of attackAmount. Returns the amount of energy reduced from the attack
int attack(Weapon w1): Return the total amount of attack generated by the character. It is the sum of power of the weapon generated from the shoot and the skill level of the character.
boolean isLose(): Return true if the characters energy level drops to zero or below.
The Weapon class:
Properties:
String weaponName: Name of the weapon
int power: Power level of the weapon
Methods (all methods must be public):
Weapon(String name, int power): Constructor, which setup the two properties accordingly
String getName(): Return the name of the weapon
int shoot(): Return the power generated when the weapon is shot/used, in which it equals to the power level of the weapon
You may add additional properties and methods to these two classes.
The Main Program
A sample main class, OfficeCombat1 is given to test your program. Here is the code in the main method of the class:
```java
import java.io.*;
public class OfficeCombat1{
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader inData = new BufferedReader(isr);
// Input combat data
String c1_info[]= inData.readLine().split("");
String c2_info[]= inData.readLine().split("");
String w1_info[]= inData.readLine().split("");
String w2_info[]= inData.readLine().split("");
Character c1= new Character(c1_info[0], Integer.valueOf(c1_info[1]), Integer.valueOf(c1_info[2]));
Character c2= new Character(c2_info[0], Integer.valueOf(c2_info[1]), Integer.valueOf(c2_info[2]));
Weapon w1= new Weapon(w1_info[0], Integer.valueOf(w1_info[1]));
Weapon w2= new Weapon(w2_info[0], Integer.valueOf(w2_info[1]));
// Start fighting
System.out.println("Now fighting: "+ c1.getName()+" VS "+ c2.getName());
System.out.println("Skill level of "+ c1.getName()+": "+ c1.getSkillLevel());
System.out.println("Skill level of "+ c2.getName()+": "+ c2.getSkillLevel());
System.out.println("Energy level of "+ c1.getName()+": "+ c1.getEnergyLevel());
System.out.println("Energy level of "+ c2.getName()+": "+ c2.getEnergyLevel());
System.out.println("----------------------------");
int round =0;
while (!c1.isLose() && !c2.isLose()){
if (round %2==0){
int attackAmount = c1.attack(w1);
int hurtAmount = c2.hurt(attackAmount);
System.out.println(c1.getName()+" makes an attack by "+ w1.getName()+"!");
System.out.println(c2.getName()+" takes a hurt of "+ hurtAmount +"! Remaining energy becomes "+ c2.getEnergyLevel()+".");
}
else {
int attackAmount = c2.attack(w2);
int hurtAmount = c1.hurt(attackAmount);
System.out.println(c2.getName()+" makes an attack by "+ w2.getName()+"!");
System.out.println(c1.getName()+" takes a hurt of "+ hurtAmount +"! Remaining energy becomes "+ c1.getEnergyLevel()+".");
}
round++;
}
if (c1.isLose()){
System.out.println(c2.getName()+" wins!");
}
else {
System.out.println(c1.getName()+" wins!");
}
}
}
```

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 Programming Questions!