Uploaded by Tohma Taniguchi

Monster.java(key)

advertisement
// CSE 110
: MWF 3:05p-3:55p
// Assignment : 7
// Author
: Jasmin Smith
// Description : This class holds the methods of the monsters name, health score,
and weapon
class Monster {
private String name;
private int healthScore;
private Weapon weapon;
sh
Th
is
ar stu
ed d
vi y re
aC s
o
ou urc
rs e
eH w
er as
o.
co
m
public Monster(String a, int b, Weapon c){
name = a;
healthScore= b;
weapon = c;
}//an overloaded constructor that takes three arguments (String, int, Weapon)
and passes variables to arguments
public String getName() {
//should just return a copy of the value currently stored in the object's
name variable.
return name;
}
public int getHealthScore(){
//should just return a copy of the value currently stored in the object's
healthScore variable.
return healthScore;
}
public String getWeaponName(){
//should just return this monster's weapon's name
return weapon.getName(); // to call the weapon's getName
}
public int attack(Monster a){
//Pick a random int between 0 and this Monster's Weapon's maxDamage
int attackDamage = (int)(Math.random()* this.weapon.getMaxDamage());
//Subtract this amount from the argument Monster's healthScore
a.healthScore = a.healthScore - attackDamage;
// Return the number of points of damage that this attack inflicted
return attackDamage;
}
}
This study source was downloaded by 100000781658667 from CourseHero.com on 03-31-2021 16:24:00 GMT -05:00
https://www.coursehero.com/file/59243622/Monsterjava/
Powered by TCPDF (www.tcpdf.org)
Download