-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
85 lines (73 loc) · 2.06 KB
/
Player.java
File metadata and controls
85 lines (73 loc) · 2.06 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
74
75
76
77
78
79
80
81
82
83
84
85
package game;
import java.util.ArrayList;
import java.util.List;
public class Player extends Creature {
public static List<Item> inv = new ArrayList<>();
public Item inHand;
/*
* Possibly develop method of keeping item stacks,
* possibly with an Item class stored in an array.
* do more research.
*/
public void equipInHand(Item itemToEquip) {
if (itemToEquip instanceof Weapon) {
Mainclass.player.inHand = itemToEquip;
Mainclass.player.atk = Weapon.calculateAtk(Mainclass.player, (Weapon) itemToEquip);
removeFromInv(itemToEquip);
}
}
public void setName(String newPlayerName) {
this.name = newPlayerName;
}
public void storeInInv(String itemName) {
inv.add(Item.stringToDisplay(itemName));
}
public static void removeFromInv(Item itemName) {
for (int i = 0; i < inv.size(); i++) {
if (inv.get(i).equals(itemName)) {
inv.remove(i);
}
}
}
public void getInventory() {
try {
for (int i = 0; i < inv.size(); i++) {
System.out.println(inv.get(i).displayName);
}
}
catch (Exception NullPointerException) {
}
}
public static Boolean isCraftable(String itemToCraft) {
// ex itemToCraft: wood_sword
if (Item.stringToItem(itemToCraft) == null) {
System.out.println("That item is not craftable");
return false;
} else {
return true;
}
}
public int numInInv(String itemName) {
int itemCount = 0;
for (int i = 0; i < inv.size();) {
if (inv.get(i).displayName.equals(itemName)) {
itemCount = itemCount + 1;
}
i = i + 1;
}
return itemCount;
}
public String getSpecificInv(String indexStr) {
try {
int index = Integer.parseInt(indexStr);
index = index - 1;
return inv.get(index).displayName;
}
catch (Exception IndexOutOfBounds) {
return "There are no items in that slot.";
}
}
public Player(String name, int health, int atk, Armor Head, Armor Chest, Armor Legs, Armor Feet, Item onHand, Item offHand) {
super(name, health, atk, Head, Chest, Legs, Feet, onHand, offHand);
}
}