-
Notifications
You must be signed in to change notification settings - Fork 1
/
Printer.java
330 lines (253 loc) · 10.3 KB
/
Printer.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
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
327
328
329
330
import java.util.Scanner;
/**
* This class do all required prints
* This class designed for UNIX bash
* ( may not work on windows )
*
*
* @author Mohammad Mahdi Malmasi
* @version 0.1.0
*/
public class Printer
{
/* Feilds */
// Reset the color of the terminal
private static final String RESET = "\033[92;40m";
// indent
private static final String indent = "\t\t\t ";
// Regular Colors
public static final String BLACK = "\033[0;30m"; // BLACK
public static final String RED = "\033[0;31m"; // RED
public static final String GREEN = "\033[0;32m"; // GREEN
public static final String YELLOW = "\033[0;33m"; // YELLOW
public static final String BLUE = "\033[0;34m"; // BLUE
public static final String PURPLE = "\033[0;35m"; // PURPLE
public static final String CYAN = "\033[0;36m"; // CYAN
public static final String WHITE = "\033[0;37m"; // WHITE
// Background
public static final String BLACK_BACKGROUND = "\033[40m"; // BLACK
public static final String RED_BACKGROUND = "\033[41m"; // RED
public static final String GREEN_BACKGROUND = "\033[42m"; // GREEN
public static final String YELLOW_BACKGROUND = "\033[43m"; // YELLOW
public static final String BLUE_BACKGROUND = "\033[44m"; // BLUE
public static final String PURPLE_BACKGROUND = "\033[45m"; // PURPLE
public static final String CYAN_BACKGROUND = "\033[46m"; // CYAN
public static final String WHITE_BACKGROUND = "\033[47m"; // WHITE
// High Intensity
public static final String BLACK_BRIGHT = "\033[0;90m"; // BLACK
public static final String RED_BRIGHT = "\033[0;91m"; // RED
public static final String GREEN_BRIGHT = "\033[0;92m"; // GREEN
public static final String YELLOW_BRIGHT = "\033[0;93m"; // YELLOW
public static final String BLUE_BRIGHT = "\033[0;94m"; // BLUE
public static final String PURPLE_BRIGHT = "\033[0;95m"; // PURPLE
public static final String CYAN_BRIGHT = "\033[0;96m"; // CYAN
public static final String WHITE_BRIGHT = "\033[0;97m"; // WHITE
// High Intensity backgrounds
public static final String BLACK_BACKGROUND_BRIGHT = "\033[0;100m";// BLACK
public static final String RED_BACKGROUND_BRIGHT = "\033[0;101m";// RED
public static final String GREEN_BACKGROUND_BRIGHT = "\033[0;102m";// GREEN
public static final String YELLOW_BACKGROUND_BRIGHT = "\033[0;103m";// YELLOW
public static final String BLUE_BACKGROUND_BRIGHT = "\033[0;104m";// BLUE
public static final String PURPLE_BACKGROUND_BRIGHT = "\033[0;105m"; // PURPLE
public static final String CYAN_BACKGROUND_BRIGHT = "\033[0;106m"; // CYAN
public static final String WHITE_BACKGROUND_BRIGHT = "\033[0;107m"; // WHITE
/* Methods */
/**
* This method print the game menu
*/
public static void printMenu()
{
clear();
System.out.println(RESET);
System.out.print("\n\n\n\n\n\n\n\n\n\n\n\n");
System.out.println(indent + "\t " + "🃏 <@••••••. Pentago Game .••••••@> 🀄️");
System.out.print("\n\n");
System.out.println(indent + "\t " + " 1. new Two Player game");
System.out.println(indent + "\t " + " 2. new Single Player game");
System.out.print("\n");
System.out.println(indent + "\t " + " 3. exit");
System.err.println(indent + "\t " + "🀄️ <@••••••••••••••••••••••••••••@> 🃏");
System.out.print("\n\n");
System.out.print( indent + "\t " + " 0_0? ");
}
/**
* This method ask the player name
*
* @param playerID : the player number
*/
public static void getPlayerName(int playerID)
{
clear();
System.out.print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
System.out.print(indent + "\t " +
"Please type the name of the player" + playerID +": ");
}
/**
* This method print the visual board in standard output(termianl)
* Run this code in an Unix-base OS to see it colorfull =)
*
* @param visualBoard : the visual board of the game
* @param y_len : the width of the visual board
* @param x_len : the lenght of the visual board
*/
public static void printVisualBoard(Board gameBoard)
{
clear();
char[][] visualBoard = gameBoard.getVisualBoard();
int y_len = gameBoard.getVisualBoardY();
int x_len = gameBoard.getVisualBoardX();
System.out.print(indent + RESET);
System.out.print(" ");
for (char k = 'A'; k <= 'F'; k++)
{
System.out.print(CYAN_BRIGHT + k + " ");
if (k == 'C')
System.out.print(" ");
}
System.out.print("\n");
for (int j = 0; j < y_len; j++)
{
System.out.print(indent);
if (j < 13)
{
if (j%4 == 2)
System.out.print(CYAN_BRIGHT + (j/4 + 1) + " " + RESET);
else
System.err.print(" ");
}
else if (j > 14)
{
if ((j-2)%4 == 2)
System.out.print(CYAN_BRIGHT + ((j-2)/4 + 1) + " " + RESET);
else
System.err.print(" ");
}
else
System.err.print(" ");
for (int i = 0; i < x_len; i++)
{
if (visualBoard[j][i] == '•' || visualBoard[j][i] == '-' || visualBoard[j][i] == '|')
System.out.print(YELLOW_BRIGHT + RED_BACKGROUND + visualBoard[j][i]);
else if (visualBoard[j][i] > '0' && visualBoard[j][i] < '5')
System.err.print(GREEN_BRIGHT + BLUE_BACKGROUND + visualBoard[j][i]);
else if (visualBoard[j][i] == 'B')
System.out.print(BLACK_BACKGROUND + " ");
else if (visualBoard[j][i] == 'W')
System.err.print(WHITE_BACKGROUND_BRIGHT + " ");
else
System.out.print(RED_BACKGROUND + visualBoard[j][i]);
System.out.print(RESET);
}
System.out.print("\n");
}
}
/**
* This method print the player name and some other words to get player choosen block
*
* @param player : the player that should choose a block
*/
public static void printTurn1(Player player)
{
System.out.print(RESET +
"Hey " + BLACK_BACKGROUND_BRIGHT + player.getFirstName() + RESET +
" it's your turn. choose a block from empty blocks(example: '3D'): ");
}
/**
* This method print the player name and some other words to get player choosen square to rotate
*
* @param player : the player that should choose a square to rotate
*/
public static void printTurn2(Player player)
{
System.out.print(RESET +
"Hey " + BLACK_BACKGROUND_BRIGHT + player.getFirstName() + RESET +
" it's your turn. choose a square to rotate\n(example: '1t', '2f'. t: clockwise, f: counterClockwise): ");
}
/**
* This method says congratulations to winner player =)
*
* @param winnePlayer : the winner player
* @param finish : the input source
*/
public static void printWinner(Player winnePlayer, Scanner finish)
{
System.out.println(indent + "\t " +
"Congratulations " +
BLACK_BACKGROUND_BRIGHT + winnePlayer.getFirstName() + RESET +
". you win !");
finishEnter(finish);
}
/**
* Call this method when game drawed
*
* @param finish : the input source
*/
public static void printDraw(Scanner finish)
{
System.out.println(indent + "\t " +
"Congratulations " +
BLACK_BACKGROUND_BRIGHT + "both of you" + RESET +
" are win !");
finishEnter(finish);
}
/**
* This mehtod calibrate the font size of the terminal
*
* @param finish : the players input source
*/
public static void calibrate(Scanner finish)
{
clear();
System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
System.out.println(RESET + indent + "\b\b\b\b\b\b\b" +
"please use (cntrl, +) and (cntrl, -) to fit this line to your screen");
System.out.println("<~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>");
finishEnter(finish);
}
/**
* This method reset the color of the terminal
* Both text color and background color
*
* ()
*/
public static void colorReset()
{
System.out.println(RESET);
}
/**
* This method warn the player that his/her choosen block is in valid
*
* @param finish : the player input source
*/
public static void wrongChooseError(Scanner finish)
{
System.out.println(indent + "\t " +
YELLOW_BACKGROUND_BRIGHT + RED_BRIGHT +
"<@ ! YOU CAN NOT CHOOSE THAT BLOCK ! @>" + RESET);
finishEnter(finish);
}
/**
* This method warn the player that his/her input is in valid
*
* @param finish : the player input source
*/
public static void inValidInputError(Scanner finish)
{
System.out.println(indent + "\t " +
YELLOW_BACKGROUND_BRIGHT + RED_BRIGHT +
"<@ ! YOUR INPUT IS INVALID ! @>" + RESET);
finishEnter(finish);
}
// this method wait until player push 'enter' bottom
private static void finishEnter(Scanner inputsSource)
{
System.out.println(indent + "\t\t " + "(press enter to continue)");
inputsSource.nextLine();
}
// this method clear the terminal
private static void clear()
{
System.out.print("\033[H\033[2J");
System.out.flush();
}
}