-
Notifications
You must be signed in to change notification settings - Fork 0
/
Card.pde
64 lines (56 loc) · 1.19 KB
/
Card.pde
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
/**
* Class for a card
*/
public class Card implements Comparable<Card> {
public static final double _ratio = 1.4953271028037383; // 320.0 / 214
public static final int w = 125;
public static final int h = 187; // (int) Math.round(w * _ratio)
public int num;
public Suit suit;
public String s;
public String c = "?";
// Color
public String col;
/**
* Generates a card with a given value [1, 13]
*/
public Card(int num, Suit s) {
this.num = num;
this.suit = s;
col = getColor(s);
// Assign a character
if (num == 14) {
c = "a";
} else if (num >= 2 && num <= 10) {
c = "" + num;
} else if (num == 11){
c = "j";
} else if (num == 12) {
c = "q";
} else if (num == 13) {
c = "k";
}
this.s = "" + c + " of " + s.name();
}
@Override
public int compareTo(Card o) {
return Integer.compare(num, o.num);
}
public String toString() {
return s;
}
private String getColor(Suit s) {
switch(s) {
case CLUB:
return "r";
case SPADE:
return "b";
case HEART:
return "b";
case DIAMOND:
return "y";
default:
return "?";
}
}
}