-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSabaccApp.java
More file actions
166 lines (160 loc) · 4.34 KB
/
SabaccApp.java
File metadata and controls
166 lines (160 loc) · 4.34 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
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
/**
* Adam Novitch
* Sabacc Game App
* v0.1 6/1/2012
*/
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Random;
import java.lang.Math;
public class SabaccApp
{
public static void main (String[] args)
{
//------------------------------------------------------
// Sets up # of players and each player's first card
//------------------------------------------------------
int players = Integer.parseInt(args[0]);
Deck myDeck = new Deck();
myDeck.shuffle_deck();
Scanner sc = new Scanner(System.in);
SabaccHand[] roster = new SabaccHand[players];
int turn = 1;
int opt;
Random rn = new Random();
Card drawphase;
boolean call = false;
int outCounter = 0;
SabaccHand winner;
//------------------------------------------------------
// Total Player roster, game, and hand arrays
//------------------------------------------------------
for (int i = 0; i < players; i++)
{
roster[i] = new SabaccHand(i+1);
}
int pot = 0;
ArrayList <SabaccHand> game = new ArrayList(players);
ArrayList <SabaccHand> hand = new ArrayList(players);
for (int i = 0; i < players; i++) game.add(roster[i]);
//------------------------------------------------------
// Outer loop for filling the hand array with
// players still in the game and the ante.
//------------------------------------------------------
while (true)
{
for (int i = 0; i < game.size(); i++) hand.add(game.get(i));
for (int i = 0; i < hand.size(); i++)
{
hand.get(i).bet(10);
pot += 10;
}
myDeck.drawCard();
for (int i = 0; i < game.size(); i++) game.get(i).hit(myDeck.drawCard());
myDeck.drawCard();
for (int i = 0; i < game.size(); i++) game.get(i).hit(myDeck.drawCard());
while (true)
{
System.out.println("------------------------------------------------------");
System.out.println("\t\tTURN #" + turn);
System.out.println("------------------------------------------------------");
System.out.println("THE BET (Turn #" + turn + ")");
for (int i = 0; i < game.size(); i++)
{
if (!game.get(i).out)
{
System.out.print("Player #" + (i+1) + ": ");
game.get(i).printHand();
System.out.print("Player #" + (i+1) + ": Bet(1) or Fold(0)? ");
opt = sc.nextInt();
if (opt == 0)
{
game.get(i).out = true;
outCounter++;
}
else
{
game.get(i).bet(10);
pot += 10;
}
}
System.out.println("");
}
//Ends the hand if only one man remains
if (outCounter == game.size()-1) break;
System.out.println("Pot: " + pot);
System.out.println("THE SHIFT (Turn #" + turn + ")");
if(rn.nextInt(6) > 2)
{
for (int i = 0; i < game.size(); i++)
{
if (!game.get(i).out)
{
game.get(i).shift(myDeck.drawCard());
System.out.print("Player #" + (i+1) + ": ");
game.get(i).printHand();
}
}
}
else System.out.println(" No Shift Performed\n");
if (turn > 3)
{
System.out.println("THE CALL (Turn #" + turn + ")");
for (int i = 0; i < game.size(); i++)
{
if (!game.get(i).out && !call)
{
System.out.print("Player #" + (i+1) + ": ");
game.get(i).printHand();
System.out.println("Player #" + (i+1) + ": Call? Yes(1) or No(0)? ");
opt = sc.nextInt();
if (opt == 1) call = true;
}
}
}
if (call) break;
System.out.println("THE DRAW (Turn #" + turn + ")");
for (int i = 0; i < game.size(); i++)
{
if (!game.get(i).out)
{
System.out.print("Player #" + (i+1) + ": ");
game.get(i).printHand();
drawphase = myDeck.drawCard();
drawphase.print();
System.out.print(" (" + drawphase.getValue() + ")\n");
System.out.println("Player #" + (i+1) + ": Keep(1) or Discard(0)? ");
opt = sc.nextInt();
if (opt == 1) game.get(i).hit(drawphase);
}
}
turn++;
}
//takes out all who folded
for (int i = 0; i < hand.size(); i++)
{
if (hand.get(i).out)
{
hand.get(i).out = false;
hand.remove(i);
i--;
}
}
//takes out all who busted
for (int i = 0; i < hand.size(); i++)
{
if (Math.abs(hand.get(i).getValue()) > 23)
{
hand.get(i).bet(5);
hand.remove(i);
i--;
}
}
turn = 1;
for (int i = 0; i < game.size(); i++)
{
hand.get(i).hand_list.
}
}
}
}