-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserIO.java
146 lines (135 loc) · 4.6 KB
/
UserIO.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
import java.util.Scanner;
public class UserIO {
Scanner in;
BaoGame g;
public UserIO(BaoGame game) {
in = new Scanner(System.in);
g = game;
}
public UserIO() {
in = new Scanner(System.in);
}
public boolean getBoolean(String q) {
String ans = "";
while(true) {
System.out.print(q + "(y/n): ");
ans = in.next();
if(ans.equalsIgnoreCase("y")) {
return true;
} else if(ans.equalsIgnoreCase("n")) {
return false;
}
}
}
public Loc getLoc(String q) {
System.out.println(q);
int r = -1;
int c = -1;
while(!(r > -1 && r < 4) || !(c > -1 && c < 8)) {
System.out.print("Row: ");
r = in.nextInt() - 1;
System.out.print("Column: ");
c = in.nextInt() - 1;
}
return new Loc(r, c);
}
public Loc getCapLoc(String q, int p, BaoGame g) {
System.out.println(q);
Loc ans = new Loc(0, 0);
while(ans.whosePit() != p || !g.pitCanCapture(ans)) {
System.out.print("Row: ");
int r = in.nextInt() - 1;
System.out.print("Column: ");
int c = in.nextInt() - 1;
ans = new Loc(r, c);
}
return ans;
}
public int getDir(String q) {
System.out.println(q);
String ans = "";
while(!ans.equalsIgnoreCase("cw") && !ans.equalsIgnoreCase("ccw")) {
System.out.print("CW or CCW?");
ans = in.next();
}
if(ans.equalsIgnoreCase("cw")) {
return 1;
} else {
return -1;
}
}
private void printHB(int r) {
System.out.print("+");
for(int i = 0; i < 8; i++) {
if(((r == 1 || r == 2) && i == 3) ||
((r == 2 || r == 3) && i == 4)) {
System.out.print("xxxx");
} else {
System.out.print("----");
}
System.out.print("+");
}
System.out.print("\n");
}
public void printBoard(Pit[][] b) {
printHB(0);
for(int r = 0; r < b.length; r++) {
System.out.print("| ");
for(int c = 0; c < b[0].length; c++) {
System.out.printf("%2d", b[r][c].getSeeds());
if((r == 1 && (c == 2 || c == 3)) ||
(r == 2 && (c == 3 || c == 4))) {
System.out.print(" x ");
} else {
System.out.print(" | ");
}
}
System.out.print("\n");
printHB(r + 1);
}
printSeeds();
}
public void printSeeds() {
System.out.println("Player 1 seeds: " + g.getPlayerSeeds(0));
System.out.println("Player 2 seeds: " + g.getPlayerSeeds(1));
}
public int printTitle() {
System.out.println("****************SWAHILIAN***************");
System.out.println(" ___ ___ ___ ");
System.out.println(" /\\ \\ /\\ \\ /\\ \\ ");
System.out.println(" /::\\ \\ /::\\ \\ /::\\ \\ ");
System.out.println(
" /:/\\:\\ \\ /:/\\:\\ \\ /:/\\:\\ \\ ");
System.out.println(
" /::\\~\\:\\__\\ /::\\~\\:\\ \\ /:/ \\:\\ \\ ");
System.out.println(
"/:/\\:\\ \\:|__| /:/\\:\\ \\:\\__\\ /:/__/ \\:\\__\\");
System.out.println(
"\\:\\~\\:\\/:/ / \\/__\\:\\/:/ / \\:\\ \\ /:/ /");
System.out.println(" \\:\\ \\::/ / \\::/ / \\:\\ /:/ / ");
System.out.println(" \\:\\/:/ / /:/ / \\:\\/:/ / ");
System.out.println(" \\::/__/ /:/ / \\::/ / ");
System.out.println(" ~~ \\/__/ \\/__/ ");
System.out.println("Select game mode:");
System.out.println("1. Play against Player");
System.out.println("2. Play against Ashkon");
int mode = -1;
while(mode != 1 && mode != 2) {
System.out.print("Mode: ");
mode = in.nextInt();
}
if(mode == 1) {
return 1;
} else {
System.out.println("Select Ashkon's level:");
System.out.println("1. Terrible");
System.out.println("2. Slightly less terrible");
mode = -1;
while(mode != 1 && mode != 2) {
System.out.print("Difficulty: ");
mode = in.nextInt();
}
return mode + 1;
}
}
}