-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnoCard.java
More file actions
103 lines (86 loc) · 2.3 KB
/
UnoCard.java
File metadata and controls
103 lines (86 loc) · 2.3 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
97
98
99
100
101
102
103
import java.util.Random;
public class UnoCard {
public enum Color {
YELLOW("YELLOW"),
GREEN("GREEN"),
BLUE("BLUE"),
RED("RED"),
WILD("WILD");
private final String name;
private Color(String name){
this.name = name;
}
public String toString(){
return this.name;
}
static Color random(){
int rand = new Random().nextInt(5);
return Color.values()[rand];
}
static Color randomNonWild(){
int rand = new Random().nextInt(4);
return Color.values()[rand];
}
}
public enum Card {
ZERO("ZERO"),
ONE("ONE"),
TWO("TWO"),
THREE("THREE"),
FOUR("FOUR"),
FIVE("FIVE"),
SIX("SIX"),
SEVEN("SEVEN"),
EIGHT("EIGHT"),
NINE("NINE"),
SKIP("SKIP"),
DRAWTWO("DRAW TWO"),
REVERSE("REVERSE"),
WILD("\b"), //formatting
DRAWFOUR("DRAW FOUR");
private final String name;
private Card(String name){
this.name = name;
}
public String toString(){
return this.name;
}
static Card random(){
int rand = new Random().nextInt(15);
return Card.values()[rand];
}
static Card randomNonWild(){
int rand = new Random().nextInt(13);
return Card.values()[rand];
}
}
private Card cardtype;
private Color colortype;
public UnoCard(Card cardtype, Color colortype) {
this.cardtype = cardtype;
this.colortype = colortype;
}
public Card getCard(){
return this.cardtype;
}
public Color getColor(){
return this.colortype;
}
public void setColor(Color color){
this.colortype = color;
}
public String toString(){
return this.colortype + " " + this.cardtype + " CARD";
}
public static UnoCard random(){
Color color = Color.random();
Card card;
if (color.equals(Color.WILD)){
int rand = new Random().nextInt(2);
card = (rand == 1) ? Card.WILD : Card.DRAWFOUR;
} else {
card = Card.randomNonWild();
}
return new UnoCard(card,color);
}
}