-
Notifications
You must be signed in to change notification settings - Fork 0
/
Elixir.java
55 lines (48 loc) · 1.69 KB
/
Elixir.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
package sample;
import javafx.scene.control.TextArea;
/**
* Created by Sonia on 10/6/2015.
*/
public class Elixir extends Item
{
TextArea outScreen;
int numUses;
public Elixir(TextArea outScreen, String itemName, int healthBonus, int strengthBonus, int numUses)
{
super(itemName, healthBonus, strengthBonus);
this.numUses = numUses;
this.outScreen = outScreen;
}
public void use(Player player)
{
player.setHealth(healthBonus);
if(player.getHealth() > player.getHealthMax())
{
player.setHealth(player.getHealthMax());
}
player.setStrength(strengthBonus);
outScreen.appendText("Health: " + player.getHealth() + "/" + player.getHealthMax()+"\n");
outScreen.appendText("Strength: " + player.getStrength()+"\n");
numUses --;
if (numUses == 0)
{
outScreen.appendText(itemName +" is empty. You throw it into the appropriate recycling bin.\n");
player.removeItem(this);
}
else if (numUses == 1)
{
outScreen.appendText("You have one use left.\n");
}
else
{
outScreen.appendText("You have " + numUses + " uses left.\n");
}
}
public void listEffects()
{
outScreen.appendText("This is the " + itemName + ".\n");
outScreen.appendText(" It adds " + healthBonus + " points to your health.\n");
outScreen.appendText(" It adds " + strengthBonus + " points to your strength.\n");
outScreen.appendText(" You can use it " + numUses + " times\n");
}
}