-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hand.java
170 lines (144 loc) · 4.74 KB
/
Hand.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package blackjack_verkort_tentamen_rob_biemans;
import java.util.ArrayList;
import java.util.Scanner;
public class Hand {
// Declarations
private ArrayList<ArrayList<Card>> hands; // array with amount of hands (with cards)
private ArrayList<ArrayList<String>> handsInfo = new ArrayList<ArrayList<String>>(); // array with bet size and status of the particular hand
private String status = " "; // dubbel, gepast, dood, blackjack
private Cards c;
private Participant p;
public Hand(Participant p) {
this.p = p;
c = new Cards();
}
public void CreatePlayerHandwithCards (int value) {
hands = new ArrayList<ArrayList<Card>>();
handsInfo.clear();
String st = " ";
for (int i = 0; i < value; i++) {
ArrayList<Card> deck = new ArrayList<Card>();
ArrayList<String> values = new ArrayList<String>();
for (int a = 0; a < 2; a++) {
deck.add(c.getCard());
}
if (deck.get(0).getValue().toString() == "AAS" || deck.get(1).getValue().toString() == "AAS") {
if (deck.get(0).getValue().toString() == "TIEN" || deck.get(1).getValue().toString() == "TIEN") {
st = "Blackjack";
}
else if (deck.get(0).getValue().toString() == "BOER" || deck.get(1).getValue().toString() == "BOER") {
st = "Blackjack";
}
else if (deck.get(0).getValue().toString() == "VROUW" || deck.get(1).getValue().toString() == "VROUW") {
st = "Blackjack";
}
else if (deck.get(0).getValue().toString() == "KONING" || deck.get(1).getValue().toString() == "KONING") {
st = "Blackjack";
}
}
String number = Integer.toString(((Player)p).getBet());
values.add(st);
st = " ";
values.add(number);
handsInfo.add(values);
hands.add(deck);
}
((Player)p).setHandenInfo(handsInfo);
p.setHanden(hands);
}
public void givePlayerCard(int value) {
hands = new ArrayList<ArrayList<Card>>();
ArrayList<Card> deck = new ArrayList<Card>();
deck.add(c.getCard());
p.addCardToHand(value,deck);
printPlayerHandSituation(value);
}
public void printPlayerHandSituation(int value) {
System.out.print("Nieuwe situatie: ");
for (int a = 0; a < ((Player)p).getHanden().get(value).size(); a++) {
System.out.print(" "+((Player)p).getHanden().get(value).get(a).getType().getValue()+((Player)p).getHanden().get(value).get(a).getValue().getValue());
}
System.out.println();
}
/* DEALER CODE BELOW */
/*********************/
public void CreateDealerHandwithCards() {
hands = new ArrayList<ArrayList<Card>>();
ArrayList<Card> deck = new ArrayList<Card>();
ArrayList<String> values = new ArrayList<String>();
deck.add(c.getCard());
values.add("none");
handsInfo.add(values);
hands.add(deck);
((Dealer)p).setHandenInfo(handsInfo);
((Dealer)p).setHanden(hands);
}
public void printDealerHandSituation() {
int points = 0;
System.out.print("Deler: ");
for (int a = 0; a < ((Dealer)p).getHanden().get(0).size(); a++) {
System.out.print(" "+((Dealer)p).getHanden().get(0).get(a).getType().getValue()+((Dealer)p).getHanden().get(0).get(a).getValue().getValue());
}
for (int a = 0; a < ((Dealer)p).getHanden().get(0).size(); a++) {
switch (((Dealer)p).getHanden().get(0).get(a).getValue().getValue()){
case "B":
points += 10;
break;
case "V":
points += 10;
break;
case "K":
points += 10;
break;
case "A":
if (points <= 10) {
points += 11;
} else {
points += 1;
}
break;
default:
points += Integer.parseInt(((Dealer)p).getHanden().get(0).get(a).getValue().getValue());
break;
}
}
if (((Dealer)p).getHanden().get(0).size() == 2) {
if (points == 21) {
System.out.print("\tBlackjack");
}
}
System.out.println();
if (points >= 17) {
if (points > 21) {
System.out.println("De deler is dood");
((Dealer)p).updateHandDeath();
} else {
System.out.println("Deler heeft gepast en is geëindigd met "+points+" punten");
}
((Dealer)p).setPoints(points);
((Dealer)p).setFinished(true);
} else if (points < 17) {
System.out.print("Druk op ENTER om de deler te laten spelen...");
try {
Scanner sc = new Scanner(System.in);
sc.nextLine();
giveDealerCard();
} catch (Exception e) {
System.out.println("ERROR 7: " + e);
}
}
}
public void giveDealerCard() {
hands = new ArrayList<ArrayList<Card>>();
ArrayList<Card> deck = new ArrayList<Card>();
deck.add(c.getCard());
p.addCardToDealerHand(deck);
printDealerHandSituation();
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}