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

The Character class represents any game character with a name, skill level, and energy level. More...

Inheritance diagram for assignment2.Character:
Collaboration diagram for assignment2.Character:

Public Member Functions

 Character (String name, int energyLevel, int skillLevel)
 Constructs a new Character with the specified name, energy level, and skill level.
 
int attack (Weapon w1)
 Calculates the total attack amount generated by the character.
 
int getEnergyLevel ()
 Returns the current energy level of the character.
 
String getName ()
 Returns the name of the character.
 
int getSkillLevel ()
 Returns the skill level of the character.
 
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.
 

Private Attributes

final String characterName
 
int energyLevel
 
final int skillLevel
 

Detailed Description

The Character class represents any game character with a name, skill level, and energy level.

A character can attack using a weapon and can be hurt by attacks.

Definition at line 7 of file Character.java.

Constructor & Destructor Documentation

◆ Character()

assignment2.Character.Character ( String name,
int energyLevel,
int skillLevel )
inline

Constructs a new Character with the specified name, energy level, and skill level.

Parameters
namethe name of the character
energyLevelthe initial energy level of the character
skillLevelthe skill level of the character

Definition at line 19 of file Character.java.

19 {
20 this.characterName = name;
21 this.energyLevel = Math.max(0, energyLevel);
22 this.skillLevel = Math.max(0, skillLevel);
23 }

References assignment2.Character.energyLevel, and assignment2.Character.skillLevel.

Member Function Documentation

◆ attack()

int assignment2.Character.attack ( Weapon w1)
inline

Calculates the total attack amount generated by the character.

It is the sum of the weapon's power and the character's skill level.

Parameters
w1the weapon used for the attack
Returns
the total attack amount

Definition at line 70 of file Character.java.

70 {
71 return w1.shoot() + this.skillLevel;
72 }

References assignment2.Weapon.shoot(), and assignment2.Character.skillLevel.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getEnergyLevel()

int assignment2.Character.getEnergyLevel ( )
inline

Returns the current energy level of the character.

Returns
the character's current energy level

Definition at line 48 of file Character.java.

48 {
49 return energyLevel;
50 }

References assignment2.Character.energyLevel.

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

Here is the caller graph for this function:

◆ getName()

String assignment2.Character.getName ( )
inline

Returns the name of the character.

Returns
the character's name

Definition at line 30 of file Character.java.

30 {
31 return characterName;
32 }
final String characterName
Definition Character.java:8

References assignment2.Character.characterName.

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

Here is the caller graph for this function:

◆ getSkillLevel()

int assignment2.Character.getSkillLevel ( )
inline

Returns the skill level of the character.

Returns
the character's skill level

Definition at line 39 of file Character.java.

39 {
40 return skillLevel;
41 }

References assignment2.Character.skillLevel.

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

Here is the caller graph for this function:

◆ hurt()

int assignment2.Character.hurt ( int attackAmount)
inline

Reduces the energy level of the character by the specified attack amount.

Parameters
attackAmountthe amount of energy to reduce
Returns
the actual amount of energy reduced

Reimplemented in assignment2.Student.

Definition at line 58 of file Character.java.

58 {
59 this.energyLevel -= attackAmount;
60 return attackAmount;
61 }

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

Here is the caller graph for this function:

◆ isLose()

boolean assignment2.Character.isLose ( )
inline

Determines whether the character has lost the combat.

A character loses if their energy level is zero or below.

Returns
true if the character has lost, false otherwise

Definition at line 80 of file Character.java.

80 {
81 return this.energyLevel <= 0;
82 }

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

Here is the caller graph for this function:

Member Data Documentation

◆ characterName

final String assignment2.Character.characterName
private

Definition at line 8 of file Character.java.

Referenced by assignment2.Character.getName().

◆ energyLevel

◆ skillLevel


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