-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
90 lines (85 loc) · 2.36 KB
/
Player.java
File metadata and controls
90 lines (85 loc) · 2.36 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
import java.util.*;
public class Player {
private String name;
private int chips;
private boolean in;
public static Scanner sc = new Scanner(System.in);
public Player(String name) {
if (name.length() > 0)
this.name = name.substring(0,1).toUpperCase() + name.substring(1);
else
this.name = Names.getName();
chips = 1000;
in = true;
}
public int[] action() { // length 2
return null;
}
public int getChips() {
return chips;
}
public String getName() {
return name;
}
public boolean inHand() {
return in;
}
public void addChips(int chips) {
this.chips += chips;
}
public int removeChips(int chips) {
this.chips -= chips;
return chips;
}
public void setName(String name) {
this.name = name;
}
public void setInHand(boolean in) {
this.in = in;
}
public static int getValidInt(String message, int min, int max) {
Utils.flushInput();
return getValidInt(message, min, max, false);
}
public static int getValidInt(String message, int min, int max, boolean allowBack) { // continuously prompt user for valid int given range and message to keep prompting with
int x;
if (!allowBack) Utils.flushInput();
while (true) {
System.out.println(message + (allowBack ? " [B] to go back" : ""));
try {
String z = sc.nextLine().trim();
if (z.toLowerCase().trim().equals("q")) System.exit(0);
if (allowBack && z.toLowerCase().trim().equals("b")) return -1;
x = Integer.parseInt(z);
if (x >= min && x <= max) break;
else System.out.print("Not within specified bounds! ");
} catch (Exception e) {
System.out.print("Not an integer! ");
continue;
}
}
return x;
}
public static String getValidStr(String message, int min, int max) { // continusoly prompt user for valid string between certain length
int x;
String r;
while (true) {
System.out.println(message);
try {
String z = sc.nextLine().trim();
if (z.toLowerCase().trim().equals("q")) System.exit(0);
x = z.length();
if (x >= min && x <= max) {
r = z;
break;
} else System.out.print("Not within specified length! ");
} catch (Exception e) {
continue;
}
}
return r;
}
public String toString() {
return name + ": ✨" + chips;
}
}