-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlackJackPlayer.java
More file actions
75 lines (66 loc) · 1.51 KB
/
BlackJackPlayer.java
File metadata and controls
75 lines (66 loc) · 1.51 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
import java.util.ArrayList;
import java.util.Scanner;
public class BlackJackPlayer {
public String name;
public ArrayList<Card> cards = new ArrayList<Card>();
public int money = 100;
public int bet;
BlackJackPlayer(String name)
{
this.name = name;
}
public void bet()
{
Scanner input = new Scanner(System.in);
boolean isValidBet = false;
int bet = 0;
while(!isValidBet)
{
System.out.println(this.name + ", specify a bet (min 5, max 20)");
bet = input.nextInt();
if(bet >= 5 && bet <= 20)
{
isValidBet = true;
this.money -= bet;
this.bet = bet;
}
else
{
System.out.println("Bet does not meet criteria");
}
}
}
public void drawCard(Card card)
{
this.cards.add(card);
}
public int getCardsValue()
{
int val = 0;
for(Card card : this.cards) {
val += card.value;
}
return val;
}
public void payUp(boolean wonHand)
{
if(wonHand)
{
this.money += 2 * this.bet;
}
this.bet = 0;
while(this.cards.size() > 0)
{
this.cards.remove(0);
}
}
public void payTie()
{
this.money += this.bet;
this.bet = 0;
while(this.cards.size() > 0)
{
this.cards.remove(0);
}
}
}