-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonster.java
More file actions
73 lines (60 loc) · 1.85 KB
/
Monster.java
File metadata and controls
73 lines (60 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.Random;
public class Monster {
private String monsterName;
private String[] monsterMoves;
private double[] damage;
private double monsterHealth;
private double monsterMaxHealth;
private static int monstersKilled;
private int killBenefits;
Random rand = new Random();
public Monster(String mName, String[] mMoves, double[] mDamage, double health, int benefits) {
this.monsterName = mName;
this.monsterMoves = mMoves;
this.damage = mDamage;
this.monsterHealth = health;
this.killBenefits = benefits;
}
/* Returns the Monsters Health */
public String getName() {
return this.monsterName;
}
/* Monster's Attack Function */
public double attack() {
int maxInt = 4;
int randAttack = rand.nextInt(maxInt);
if (randAttack == 0) {
return damage[0];
} else if (randAttack == 1) {
return damage[1];
} else if (randAttack == 2) {
return 0.0;
} else {
addHealth(50);
return 0.17845;
}
}
/* Returns Current Health of the Monster */
public double getHealth() {
return monsterHealth;
}
/* Sets Health */
public void setHealth(double newHealth) {
this.monsterHealth = newHealth;
}
/* Adds Health */
public void addHealth(double x) {
this.monsterHealth += x;
if (this.monsterHealth > this.monsterMaxHealth) {
this.monsterHealth = this.monsterMaxHealth;
}
}
/* Subtracts Health */
public void subtractHealth(double x) {
this.monsterHealth -= x;
}
/* Returns money to the player after monster killed */
public int onKilled() {
return this.killBenefits;
}
}