COMP2396
Loading...
Searching...
No Matches
assignment2.SuperGun Class Reference

The SuperGun can produce a boosted shot, such that the shot produces two times power than the original. More...

Inheritance diagram for assignment2.SuperGun:
Collaboration diagram for assignment2.SuperGun:

Public Member Functions

 SuperGun (String name, int power)
 Constructs a new SuperGun with the specified name and power level.
 
void boost ()
 Boosts the gun for the next attack.
 
int shoot ()
 Shoots the gun.
 
- Public Member Functions inherited from assignment2.Weapon
 Weapon (String name, int power)
 Constructs a new Weapon with the specified name and power level.
 
String getName ()
 Returns the name of the weapon.
 

Private Attributes

boolean isBoosted = false
 

Detailed Description

The SuperGun can produce a boosted shot, such that the shot produces two times power than the original.

It is a subclass of the Weapon class.

Definition at line 8 of file SuperGun.java.

Constructor & Destructor Documentation

◆ SuperGun()

assignment2.SuperGun.SuperGun ( String name,
int power )
inline

Constructs a new SuperGun with the specified name and power level.

Parameters
namethe name of the super gun
powerthe power level of the super gun

Definition at line 17 of file SuperGun.java.

17 {
18 super(name, power);
19 }
final int power
Definition Weapon.java:9

References assignment2.Weapon.power.

Member Function Documentation

◆ boost()

void assignment2.SuperGun.boost ( )
inline

Boosts the gun for the next attack.

Definition at line 24 of file SuperGun.java.

24 {
25 isBoosted = true;
26 }

References assignment2.SuperGun.isBoosted.

Referenced by assignment2.SecurityGuard.boostWeapon().

Here is the caller graph for this function:

◆ shoot()

int assignment2.SuperGun.shoot ( )
inline

Shoots the gun.

If boosted, the power is doubled for the attack. Resets the boosting effect after the shot.

Returns
the power generated by the weapon

Reimplemented from assignment2.Weapon.

Definition at line 35 of file SuperGun.java.

35 {
36 if (isBoosted) {
37 isBoosted = false;
38 return super.shoot() * 2;
39 } else {
40 return super.shoot();
41 }
42 }

References assignment2.SuperGun.isBoosted.

Member Data Documentation

◆ isBoosted

boolean assignment2.SuperGun.isBoosted = false
private

Definition at line 9 of file SuperGun.java.

Referenced by assignment2.SuperGun.boost(), and assignment2.SuperGun.shoot().


The documentation for this class was generated from the following file: