forked from MmahdiM79/Othello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrinter.java
268 lines (204 loc) · 7.78 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
import java.util.Scanner;
/**
* This class do all required prints
* This class only work on UNIX bash
*
* @author Mohammad Mahdi Malmsi
* @version 0.1.5
*/
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\t ";
// Text colors
private static final String BLACK_BRIGHT = "\033[90m";
private static final String RED_BRIGHT = "\033[91m";
private static final String GREEN_BRIGHT = "\033[92m";
private static final String YELLOW_BRIGHT = "\033[93m";
private static final String BLUE_BRIGHT = "\033[94m";
private static final String PURPLE_BRIGHT = "\033[95m";
private static final String CYAN_BRIGHT = "\033[96m";
private static final String WHITE_BRIGHT = "\033[97m";
// High Intensity backgrounds
private static final String BLACK_BACKGROUND_BRIGHT = "\033[100m";
private static final String RED_BACKGROUND_BRIGHT = "\033[101m";
private static final String GREEN_BACKGROUND_BRIGHT = "\033[102m";
private static final String YELLOW_BACKGROUND_BRIGHT = "\033[103m";
private static final String BLUE_BACKGROUND_BRIGHT = "\033[104m";
private static final String PURPLE_BACKGROUND_BRIGHT = "\033[105m";
private static final String CYAN_BACKGROUND_BRIGHT = "\033[106m";
private static final String WHITE_BACKGROUND_BRIGHT = "\033[107m";
/* Methods */
/**
* 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(char[][] visualBoard, int y_len, int x_len)
{
clear();
System.out.print(indent + RESET);
System.out.print(" ");
for (char k = 'A'; k <= 'H'; k++)
System.out.print(YELLOW_BRIGHT + k + " ");
System.out.print("\n");
for (int j = 0; j < y_len; j++)
{
System.out.print(indent);
if (j%4 == 2)
System.out.print(YELLOW_BRIGHT + (j/4 + 1) + " " + RESET);
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(GREEN_BRIGHT + visualBoard[j][i]);
else if (visualBoard[j][i] == 'X')
System.out.print(RED_BACKGROUND_BRIGHT + " ");
else if (visualBoard[j][i] == 'O')
System.out.print(CYAN_BACKGROUND_BRIGHT + " ");
else if (visualBoard[j][i] == 'W')
System.err.print(WHITE_BACKGROUND_BRIGHT + " ");
else
System.out.print(visualBoard[j][i]);
System.out.print(RESET);
}
System.out.print("\n");
}
}
/**
* 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 tells to player that he/she can't choose any block
*
* @param finish : the player input source
*/
public static void passedPlayer(Scanner finish)
{
System.out.println(indent + "\t " +
"You Can Not Choose Any Block :( (pass)" + RESET);
finishEnter(finish);
}
/**
* 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 printTurn(Player player)
{
System.out.print(RESET +
" Hey " + BLACK_BACKGROUND_BRIGHT + player.getFirstName() + RESET +
" it's your turn. choose a block from white blocks(example: '3D'. no space between integer and character): ");
}
/**
* This mehtod print the players scores
*
* @param player1 : player one
* @param player2 : player two
*/
public static void printPlayersScores(Player player1, Player player2)
{
System.out.println(indent + WHITE_BRIGHT + "\t " +
player1.getFirstName() + ": " + player1.getScore() +
", " +
player2.getFirstName() + ": " + player2.getScore() + RESET);
}
/**
* 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\t " + "🔵 <@~~~ Othello Game ~~~@> 🔴");
System.out.print("\n\n");
System.out.println(indent + "\t\t " + " 1. new Two Player game");
System.out.println(indent + "\t\t " + " 2. new Single Player game");
System.out.print("\n");
System.out.println(indent + "\t\t " + " 3. exit");
System.err.println(indent + "\t\t " + "🔴 <@~~~~~~~~~~~~~~~~~~~~~@> 🔵");
System.out.print("\n\n");
System.out.print( indent + "\t\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 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);
}
/**
* 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 +
"please use (cntrl, +) and (cntrl, -) to fit this line to your screen");
System.out.println("<~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>");
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();
}
}