COMP2396
Loading...
Searching...
No Matches
Student.java
Go to the documentation of this file.
1package assignment2;
2
3/**
4 * The Student is poor and can only afford using a BadGun. However, he/she can
5 * hide to dodge an attack and receive 0 hurt.
6 * It is a subclass of the Character class.
7 */
8public class Student extends Character {
9 private boolean isHidden = false;
10
11 /**
12 * Constructs a new Student with the specified name, energy level, and skill level.
13 *
14 * @param name the name of the student
15 * @param energyLevel the initial energy level of the student
16 * @param skillLevel the skill level of the student
17 */
18 public Student(String name, int energyLevel, int skillLevel) {
19 super(name, energyLevel, skillLevel);
20 }
21
22 /**
23 * Hides the student from the next attack. When hidden, the student takes no damage.
24 */
25 public void hide() {
26 isHidden = true;
27 }
28
29 /**
30 * Calculates the amount of hurt taken from an attack.
31 * If the student is hidden, they take no damage.
32 * Otherwise, reduces the energy level by the attack amount.
33 *
34 * @param attackAmount the amount of attack received
35 * @return the actual amount of energy reduced from the attack
36 */
37 @Override
38 public int hurt(int attackAmount) {
39 if (isHidden) {
40 isHidden = false;
41 return 0;
42 } else {
43 return super.hurt(attackAmount);
44 }
45 }
46}
The Character class represents any game character with a name, skill level, and energy level.
Definition Character.java:7
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
Student(String name, int energyLevel, int skillLevel)
Constructs a new Student with the specified name, energy level, and skill level.
Definition Student.java:18