-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hand.java
125 lines (113 loc) · 4.12 KB
/
Hand.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
124
125
import java.util.ArrayList;
import java.io.*;
import java.util.List;
import java.util.Arrays;
public class Hand {
private int total = 0;
private ArrayList<String> handContents = new ArrayList<String>();
private boolean isDisplay;
public String getCard(int index){
return handContents.get(index);
}
public void putInHand(Deck deck){
handContents.add(deck.draw());
}
public void takeOut(){
handContents.remove(handContents.get(0));
}
public void add(String card){
handContents.add(card);
}
public void conceal(String addition){
handContents.add(addition);
}
public void displayCard(){
for (int i = 0; i < handContents.size(); i++){
System.out.print(" _____ ");
}
if (isDisplay){
System.out.print(" _____ ");
}
System.out.println("");
for (int i = 0; i < handContents.size(); i++){
if (((handContents.get(i)).substring(1)).equals("10") || ((handContents.get(i)).substring(1)).equals("11") || ((handContents.get(i)).substring(1)).equals("12")){
System.out.print("| " + (handContents.get(i)).substring(1) +"|");
}
else{
System.out.print("| " + (handContents.get(i)).substring(1) +"|");
}
}
if (isDisplay){
System.out.print("|/////|");
}
System.out.println("");
for (int i = 0; i < handContents.size(); i++){
System.out.print("| |");
}
if (isDisplay){
System.out.print("|/////|");
}
System.out.println("");
for (int i = 0; i < handContents.size() -1; i++){
if (!isDisplay){
System.out.print("| " + (handContents.get(i)).substring(0, 1) + " |");
}
else{
System.out.println("| " + (handContents.get(i)).substring(0, 1) + " |");
}
}
if (!isDisplay){
System.out.println("| " + (handContents.get(handContents.size()-1)).substring(0, 1)+ " |");
}
else{
System.out.print("| " + (handContents.get(handContents.size()-1)).substring(0, 1)+ " |");
System.out.println("|/////|");
}
for (int i = 0; i < handContents.size(); i++){
System.out.print("| |");
}
if (isDisplay){
System.out.print("|/////|");
}
System.out.println("");
for (int i = 0; i < handContents.size(); i++){
if (((handContents.get(i)).substring(1)).equals("10") || ((handContents.get(i)).substring(1)).equals("11") || ((handContents.get(i)).substring(1)).equals("12")){
System.out.print("|" + (handContents.get(i)).substring(1) + "___|");
}
else{
System.out.print("|" + (handContents.get(i)).substring(1) + "____|");
}
}
if (isDisplay){
System.out.print("|/////|");
}
System.out.println("");
}
public void calculateTotal(){
total = 0;
for (int k = 0; k < handContents.size(); k++){
if (((handContents.get(k)).substring(1)).equals("Q") || ((handContents.get(k)).substring(1)).equals("K") || ((handContents.get(k)).substring(1)).equals("J")) {
total += 10;
}
else if (!((handContents.get(k)).substring(1)).equals("A")){
total += Integer.parseInt(((handContents.get(k)).substring(1)));
}
}
for (int j = 0; j < handContents.size(); j++){
if (((handContents.get(j)).substring(1)).equals("A")){
if (total + 11 > 21){
total += 1;
}
else{
total += 11;
}
}
}
}
public int getTotal(){
return total;
}
public void makeHidden(){
isDisplay = true;
}
}