-
Notifications
You must be signed in to change notification settings - Fork 2
/
Game.java~
291 lines (235 loc) · 9.41 KB
/
Game.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/**
* Game.java
*
* Known bugs:
* none! :)
*
* @author Emma Shumadine, Lily Orth-Smith, Rachel Zhang
* */
import java.util.*;
public class Game {
private Player player;
private Map myMap;
/**
* Creates a game with the default map
*/
public Game() {
player = new Player();
myMap = makeMap1();
}
/**
* Creates a game with the specified map
* @param userMap the map to use for the game
*/
public Game(Map userMap) {
player = new Player();
myMap = userMap;
}
/**
* Returns the player to the start of the map
*/
public void goToBeginning() {
myMap.goToBeginning();
}
/**
* Moves the player to an adjacent situation given by the index in the adjacency array
* @param adjIndex the index in the adjacency array
*/
public void movePlayer(int adjIndex) {
Situation[] adjacentSituations = myMap.getAdjArray();
movePlayer(adjacentSituations[adjIndex]);
}
/**
* Moves the player to an adjacent situation
* @param adjSit the situation
*/
public void movePlayer(Situation adjSit) {
//check if the player has the required items to enter the situation
if(!adjSit.getRequiredItems().isEmpty()) {
int count = 0;
for (Item i: adjSit.getRequiredItems()) {
if (player.hasItem(i)) {
count++;
}
}
if (count == adjSit.getRequiredItems().size()) {
myMap.changeSituation(adjSit);
} else {
throw new IllegalMoveException();
}
} else {
myMap.changeSituation(adjSit);
}
}
/**
* Picks up an item from the current situation and puts it in the player's inventory
* @param item the item to pick up
*/
public void pickUpItem(Item item) {
myMap.getCurrentSituation().removeItem(item);
player.pickUpItem(item);
}
/**
* Picks up an weapon from the current situation and gives it to the player
* @param item the weapon to pick up
*/
public void pickUpItem(Weapon item) {
myMap.getCurrentSituation().removeItem(item);
player.pickUpWeapon(item);
}
/**
* Removes the item from the player's inventory and drops it into the situation
* @param item the item to drop
*/
public void dropItem(Item item) {
player.dropItem(item);
myMap.getCurrentSituation().addItem(item);
}
/**
* Returns true if the boss has been defeated, and false otherwise
* @return true if the boss has been defeated
*/
public boolean isOver() {
return myMap.isCleared();
}
/**
* Makes the map
* @return the map
*/
public Map makeMap1() {
// beginning
Situation beginning = new Situation("First Room", "You are in a small, dark room.");
Weapon smashBall = new Weapon("Smash Ball", "Final smaaaaaaash! Hit Rate: 1%, 10d100 damage", 0.01, "10d100");
beginning.addItem(smashBall);
// nyan cat room
HealItem rainbowPopTart = new HealItem("A rainbow poptart", "It crosses your mind that this could be nyan cat poop, but as the rainbowy scent wafts "
+ "towards you, you put the thought out of your mind. Heals 5 meme points.", 5);
Vector<Item> dropNyan = new Vector<>();
dropNyan.add(rainbowPopTart);
dropNyan.add(rainbowPopTart.clone());
Situation nyanCats = new Situation("Nyan Cat Attack!", "Some Nyan Cats seem to have made their home here.", dropNyan);
Weapon rainbow = new Weapon("Rainbow Power", "Nyanyanyanyanyanyanya!", 0.7, "1d8");
GameCharacter nyanCat = new GameCharacter(10, rainbow, "A Nyan Cat");
Vector<GameCharacter> manyNyanCats = new Vector<GameCharacter>();
manyNyanCats.add(nyanCat);
manyNyanCats.add(nyanCat.clone());
Fight nyanCatFight = new Fight(player, manyNyanCats);
nyanCats.addFight(nyanCatFight);
// apple room
Vector<Item> apples = new Vector<>();
Item apple = new HealItem("Apple", "A crunchy apple. Can be eaten. Heals 10 meme points.", 10);
apples.add(apple);
apples.add(apple.clone());
Situation forest = new Situation("A wild wood", "You find yourself in what appears to be an abandoned apple orchard. Apples are strewn on the "
+ "ground.", apples);
// sword room
Situation swordRoom = new Situation("A clearing", "You find yourself in a circular clearing. Someone seems to have left a sword here.");
Weapon sword = new Weapon("Sword", "A sharp sword. Hit Rate: 95%, 4d6 damage", 0.95, "4d6");
swordRoom.addItem(sword);
// dat boi room
Situation datBoiRoom = new Situation("The dankest of memes", "You can feel the meme energy in the air.");
Item datBoi = new Item("Dat Boi", "Here comes dat boi!");
datBoiRoom.addItem(datBoi);
// sickle room
Vector<Item> grains = new Vector<>();
Item wheat = new HealItem("Wheat", "A grain of wheat. Heals 5 meme points", 5);
grains.add(wheat);
grains.add(wheat.clone());
Situation sickleRoom = new Situation("A wheat field", "Outside of the woods lies a large wheat field. It looks like someone was in the "
+ "middle of harvesting the wheat, but only their sickle was left behind.", grains);
Weapon sickle = new Weapon("Sickle", "A sickle used for harvesting wheat. Hit Rate: 85%, 3d10 damage", 0.85, "3d10");
sickleRoom.addItem(sickle);
// the second apple room
Vector<Item> apples2 = new Vector<>();
Item apple2 = new HealItem("Apple", "A crunchy apple. Can be eaten.", 10);
apples.add(apple2);
apples.add(apple2.clone());
Situation appleStorage = new Situation("A storehouse", "The storehouse appears not to have been used for some time, but a few apples remain.",
apples2);
// doge room
Situation dogeRoom = new Situation("Shibe", "A doge lives here.");
Weapon suchDamage = new Weapon("Such Damage", "Much wow", 0.8, "3d8");
GameCharacter doge = new GameCharacter(50, suchDamage, "Doge");
Vector<GameCharacter> dogeVector = new Vector<>();
dogeVector.add(doge);
Fight dogeFight = new Fight(player, dogeVector);
dogeRoom.addFight(dogeFight);
Item dogeCoin = new Item("Dogecoin", "Much money");
dogeRoom.addItem(dogeCoin);
// mace room
Situation maceRoom = new Situation("A cottage", "A run-down cottage. Whoever lived here left behind a mace.");
Weapon mace = new Weapon("Mace", "A heavy mace. Hit Rate: 80%, 3d12 damage", 0.8, "3d12");
maceRoom.addItem(mace);
// boss room
Situation cena = new Situation("The Finale", "A wild John Cena appears!");
Weapon sass = new Weapon("Sass", "You call that a weapon?", 0.9, "4d10");
GameCharacter johnCena = new GameCharacter(150, sass, "John Cena");
Vector<GameCharacter> cenaFight = new Vector<>();
cenaFight.add(johnCena);
Fight bossFight = new Fight(player, cenaFight);
cena.addFight(bossFight);
Vector<Item> required = new Vector<>();
required.add(datBoi);
required.add(dogeCoin);
cena.setRequiredItems(required);
// create the map
Map map = new Map(beginning, cena);
map.addVertex(nyanCats);
map.addVertex(forest);
map.addVertex(swordRoom);
map.addVertex(appleStorage);
map.addVertex(dogeRoom);
map.addVertex(sickleRoom);
map.addVertex(datBoiRoom);
map.addVertex(maceRoom);
map.addEdge(beginning, nyanCats);
map.addEdge(beginning, cena);
map.addEdge(nyanCats, forest);
map.addEdge(nyanCats, swordRoom);
map.addEdge(forest, swordRoom);
map.addEdge(forest, datBoiRoom);
map.addEdge(swordRoom, sickleRoom);
map.addEdge(sickleRoom, appleStorage);
map.addEdge(swordRoom, dogeRoom);
map.addEdge(dogeRoom, maceRoom);
return map;
}
/**
* Returns a string representation of the player's current situation, health, and options
* @return a string representation of the player's current situation, health, and options
*/
public String toString() {
LinkedList<Situation> adj = myMap.getAdjacent();
String s = myMap.getCurrentSituation().toString() + "\nAdjacent rooms: ";
for(Situation sit: adj) {
if(adj.indexOf(sit) != adj.size() - 1) {
s += sit.getName() + ", ";
} else {
s += sit.getName();
}
}
s += "\nCurrent Meme Points: " + player.getCurrentHP() + "/" + player.getMaxHP() + "\nInventory: [";
for(int i = 0; i < player.getInventory().length; i++) {
if(i != player.getInventory().length - 1) {
s += player.getInventory()[i] + ", ";
} else {
s += player.getInventory()[i] + "]";
}
}
s += "\nWeapon: " + player.getWeapon();
return s;
}
public static void main(String[] args) {
Game myGame = new Game();
System.out.println(myGame);
myGame.movePlayer(1);
myGame.pickUpItem(new HealItem("A rainbow poptart", "It crosses your mind that this could be nyan cat poop, but as the rainbowy scent wafts "
+ "towards you, you put the thought out of your mind. Heals 5 meme points.", 5));
System.out.println("\n" + myGame);
myGame.movePlayer(2);
System.out.println("\n" + myGame);
Weapon sword = new Weapon("Sword", "A sharp sword. Hit Rate: 95%, 4d6 damage", 0.95, "4d6");
myGame.pickUpItem(sword);
System.out.println("\n" + myGame);
}
}