/
EntireProject
326 lines (252 loc) · 8.05 KB
/
EntireProject
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/**
* Player Project
* Period 2
* @author Riley Hogue, Alyx Hartman, and Gabe Santana
*/
import java.util.ArrayList;
import java.util.Scanner;
public class PlayerProject
{
public static void main(String[] args)
{
Player cloud = new Player(1, 1, 3); // player to place into the world (direction, health, x)
Boss dragon = new Boss(1, 79000, 5);
World world = new World(); // the World object that contains Player objects
world.placePlayer(cloud);
Scanner keyboard = new Scanner(System.in); // keyboard to get human's input
String command = ""; // user's input
while (!(command.equals("exit") || command.equals("e")))
{
clearScreen();
world.display();
System.out.print("Type attack, magic or guard: ");
command = keyboard.nextLine();
if (command.equals("attack") || command.equals("a"))
{
cloud.attack(); //make attack class
}
else if (command.equals("magic") || command.equals("m"))
{
System.out.println("Type cure(heal), fire(fire damage), blizzard(ice damage), holy(light damage), or thunder(lightning damage)");
if (command.equals("cure") || command.equals("c") || command.equals("heal"))
{
cloud.cure(); //make cure class
}
else if (command.equals("fire") || command.equals("f"))
{
cloud.fire(); //make fire class
}
else if (command.equals("blizzard") || command.equals("b") || command.equals("ice"))
{
cloud.blizzard(); //make blizzard class
}
else if (command.equals("holy") || command.equals("h") || command.equals("light"))
{
cloud.holy(); //make holy class
}
else if (command.equals("thunder") || command.equals("t") || command.equals("lightning"))
{
cloud.thunder(); //make thunder class
}
}
else if (command.equals("guard") || command.equals("g"))
{
cloud.guard(); //make guard class
}
}
}// end of main method
// postcondition: console screen is cleared
public final static void clearScreen()
{
for (int i = 0; i < 25; i++)
{
System.out.println();
}
}// end of clearScreen method
}// end of Main (client) class
///////// regular classes //////////////
class Player
{
// instance variables (properties) *******************
private int myDirection; // -1 west, 1 east
private int myX; // location on x-axis
private int myHealth; // Health of player
private int myAttack; //Attack of player
private int myMana; //Mana of player
// default constructor *******************************
public Player()
{
myDirection = 1;
myX = 0;
myHealth = 9000;
myAttack = 2000;
myMana = 50;
}
// other constructor *********************************
public Player(int direction, int x, int health, int mana, int attack)
{
myDirection = direction;
myX = x;
myHealth = health;
myMana = mana;
myAttack = attack;
}
// accessor methods (getters) ***********************
public int getDirection()
{
return myDirection;
}
public int getX()
{
return myX;
}
public int getHealth()
{
return myHealth;
}
public int getMana()
{
return myMana();
}
public int getAttack()
{
return myAttack;
}
// modifier methods (setters or mutators) *************
public void setDirection(int direction)
{
myDirection = direction;
}
public void setX(int x)
{
myX = x;
}
public void setHealth(int health)
{
myHealth = health;
}
public void setMana(int mana)
{
myMana = mana;
}
public void setAttack(int attack)
{
myAttack = attack;
}
// interesting methods *****************************
}// end of Player class
//////////////////////////////////////////////////////
class Boss
{
// instance variables (properties) *******************
private int myDirection; // -1 west, 1 east
private int myX; // location on x-axis
private int myHealth; // Health points of Boss
// default constructor *******************************
public Boss()
{
myDirection = -1;
myX = 5;
myHealth = 79000;
myAttack = 500;
}
// other constructor *********************************
public Boss(int direction, int x, int health, int attack)
{
myDirection = direction;
myX = x;
myHealth = health;
myAttack = attack;
}
// accessor methods (getters) ***********************
public int getDirection()
{
return myDirection;
}
public int getX()
{
return myX;
}
public int getHealth()
{
return myHealth;
}
public int getAttack()
{
return myAttack;
}
// modifier methods (setters or mutators) *************
public void setDirection(int direction)
{
myDirection = direction;
}
public void setX(int x)
{
myX = x;
}
public void setHealth(int health)
{
myHealth = helath;
}
public void setHealth(int health)
{
myHealth = health;
}
public void setAttack(int attack)
{
myAttack = attack;
}
// interesting methods *****************************
}// end of Boss class
//////////////////////////////////////////////////////
class World
{
// instance variables (properties) *******************
private ArrayList<Player> players; // list of all Player objects in the World object
// default constructor *******************************
public World()
{
players = new ArrayList(); // instantiating an empty list of players
}
// interesting methods *****************************
// postcondition: a new player is placed in the world
public void placePlayer(Player cloud)
{
players.add(player);
}
public void placeBoss(Boss dragon)
{
boss.add(dragon);
}
// display all the players in the world
public void display()
{
final int SIZE = 21; // length of the world
String[] strip = new String[SIZE]; // number line
for (Player nextPlayer : players) // looping thru the list of players
{
if (nextPlayer.getDirection() == 1) // if current player points east
{
strip[nextPlayer.getX() + SIZE / 2] = ">"; // place correct marker into strip at proper place
} // adding half the SIZE due to the negative portion of x axis
else if (nextPlayer.getDirection() == -1)
{
strip[nextPlayer.getX() + SIZE / 2] = "<";
}
}
// display the world
System.out.print("\n|");
for (int i = 0; i < strip.length; i++)
{
if (strip[i] == null)
{
System.out.print("-"); // display hyphen if no player
}
else
{
System.out.print(strip[i]); // display player as a direction marker
}
}
System.out.println("|");
}// end of display method
}// end of World class