COMP2396
Loading...
Searching...
No Matches
OfficeCombat2.java
Go to the documentation of this file.
1package assignment2;
2import java.io.*;
3
4public class OfficeCombat2 {
5 public static void main(String[] args) throws IOException {
6 InputStreamReader isr = new InputStreamReader(System.in);
7 BufferedReader inData = new BufferedReader(isr);
8
9 // Input combat data
10 String c1_info[] = inData.readLine().split(" ");
11 String c2_info[] = inData.readLine().split(" ");
12 String w1_info[] = inData.readLine().split(" ");
13 String w2_info[] = inData.readLine().split(" ");
14
15 SecurityGuard c1 = new SecurityGuard(c1_info[0], Integer.valueOf(c1_info[1]), Integer.valueOf(c1_info[2]));
16 Student c2 = new Student(c2_info[0], Integer.valueOf(c2_info[1]), Integer.valueOf(c2_info[2]));
17 SuperGun w1 = new SuperGun(w1_info[0], Integer.valueOf(w1_info[1]));
18 BadGun w2 = new BadGun(w2_info[0], Integer.valueOf(w2_info[1]));
19
20 // Start fighting
21 System.out.println("Now fighting: " + c1.getName() + " VS " + c2.getName());
22 System.out.println("Skill level of " + c1.getName() + ": " + c1.getSkillLevel());
23 System.out.println("Skill level of " + c2.getName() + ": " + c2.getSkillLevel());
24 System.out.println("Energy level of " + c1.getName() + ": " + c1.getEnergyLevel());
25 System.out.println("Energy level of " + c2.getName() + ": " + c2.getEnergyLevel());
26 System.out.println("----------------------------");
27
28 int round = 0;
29 while (!c1.isLose() && !c2.isLose()) {
30 if (round % 2 == 0) {
31 int attackAmount = c1.attack(w1);
32 System.out.println(c1.getName() + " makes an attack by " + w1.getName() + "!");
33
34 int hurtAmount = c2.hurt(attackAmount);
35 if (hurtAmount == 0) {
36 System.out.println(c2.getName() + " hides from the attack!");
37 }
38 else {
39 System.out.println(c2.getName() + " takes a hurt amount of " + hurtAmount + "! Remaining energy becomes " + c2.getEnergyLevel() + ".");
40 }
41
42 if (round % 3 == 0) {
43 c2.hide();
44 }
45 }
46 else {
47 int attackAmount = c2.attack(w2);
48 int hurtAmount = c1.hurt(attackAmount);
49
50 System.out.println(c2.getName() + " makes an attack by " + w2.getName() + "!");
51 System.out.println(c1.getName() + " takes a hurt amount of " + hurtAmount + "! Remaining energy becomes " + c1.getEnergyLevel() + ".");
52
53 if (round % 3 == 0) {
54 c1.boostWeapon(w1);
55 System.out.println(c1.getName() + " boost the " + w1.getName() + "!");
56 }
57 }
58 round++;
59 }
60
61 if (c1.isLose()) {
62 System.out.println(c2.getName() + " wins! The examination paper is stolen!");
63 }
64 else {
65 System.out.println(c1.getName() + " wins! The examination paper is secured!");
66 }
67 }
68}
The BadGun has poor quality such that at each shot, only 80% of its original power can be produced (r...
Definition BadGun.java:8
int hurt(int attackAmount)
Reduces the energy level of the character by the specified attack amount.
boolean isLose()
Determines whether the character has lost the combat.
int getSkillLevel()
Returns the skill level of the character.
int getEnergyLevel()
Returns the current energy level of the character.
int attack(Weapon w1)
Calculates the total attack amount generated by the character.
String getName()
Returns the name of the character.
static void main(String[] args)
The SecurityGuard is well-funded by the department and must use a SuperGun.
void boostWeapon(SuperGun w1)
Boosts the specified SuperGun for the next attack.
The Student is poor and can only afford using a BadGun.
Definition Student.java:8
void hide()
Hides the student from the next attack.
Definition Student.java:25
int hurt(int attackAmount)
Calculates the amount of hurt taken from an attack.
Definition Student.java:38
The SuperGun can produce a boosted shot, such that the shot produces two times power than the origina...
Definition SuperGun.java:8
String getName()
Returns the name of the weapon.
Definition Weapon.java:27