-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deck.java
132 lines (124 loc) · 2.49 KB
/
Deck.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
126
127
128
129
130
131
132
import java.util.*;
import java.lang.Math;
class Deck{
/*Numbered cards are the same
1 for red, 2 for blue, 3 for green, and 4 for yellow
10 is skip, 11 is reverse, 12 is draw, 100000 is wild and 200000 is wild draw
*/
//find this
static List<Integer> deck = new ArrayList<Integer>();
public Deck(){
for(int i = 0; i < 10; i++){
for(int j = 1; j<5; j++){
deck.add(j*100+i);
}
}
for(int i = 1; i < 10; i++){
for(int j = 1; j<5; j++){
deck.add(j*100+i);
}
}
for(int i = 10; i < 13; i++){
for(int k = 1; k<5; k++){
deck.add(k*100+i);
}
}
for(int i = 10; i < 13; i++){
for(int k = 1; k<5; k++){
deck.add(k*100+i);
}
}
for(int i=0; i<4; i++){
deck.add(1000);
deck.add(2000);
}
}
public String toString(){
String str = "";
for(int i = 0; i < deck.size(); i++){
str+= cardToString(deck.get(i));
}
return str;
}
public static String cardToString(int num){
String str = "";
if(num<200){
str+= "Red ";
str+= cardType(num-100);
}else if(num<300){
str+= "Blue ";
str+= cardType(num-200);
}else if(num<400){
str+= "Green ";
str+= cardType(num-300);
}else if(num<500){
str+= "Yellow ";
str+= cardType(num-400);
}else if(num==1000){
str+= "Wild";
}else{
str+= "Wild Draw 4";
}
return str;
}
public static String cardType(int rawNum){
if(rawNum<10){
return Integer.toString(rawNum);
}else if(rawNum == 10){
return "Skip";
}else if(rawNum == 11){
return "Reverse";
}else if(rawNum == 12){
return "Draw 2";
}else{
return "NA";
}
}
public void shuffle(){
int oldLoc;
int newLoc;
int old;
for(int i = 0; i < deck.size()/4; i++){
oldLoc = (int)(Math.random()*deck.size());
newLoc = (int)(Math.random()*deck.size());
old = deck.get(oldLoc);
deck.set(oldLoc, deck.get(newLoc));
deck.set(newLoc, old);
}
}
public int drawCard(){
if(deck.size()==0){
resetCards();
System.out.println("Reshuffling...");
}
int card = deck.get(0);
deck.remove(0);
return card;
}
public void resetCards(){
for(int i = 0; i < 10; i++){
for(int j = 1; j<5; j++){
deck.add(j*100+i);
}
}
for(int i = 1; i < 10; i++){
for(int j = 1; j<5; j++){
deck.add(j*100+i);
}
}
for(int i = 10; i < 13; i++){
for(int k = 1; k<5; k++){
deck.add(k*100+i);
}
}
for(int i = 10; i < 13; i++){
for(int k = 1; k<5; k++){
deck.add(k*100+i);
}
}
for(int i=0; i<4; i++){
deck.add(1000);
deck.add(2000);
}
}
}