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

The Weapon class represents any game weapon with a name and power level. More...

Inheritance diagram for assignment2.Weapon:
Collaboration diagram for assignment2.Weapon:

Public Member Functions

 Weapon (String name, int power)
 Constructs a new Weapon with the specified name and power level.
 
String getName ()
 Returns the name of the weapon.
 
int shoot ()
 Simulates shooting the weapon and returns the power generated.
 

Private Attributes

final int power
 
final String weaponName
 

Detailed Description

The Weapon class represents any game weapon with a name and power level.

A weapon can be used to shoot and generate power for attacks.

Definition at line 7 of file Weapon.java.

Constructor & Destructor Documentation

◆ Weapon()

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

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

Parameters
namethe name of the weapon
powerthe power level of the weapon

Definition at line 17 of file Weapon.java.

17 {
18 this.weaponName = name;
19 this.power = Math.max(0, power);
20 }
final int power
Definition Weapon.java:9

References assignment2.Weapon.power.

Member Function Documentation

◆ getName()

String assignment2.Weapon.getName ( )
inline

Returns the name of the weapon.

Returns
the weapon's name

Definition at line 27 of file Weapon.java.

27 {
28 return weaponName;
29 }
final String weaponName
Definition Weapon.java:8

References assignment2.Weapon.weaponName.

Referenced by assignment2.OfficeCombat1.main(), and assignment2.OfficeCombat2.main().

Here is the caller graph for this function:

◆ shoot()

int assignment2.Weapon.shoot ( )
inline

Simulates shooting the weapon and returns the power generated.

Returns
the power generated by the weapon

Reimplemented in assignment2.BadGun, and assignment2.SuperGun.

Definition at line 36 of file Weapon.java.

36 {
37 return power;
38 }

References assignment2.Weapon.power.

Referenced by assignment2.Character.attack().

Here is the caller graph for this function:

Member Data Documentation

◆ power

final int assignment2.Weapon.power
private

◆ weaponName

final String assignment2.Weapon.weaponName
private

Definition at line 8 of file Weapon.java.

Referenced by assignment2.Weapon.getName().


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