COMP2396
Loading...
Searching...
No Matches
SuperGun.java
Go to the documentation of this file.
1package assignment2;
2
3/**
4 * The SuperGun can produce a boosted shot, such that the shot produces two times
5 * power than the original.
6 * It is a subclass of the Weapon class.
7 */
8public class SuperGun extends Weapon {
9 private boolean isBoosted = false;
10
11 /**
12 * Constructs a new SuperGun with the specified name and power level.
13 *
14 * @param name the name of the super gun
15 * @param power the power level of the super gun
16 */
17 public SuperGun(String name, int power) {
18 super(name, power);
19 }
20
21 /**
22 * Boosts the gun for the next attack.
23 */
24 public void boost() {
25 isBoosted = true;
26 }
27
28 /**
29 * Shoots the gun. If boosted, the power is doubled for the attack.
30 * Resets the boosting effect after the shot.
31 *
32 * @return the power generated by the weapon
33 */
34 @Override
35 public int shoot() {
36 if (isBoosted) {
37 isBoosted = false;
38 return super.shoot() * 2;
39 } else {
40 return super.shoot();
41 }
42 }
43}
The SuperGun can produce a boosted shot, such that the shot produces two times power than the origina...
Definition SuperGun.java:8
int shoot()
Shoots the gun.
Definition SuperGun.java:35
void boost()
Boosts the gun for the next attack.
Definition SuperGun.java:24
SuperGun(String name, int power)
Constructs a new SuperGun with the specified name and power level.
Definition SuperGun.java:17
The Weapon class represents any game weapon with a name and power level.
Definition Weapon.java:7
final int power
Definition Weapon.java:9