-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBJPlayer.java
More file actions
64 lines (57 loc) · 1.92 KB
/
BJPlayer.java
File metadata and controls
64 lines (57 loc) · 1.92 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
import java.util.*;
public class BJPlayer extends Player {
private ArrayList<Card> hand = new ArrayList<Card>(); // getAction
public BJPlayer(String name) {
super(name);
}
public ArrayList<Card> getHand() {
return hand;
}
public void add(Card c) {
hand.add(c);
}
public void clear() {
hand.clear();
}
public int[] action(int prevBet) { // if hand.size() == 0 prompt for bet
// else ask him for regular action and display his hand
int[] out = new int[2]; // {a, b}
/*
* a: 0 - bet, 1 - hit, 2 - stand, 3 - surrender
* b: bet (if applicable), otherwise js 0
*/
// 0 betting
// 1 dealing
// 2 player's turn // can only hit, stand, or surrender (lose half bet continue
// to next round), no double down so bet is not made into a method
// 3 dealer's turn
// external method to check if win
if (hand.size() == 0) {
out[0] = 0;
if (super.getChips() >= 50) {
out[1] = BJPlayer.getValidInt("Current stack: " + getChips() + "✨\nPlace your bet: (50-" + getChips() + "✨)", 50, getChips());
} else {
out[1] = BJPlayer.getValidInt("Current stack: " + getChips() + "✨\nPlace your bet: (" + getChips() + "-" + getChips() + "✨)", getChips(), getChips());
}
// System.out.println(out[0]);
return out;
} else {
System.out.println("What will you do?");
if (getChips() == 1) {
out[0] = BJPlayer.getValidInt("[1] Hit [2] Stand", 1, 2);
} else {
out[0] = BJPlayer.getValidInt("[1] Hit [2] Stand [3] Surrender(-50% bet)", 1, 3);
}
return out;
}
// System.out.println("Your hand: " + hand[0] + " " + hand[1]);
}
public void dispHand() {
System.out.println(); // start to display cards each person has
System.out.println(getName() + ":");
for (Card card : hand) {
System.out.print(card.getValue() + " ");
}
System.out.println("\n");
}
}