generated from Stuycs-K/APCS-Stuyrim-Template
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathGame.java
242 lines (185 loc) · 7.91 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
import java.util.*;
public class Game{
private static final int WIDTH = 80;
private static final int HEIGHT = 30;
private static final int BORDER_COLOR = Text.BLACK;
private static final int BORDER_BACKGROUND = Text.WHITE + Text.BACKGROUND;
public static void main(String[] args) {
run();
}
//Display the borders of your screen that will not change.
//Do not write over the blank areas where text will appear or parties will appear.
public static void drawBackground(){
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
//YOUR CODE HERE
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
}
//Display a line of text starting at
//(columns and rows start at 1 (not zero) in the terminal)
//use this method in your other text drawing methods to make things simpler.
public static void drawText(String s,int startRow, int startCol){
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
//YOUR CODE HERE
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
}
/*Use this method to place text on the screen at a particular location.
*When the length of the text exceeds width, continue on the next line
*for up to height lines.
*All remaining locations in the text box should be written with spaces to
*clear previously written text.
*@param row the row to start the top left corner of the text box.
*@param col the column to start the top left corner of the text box.
*@param width the number of characters per row
*@param height the number of rows
*/
public static void TextBox(int row, int col, int width, int height, String text){
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
//YOUR CODE HERE
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
}
//return a random adventurer (choose between all available subclasses)
//feel free to overload this method to allow specific names/stats.
public static Adventurer createRandomAdventurer(){
return new CodeWarrior("Bob"+(int)(Math.random()*100));
}
/*Display a List of 2-4 adventurers on the rows row through row+3 (4 rows max)
*Should include Name HP and Special on 3 separate lines.
*Note there is one blank row reserved for your use if you choose.
*Format:
*Bob Amy Jun
*HP: 10 HP: 15 HP:19
*Caffeine: 20 Mana: 10 Snark: 1
* ***THIS ROW INTENTIONALLY LEFT BLANK***
*/
public static void drawParty(ArrayList<Adventurer> party,int startRow){
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
//YOUR CODE HERE
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
}
//Use this to create a colorized number string based on the % compared to the max value.
public static String colorByPercent(int hp, int maxHP){
String output = String.format("%2s", hp+"")+"/"+String.format("%2s", maxHP+"");
//COLORIZE THE OUTPUT IF HIGH/LOW:
// under 25% : red
// under 75% : yellow
// otherwise : white
return output;
}
//Display the party and enemies
//Do not write over the blank areas where text will appear.
//Place the cursor at the place where the user will by typing their input at the end of this method.
public static void drawScreen(){
drawBackground();
//draw player party
//draw enemy party
}
public static String userInput(Scanner in){
//Move cursor to prompt location
//show cursor
String input = in.nextLine();
//clear the text that was written
return input;
}
public static void quit(){
Text.reset();
Text.showCursor();
Text.go(32,1);
}
public static void run(){
//Clear and initialize
Text.hideCursor();
Text.clear();
//Things to attack:
//Make an ArrayList of Adventurers and add 1-3 enemies to it.
//If only 1 enemy is added it should be the boss class.
//start with 1 boss and modify the code to allow 2-3 adventurers later.
ArrayList<Adventurer>enemies = new ArrayList<Adventurer>();
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
//YOUR CODE HERE
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
//Adventurers you control:
//Make an ArrayList of Adventurers and add 2-4 Adventurers to it.
ArrayList<Adventurer> party = new ArrayList<>();
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
//YOUR CODE HERE
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
boolean partyTurn = true;
int whichPlayer = 0;
int whichOpponent = 0;
int turn = 0;
String input = "";//blank to get into the main loop.
Scanner in = new Scanner(System.in);
//Draw the window border
//You can add parameters to draw screen!
drawScreen();//initial state.
//Main loop
//display this prompt at the start of the game.
String preprompt = "Enter command for "+party.get(whichPlayer)+": attack/special/quit";
while(! (input.equalsIgnoreCase("q") || input.equalsIgnoreCase("quit"))){
//Read user input
input = userInput(in);
//example debug statment
TextBox(24,2,1,78,"input: "+input+" partyTurn:"+partyTurn+ " whichPlayer="+whichPlayer+ " whichOpp="+whichOpponent );
//display event based on last turn's input
if(partyTurn){
//Process user input for the last Adventurer:
if(input.equals("attack") || input.equals("a")){
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
//YOUR CODE HERE
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
}
else if(input.equals("special") || input.equals("sp")){
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
//YOUR CODE HERE
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
}
else if(input.startsWith("su ") || input.startsWith("support ")){
//"support 0" or "su 0" or "su 2" etc.
//assume the value that follows su is an integer.
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
//YOUR CODE HERE
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
}
//You should decide when you want to re-ask for user input
//If no errors:
whichPlayer++;
if(whichPlayer < party.size()){
//This is a player turn.
//Decide where to draw the following prompt:
String prompt = "Enter command for "+party.get(whichPlayer)+": attack/special/quit";
}else{
//This is after the player's turn, and allows the user to see the enemy turn
//Decide where to draw the following prompt:
String prompt = "press enter to see monster's turn";
partyTurn = false;
whichOpponent = 0;
}
//done with one party member
}else{
//not the party turn!
//enemy attacks a randomly chosen person with a randomly chosen attack.z`
//Enemy action choices go here!
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
//YOUR CODE HERE
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
//Decide where to draw the following prompt:
String prompt = "press enter to see next turn";
whichOpponent++;
}//end of one enemy.
//modify this if statement.
if(!partyTurn && whichOpponent >= enemies.size()){
//THIS BLOCK IS TO END THE ENEMY TURN
//It only triggers after the last enemy goes.
whichPlayer = 0;
turn++;
partyTurn=true;
//display this prompt before player's turn
String prompt = "Enter command for "+party.get(whichPlayer)+": attack/special/quit";
}
//display the updated screen after input has been processed.
drawScreen();
}//end of main game loop
//After quit reset things:
quit();
}
}