-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.java
More file actions
56 lines (47 loc) · 1.2 KB
/
Utils.java
File metadata and controls
56 lines (47 loc) · 1.2 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
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Utils {
private static Scanner scanner;
private static ArrayList<String> quits;
public Utils() {
scanner = new Scanner(System.in);
String[] _quits = { "exit", "end", "quit", "q" };
quits = new ArrayList<String>(Arrays.asList(_quits));
}
public void quit(String inp) {
if (quits.contains(inp.toLowerCase())) {
System.out.println(Colors.R + "Quit game" + Colors.RE);
scanner.close();
System.exit(0);
}
}
public String ln() {
System.out.print(Colors.C + ">>> " + Colors.RE);
return scan();
}
public String scan() {
String scan = scanner.nextLine().strip();
quit(scan);
return scan;
}
public int num() {
System.out.print(Colors.C + ">>> " + Colors.RE);
while (true) {
try {
return Integer.parseInt(scan());
} catch (Exception e) {
System.out.println(Colors.R + "Please enter a valid integer." + Colors.RE);
}
}
}
public void error(String text) {
System.out.println(Colors.R + text + Colors.RE);
}
public void quest(String text) {
System.out.println(Colors.B + text + Colors.RE);
}
public String opt(String text) {
return Colors.P + text + Colors.RE;
}
}