Question: Part 1 General Combat Scenario [ 5 0 % ] To make things simple, you first stimulate a general combat scenario between two characters by
Part General Combat Scenario
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 OfficeCombat 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
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
CharacterString 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 hurtint attackAmount: Reduce the energy level of the character by the specific amount of attackAmount. Returns the amount of energy reduced from the attack
int attackWeapon w: 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:
WeaponString 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 shotused 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, OfficeCombat is given to test your program. Here is the code in the main method of the class:
java
import java.io;
public class OfficeCombat
public static void mainString args throws IOException
InputStreamReader isr new InputStreamReaderSystemin;
BufferedReader inData new BufferedReaderisr;
Input combat data
String cinfo inData.readLinesplit;
String cinfo inData.readLinesplit;
String winfo inData.readLinesplit;
String winfo inData.readLinesplit;
Character c new Charactercinfo Integer.valueOfcinfo Integer.valueOfcinfo;
Character c new Charactercinfo Integer.valueOfcinfo Integer.valueOfcinfo;
Weapon w new Weaponwinfo Integer.valueOfwinfo;
Weapon w new Weaponwinfo Integer.valueOfwinfo;
Start fighting
System.out.printlnNow fighting: cgetName VS cgetName;
System.out.printlnSkill level of cgetName: cgetSkillLevel;
System.out.printlnSkill level of cgetName: cgetSkillLevel;
System.out.printlnEnergy level of cgetName: cgetEnergyLevel;
System.out.printlnEnergy level of cgetName: cgetEnergyLevel;
System.out.println;
int round ;
while cisLose && cisLose
if round
int attackAmount cattackw;
int hurtAmount churtattackAmount;
System.out.printlncgetName makes an attack by wgetName;
System.out.printlncgetName takes a hurt of hurtAmount Remaining energy becomes cgetEnergyLevel;
else
int attackAmount cattackw;
int hurtAmount churtattackAmount;
System.out.printlncgetName makes an attack by wgetName;
System.out.printlncgetName takes a hurt of hurtAmount Remaining energy becomes cgetEnergyLevel;
round;
if cisLose
System.out.printlncgetName wins!";
else
System.out.printlncgetName wins!";
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
