Repository navigation
Expand file tree
/
Copy pathrealPlayer.java
More file actions
59 lines (55 loc) · 1.94 KB
/
Copy pathrealPlayer.java
File metadata and controls
59 lines (55 loc) · 1.94 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
import java.io.*;
import java.util.ArrayList;
public class realPlayer extends player{
int balance;
int wager;
void makeWager(int input){
wager = input;
}
boolean doubleDown(ArrayList deck){
hit(hand, deck);
wager*=2;
return stand;
}
boolean surrender(){
wager=0;
return stand;
}
public void saveBalance() throws IOException {
try (BufferedWriter writer = new BufferedWriter(new FileWriter("output.txt", true))){
writer.write(String.valueOf(balance));
writer.newLine();
writer.flush();
} catch (IOException e) {
e.printStackTrace(); // Handle the exception appropriately
}
}
public void createBalance(){
try(BufferedReader localReader = new BufferedReader(new FileReader("output.txt"))) {
String balanceString = localReader.readLine();
if (balanceString == null) {
// Set an initial balance of 1000 chips for new players
balance = 1000;
}else{
try {
balance = Integer.parseInt(balanceString);
} catch (NumberFormatException ex) {
System.err.println("Invalid input for balance. Setting balance to 1000");
balance = 1000;
}
}
} catch (IOException | NumberFormatException e) {
e.printStackTrace(); // Handle the exception appropriately
}
}
public void loadBalance() {
try (BufferedReader localReader = new BufferedReader(new FileReader("output.txt"))) {
String balanceString = localReader.readLine();
if (balanceString != null) {
balance = Integer.parseInt(balanceString);
}
} catch (IOException | NumberFormatException e) {
e.printStackTrace(); // Handle the exception appropriately
}
}
}