-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainGameScreen.java
More file actions
190 lines (164 loc) · 7.6 KB
/
MainGameScreen.java
File metadata and controls
190 lines (164 loc) · 7.6 KB
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
package MainRepository;
import java.util.Scanner;
public class MainGameScreen extends Screen {
private static final String[] OPTIONS = makeOPTIONS(Poker.numPlayers);
// 카드 숫자를 출력 환경, 조건에 맞게 컨버트
private static String convertNumber(int number, boolean front) {
String result;
if (number == 10 && !front) {
result = "\b10";
} else {
switch (number) {
case 1:
case 14:
result = "A";
break;
case 10:
result = "10";
break;
case 11:
result = "J";
break;
case 12:
result = "Q";
break;
case 13:
result = "K";
break;
default:
result = String.valueOf(number);
break;
}
if (front && number != 10) {
result += " ";
}
}
return result;
}
// 입력한 플레이어 수만큼 옵션 배열 생성해 주는 함수
private static String[] makeOPTIONS(int n){
String[] optionsArr = new String[n];
for(int i = 0; i < n; ++i){
optionsArr[i] = "PLAYER " + (i+1);
}
return optionsArr;
}
// Table 카드 회차 별 출력
public static void printCardFrame(Player selectedPlayerHands, int selectedPlayer, int turn){
// 0 ~ 4 인덱스에는 Table 카드
// 5 ~ 6 인덱스에는 My Hand 카드
// Table 카드 출력은 turn으로 개수 조절, turn은 5회차까지
// My hand 카드는 직접 인덱스 5, 6을 넣어줌
// Table
System.out.printf("\n");
System.out.println(" >> Table <<\n");
System.out.printf(" "); // 앞 공백 중앙 정렬
for (int i = 0; i < turn; i++) {
System.out.printf("'-----------' "); // 카드 윗 부분 출력
}
System.out.println(); // 줄 바꿈
System.out.printf(" "); // 앞 공백 중앙 정렬
for (int i = 0; i < turn; i++) {
System.out.printf("|%s | ", convertNumber(selectedPlayerHands.hands.get(i).number, true));// 카드 숫자 출력
}
System.out.println(); // 줄 바꿈
for(int j = 0; j <3; j++){
System.out.printf(" "); // 앞 공백 중앙 정렬
for (int i = 0; i < turn; i++) {
System.out.printf("| | ");
}
System.out.println(); // 줄 바꿈
}
System.out.printf(" "); // 앞 공백 중앙 정렬
for (int i = 0; i < turn; i++) {
System.out.printf("| %s | ", selectedPlayerHands.hands.get(i).suit);// 카드 문양 출력
}
System.out.println(); // 줄 바꿈
for(int j = 0; j <3; j++){
System.out.printf(" "); // 앞 공백 중앙 정렬
for (int i = 0; i < turn; i++) {
System.out.printf("| | ");
}
System.out.println(); // 줄 바꿈
}
System.out.printf(" "); // 앞 공백 중앙 정렬
for (int i = 0; i < turn; i++) {
System.out.printf("| %s| ", convertNumber(selectedPlayerHands.hands.get(i).number, false));// 카드 숫자 출력
}
System.out.println(); // 줄 바꿈
System.out.printf(" "); // 앞 공백 중앙 정렬
for (int i = 0; i < turn; i++) {
System.out.printf("'-----------' "); // 카드 아래 부분 출력
}
System.out.println(); // 줄 바꿈
// My Hand
System.out.printf("\n\n");
System.out.println(" >> PLAYER " + (selectedPlayer+1) + " <<\n");
System.out.printf(" '-----------' '-----------'\n");
System.out.printf(" |%s | |%s |\n", convertNumber(selectedPlayerHands.hands.get(5).number, true), convertNumber(selectedPlayerHands.hands.get(6).number, true));
System.out.printf(" | | | |\n");
System.out.printf(" | | | |\n");
System.out.printf(" | | | |\n");
System.out.printf(" | %s | | %s |\n", selectedPlayerHands.hands.get(5).suit, selectedPlayerHands.hands.get(6).suit);
System.out.printf(" | | | |\n");
System.out.printf(" | | | |\n");
System.out.printf(" | | | |\n");
System.out.printf(" | %s| | %s|\n",convertNumber(selectedPlayerHands.hands.get(5).number, false), convertNumber(selectedPlayerHands.hands.get(6).number, false));
System.out.printf(" '-----------' '-----------'\n\n");
}
public static void printMenu() {
for (int i = 0; i < OPTIONS.length; i++) {
if (i == selectedIndex) {
System.out.print(" -> ");
} else {
System.out.print(" ");
}
System.out.println(OPTIONS[i]);
}
System.out.println("\n W: Move Up, S: Move Down, N: Next Turn, E: Select");
System.out.print(" Select option >> ");
}
private static void moveSelectionUp() {
selectedIndex = (selectedIndex - 1 + OPTIONS.length) % OPTIONS.length;
}
private static void moveSelectionDown() {
selectedIndex = (selectedIndex + 1) % OPTIONS.length;
}
public static void printScreen(Player[] players){
int turn = 3;
int selectedPlayer = 0;
Player selectedPlayerHands = players[0];
Scanner scanner = new Scanner(System.in);
while (true) {
clearConsole();
printCardFrame(selectedPlayerHands, selectedPlayer, turn);
printMenu(); // 메뉴 출력
if (scanner.hasNext()) {
char input = scanner.next().charAt(0);
if (input == 'W' || input == 'w') {
moveSelectionUp();
clearConsole();
}
else if (input == 'S' || input == 's') {
moveSelectionDown();
clearConsole();
}
else if (input == 'N' || input == 'n') {
++turn;
if(turn == 6) {
clearConsole();
break;
}
}
else if (input == 'E' ||input == 'e') {
for(int i = 0; i < Poker.numPlayers; ++i){
if (selectedIndex == i) {
selectedPlayer = i;
selectedPlayerHands = players[selectedPlayer];
}
}
}
}
}
}
}