-
Notifications
You must be signed in to change notification settings - Fork 0
/
Items.pde
128 lines (121 loc) · 2.77 KB
/
Items.pde
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright 2017 Billy Brown
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*
* Provide a static index of items to be used in the game.
*/
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
static final Map<String, Item> index = new HashMap<String, Item>();
static void buildItemsIndex() {
final Item[] items = new Item[] {
new Item(
"Iron Sword", // Name
Item.Slot.HAND, // Slot
6, // Weight
Item.Modifier.ATTACK, // Effect
1), // Modifier
new Item(
"Chain Mail",
Item.Slot.BODY,
12,
Item.Modifier.DEFENCE,
2),
new Item(
"Fleet Boots",
Item.Slot.FEET,
2,
Item.Modifier.SPEED,
1),
new Item(
"Cold Steel Mace",
Item.Slot.HAND,
10,
Item.Modifier.ATTACK,
2),
new Item(
"Mithril Shirt",
Item.Slot.BODY,
6,
Item.Modifier.DEFENCE,
4),
new Item(
"Headband of Strength",
Item.Slot.HEAD,
1,
new Stats(1, 0, 0)), // Stats modifiers
new Item(
"Potion of Healing",
Item.Slot.USE,
1,
Item.Modifier.HEALTH,
8),
new Item(
"Greater Potion of Healing",
Item.Slot.USE,
1,
Item.Modifier.HEALTH,
16),
new Item(
"Belt of Health",
Item.Slot.BELT,
1,
Item.Modifier.HEALTH,
8),
new Item(
"Boots of Dodge",
Item.Slot.FEET,
2,
new Stats(0, 2, 0)),
new Item(
"Boots of Dodge",
Item.Slot.FEET,
2,
new Stats(0, 2, 0)),
new Item(
"Punching Cape",
Item.Slot.BODY,
4,
Item.Modifier.ATTACK,
2),
new Item(
"Cestus of Fury",
Item.Slot.HAND,
3,
new Stats(2, 0, 0)),
new Item(
"Bashing Shield",
Item.Slot.HAND,
8,
new Stats(1, 1, 0)), // This is a way of increasing attack and defence
new Item(
"Anduril",
Item.Slot.HAND,
7,
Item.Modifier.ATTACK,
5)
};
for (final Item item : items) {
insertItem(item);
}
}
static void insertItem(final Item item) {
index.put(item.name, item);
}
static Item getItem(final String name) {
return index.get(name).clone();
}
static Item getRandomItem() {
final int choice = new Random().nextInt(index.size());
int counter = 0;
for (final Item item : index.values()) {
if (choice == counter++) {
return item;
}
}
return null;
}