-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enemy.java
61 lines (54 loc) · 2.27 KB
/
Enemy.java
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
public class Enemy implements Encounter
{
String name;
int maxHealth, health, ATKLow, ATKHigh;
int gold;
/**
* The Enemy constructor takes in 5 parameters to be assigned to various things in the enemy. These 5 values are name, maxHealth, ATKLow, ATKHigh, and gold.
* @param n: This string that is taken in is then assigned to the name value
* @param mH: This integer is assigned to the maxHealth value, and that value is also assigned to the health value, as they will always start with max health
* @param ATKL: This integer is the lowest value in the range of values that represent the amount of damage that the monster can deal
* @param ATKH: This integer is the highest value in the range of values that represent the amount of damage that the monster can deal
* @param g: This integer is assigned to gold and represents the amount of the gold that the player will receive when they kill the monster.
*/
public Enemy ( String n , int mH, int ATKL, int ATKH, int g )
{
name = n;
maxHealth = mH;
health = maxHealth;
ATKLow = ATKL;
ATKHigh = ATKH;
gold = g;
} // end constructor method.
public String getName()
{
return name;
}
public int getHP()
{
return health;
}
public void setHP( int newHP )
{
health = newHP;
}
/**
* A random number is generated within the range of the low and high damage of the enemy. This damage is taken
* and is subtracted from the health of the target using the setHP method. A message is then printed saying how much damage was dealt
* @param target: The target paramater is used to show who the damage is being dealth to. Both of the objects will be in an array when this is done so that they can be processed polymorphically.
*/
public void Attack( Encounter target)
{
int damage = (int) (Math.random() * ( ATKHigh - ATKLow )) + ATKLow ;
target.setHP( target.getHP() - damage );
System.out.println( damage + " damage was dealt to " + target.getName());
} // end method attack()
public int getGold()
{
return gold;
}
public void setGold( Encounter x )
{
gold = gold + x.getGold();
}
}