-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGame.java
More file actions
96 lines (87 loc) · 2.4 KB
/
Copy pathGame.java
File metadata and controls
96 lines (87 loc) · 2.4 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
package Java;
import java.util.Scanner;
public class Game implements Play{
private static Scanner scanner = new Scanner(System.in);
private static int playerTotal,dealerTotal;
private static Deck deck;
private static String input;
@Override
public void explainRules() {
// TODO Auto-generated method stub
System.out.println("Stuff");
}
@Override
public void setUp() {
// TODO Auto-generated method stub
deck = new Deck();
deck.shuffle();
playerTotal = dealerTotal = 0;
}
@Override
public void playGame() {
// TODO Auto-generated method stub
setUp();
while(true){
System.out.println("Dealers hand:");
dealerTotal = deck.dealRaw();
System.out.println("\nYour hand:");
playerTotal = deck.dealRaw()+deck.dealRaw();
while(true){
System.out.println("\nHit or stay?");
input = scanner.nextLine();
if(input.toLowerCase().equals("hit")){
playerTotal+=deck.dealRaw();
}else if(input.toLowerCase().equals("stay")){
break;
}else{
System.out.println("Not a valid response.");
}
if(playerTotal>21){
break;
}System.out.println("Your Total: "+playerTotal);
}
if(playerTotal>21){
System.out.println("Your Total: "+playerTotal);
System.out.println("Dealer Total: "+dealerTotal);
System.out.println("You busted!");
break;
}
System.out.print("\n");
dealerTotal+=deck.dealRaw();
System.out.println("Dealer Total:"+dealerTotal+"\n");
while(dealerTotal<=16){
System.out.println("Dealer hits:");
dealerTotal+=deck.dealRaw();
System.out.println("Dealer Total: "+dealerTotal+"\n");
}
if(dealerTotal>21){
System.out.println("Your Total: "+playerTotal);
System.out.println("Dealer Total: "+dealerTotal);
System.out.println("Dealer busted!");
break;
}
if(playerTotal>dealerTotal){
System.out.println("Your Total: "+playerTotal);
System.out.println("Dealer Total: "+dealerTotal);
System.out.println("You win!");
break;
}
else if(playerTotal<dealerTotal){
System.out.println("Your Total: "+playerTotal);
System.out.println("Dealer Total: "+dealerTotal);
System.out.println("You lost!");
break;
}
else{
System.out.println("Your Total: "+playerTotal);
System.out.println("Dealer Total: "+dealerTotal);
System.out.println("Push!");
break;
}
}
}
@Override
public void gameOver(String winner) {
// TODO Auto-generated method stub
}
}