-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSabaccHand.java
More file actions
58 lines (54 loc) · 1.11 KB
/
SabaccHand.java
File metadata and controls
58 lines (54 loc) · 1.11 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
import java.util.ArrayList;
import java.util.Random;
public class SabaccHand
{
int i_d;
int credit;
boolean out;
ArrayList <Card> hand_list;
Card[] myHand = new Card[52];
int value = 0;
int hand_index = 0;
public SabaccHand (int playnum)
{
i_d = playnum;
credit = 1000;
out = false;
hand_list = new ArrayList(52);
}
void hit(Card c)
{
myHand[hand_index] = new Card(c);
hand_list.add(myHand[hand_index++]);
}
int getValue()
{
value = 0;
if (hand_list.size() > 0) {
for (int i = 0; i < hand_list.size(); i++) value += hand_list.get(i).card_val;
}
return value;
}
void shift(Card c)
{
int q;
Random r = new Random();
q = r.nextInt(hand_list.size());
myHand[hand_index] = new Card(c);
hand_list.remove(q);
hand_list.add(myHand[hand_index++]);
}
void bet (int b) { credit -= b; }
void winHand (int prize) { credit += prize; }
void printHand ()
{
System.out.print(this.getValue() + " <");
for (int i = 0; i < hand_list.size()-1; i++)
{
hand_list.get(i).print();
System.out.print(", ");
}
hand_list.get(hand_list.size()-1).print();
System.out.print(">\n\n");
}
}