/
SinglePlayer.java~
123 lines (93 loc) · 2.98 KB
/
SinglePlayer.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
/*
// File: SinglePlayer.java
// Created: 2018/04/05
// Author: danIv
// Description: The single player game.
*/
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
import java.util.Random;
import java.util.Scanner;
public class SinglePlayer {
public static void main (String[] args){
Scanner reader = new Scanner(System.in);
String name = getName(reader);
double money = getMoney(reader);
double currentWager = 10.00; //Defaults to 10 per play
Dealer.initDeck(Dealer.deck); //Init the deck
Dealer.shuffleDeck(Dealer.deck);
Hand playerHand = new Hand(Dealer.dealStartingCards(Dealer.deck));
System.out.println("Dealing cards...\n");
try
{
TimeUnit.SECONDS.sleep(2);
}catch(InterruptedException ie)
{
}
System.out.println("You have recieved a " + playerHand.hand.get(0).suit.symbol);
String choice = "";
while(true){
System.out.println("(H)it, (St)and, (Sp)lit, (D)ouble, (Su)rrender");
choice = reader.nextLine();
boolean accepted = false;
String[] acceptedAnswers = {"H", "St", "Sp", "D", "Su"};
for(int i = 0; i < acceptedAnswers.length; i++){
if(choice.equals(acceptedAnswers[i])){
accepted = true;
break;
}
}
if(accepted)
break;
System.out.println("Sorry, but '" + choice + "' is not an accepted input.\n");
}
// if(choice.equals("H"))
// //Deal one card to player
// else if(choice.equals("D"))
// //Deal one card to player and double their wager
// else if(choice.equals("St"))
// //End the turn of the player
// else if(choice.equals("Sp"))
// //Split the player's hand into two hands
// else
}
public static double getMoney(Scanner reader){
double money = 0;
while(!false){
System.out.println("How much money do you have? You must have at least 10 dollars to play.");
money = reader.nextDouble();
reader.nextLine();
if(money>=10.00)
{
break;
}
System.out.println("You do not have enough money to begin. Please get more money and try again.");
}
return money;
}
public static String getName(Scanner reader){
String name = "";
while(!false){
System.out.println("Welcome to the table, what is your name?");
name = reader.nextLine();
if(name.length() >= 3){
break;
}
System.out.println("Sorry, but '" + name + "' is not a valid name.");
}
return name;
}
public static double getWager(Scanner reader, double currentWager){
double wager = 0;
while(!false){
System.out.println("What would you like to wager?");
wager = reader.nextDouble();
reader.nextLine();
if(wager >= currentWager){
break;
}
System.out.println("Sorry, but $" + wager + " is not a valid wager.\nPlease either match or raise $" + currentWager + ".");
}
return wager;
}
}