-
Notifications
You must be signed in to change notification settings - Fork 0
/
Card.java
executable file
·81 lines (69 loc) · 1.82 KB
/
Card.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
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class Card
{
private static final String hiddenUrl = "cards/hidden.png";
private static BufferedImage hiddenImage;
public static final Dimension SIZE = new Dimension(250, 363);
private BufferedImage image;
public static final String[] suits =
{
"clubs", "diamonds", "hearts", "spades"
};
public static final String[] ranks =
{
"2", "3", "4", "5", "6", "7", "8", "9", "10",
"ace", "jack", "queen", "king"
};
private String suit, rank;
public Card(String cardSuit, String cardRank)
{
suit = cardSuit;
rank = cardRank;
try
{
image = GamePanel.getImageFromFile("/cards/" + rank + "_of_" + suit + ".png");
} catch (Exception e)
{
e.printStackTrace();
}
}
public boolean matches(Card card)
{
return suit == card.suit && rank == card.rank;
}
public String toString()
{
return rank + " " + suit;
}
public int getPointValue()
{
if (rank.equals("ace"))
return 11;
else if (rank.equals("jack") || rank.equals("queen") || rank.equals("king"))
return 10;
else
return Integer.parseInt(rank);
}
public BufferedImage getImage()
{
return image;
}
public static void initHiddenCardImage()
{
try
{
hiddenImage = GamePanel.getImageFromFile(hiddenUrl);
} catch (Exception e)
{
e.printStackTrace();
}
}
public static BufferedImage getHiddenCardImage()
{
return hiddenImage;
}
}