-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.java
More file actions
52 lines (48 loc) · 1.51 KB
/
Card.java
File metadata and controls
52 lines (48 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
public class Card {
private String suit;
private int value; // Blackjack value -> Ace is assigned '11' to start
private String name;
private final String[] SUITS = {"Clubs", "Hearts", "Spades", "Diamonds"};
private final String[] NAME = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
private final String IMAGE_TAG = ".png";
public Card() {
suit = (SUITS[(int)(Math.random()*(SUITS.length))]);
value = (int)(Math.random()*(NAME.length)+1); // Temporary value
name = NAME[value-1];
if(value > 10)
value = 10;
if(value == 1) // If card is 'Ace' -> assign value 11
value = 11;
}
// s (suit) must be 0-3
// v (value) must be 1-13
public Card(int s, int v) {
suit = SUITS[s];
value = v; // Temporary value
name = NAME[value-1];
if(value > 10)
value = 10;
if(name == NAME[0]) // If card is 'Ace' -> assign value 11
value = 11;
}
// Get methods
public String getSuit() {
return suit;
}
public int getValue() {
return value;
}
public String getName() {
return name;
}
public String getImg() {
return name + suit + IMAGE_TAG;
}
// Set methods
public void setValue(int v) {
value = v;
}
public String toString() {
return "\n" + name + " of " + suit;
}
}