-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathActionCard.java
More file actions
188 lines (153 loc) · 4.91 KB
/
ActionCard.java
File metadata and controls
188 lines (153 loc) · 4.91 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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package Espionage;
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Stroke;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import Espionage.Player.AgentName;
/**
* @author Astrid
* This is the cards to make your choices with.
* This class produces different images of the card.
**/
public class ActionCard {
static enum CardType {
_1_SECRET_MISSION,
_2_EMBASSY_MEETING,
AGENT,
BRIBE,
COUNTERESPIONAGE,
REPORT,
PLACEHOLDER
}
private CardType type;
private AgentName player;
private boolean disabled;
private boolean selected;
private long value;
public ActionCard(CardType kt, long idx) {
value = idx;
type = kt;
disabled = false;
selected = false;
}
public CardType getType() {
return type;
}
public long getValue() {
return value;
}
public ActionCard setPlayer(AgentName arg) {
player = arg;
return this;
}
public AgentName getPlayer() {
return player;
}
public void setDisabled(boolean b) {
disabled = b;
}
public boolean getDisabled() {
return disabled;
}
public void setSelected(boolean b) {
selected = b;
}
public boolean getSelected() {
return selected;
}
public BufferedImage getDisabledFrontImage(int width, int height) {
return getFrontImage( width, height, true );
}
public BufferedImage getFrontImage(int width, int height) {
return getFrontImage( width, height, disabled);
}
//Creates Image to show the ActionCard on the Board.
public BufferedImage getFrontImage(int width, int height, boolean gray) {
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bufferedImage.createGraphics();
// fill the inner part with white or yellow
if(selected) g2d.setColor(Color.decode("0xFFFFC3")); //pale yellow
else g2d.setColor(Color.white);
g2d.fillRect(4, 4, width - 8, height - 8);
// draw 4px border in player's color
Stroke line4px = new BasicStroke(4f);
g2d.setColor(getPlayer().color);
g2d.setStroke(line4px);
g2d.drawRoundRect(4, 4, width-8, height-8, 5, 5);
if (gray) g2d.setColor(Color.lightGray);
else g2d.setColor(Color.black);
String msg1 = "";
String msg2 = "";
switch (type) {
case _1_SECRET_MISSION: msg1 = "1"; msg2 = ""; break;
case _2_EMBASSY_MEETING: msg1 = "2"; msg2 = ""; break;
case AGENT: msg1 = "A"; msg2 = Long.toString(getValue()); break;
case BRIBE: msg1 = "B"; msg2 = Long.toString(getValue()); break;
case COUNTERESPIONAGE: msg1 = "C"; msg2 = ""; break;
case REPORT: msg1 = "R"; msg2 = ""; break;
default: msg1 = ""; msg2 = ""; break;
}
//Vary the fontsize
Font myFont1 = g2d.getFont().deriveFont(Font.BOLD, height / 2 );
Font myFont2 = g2d.getFont().deriveFont(Font.BOLD, height / 5 );
g2d.setFont(myFont1);
{
int w = g2d.getFontMetrics().stringWidth(msg1);
int q = (width - w) / 2;
g2d.drawString(msg1, q, g2d.getFontMetrics().getAscent());
}
g2d.setFont(myFont2);
{
int w = g2d.getFontMetrics().stringWidth(msg2);
int q = (width - w) / 2;
g2d.drawString(msg2, q, height - g2d.getFontMetrics().getDescent()-4);
}
g2d.dispose();
return bufferedImage;
}
public BufferedImage getBackImage(int width, int height) {
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bufferedImage.createGraphics();
// --------------------------------------------------------------------------
if (type == CardType.PLACEHOLDER) {
g2d.setBackground(new Color(0, 0, 0, 0));
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.0f));
g2d.setColor(getPlayer().color);
float[] pattern = {5f, 5f};
Stroke dotted = new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, pattern, 0f);
g2d.setPaintMode();
g2d.setStroke( dotted );
g2d.drawRoundRect(5, 5, width - 10, height - 10, 5, 5);
g2d.dispose();
return bufferedImage;
}
// ---------------------------------------------------------
// draw 4px border in white
Stroke line4px = new BasicStroke(4f);
g2d.setStroke(line4px);
g2d.setColor(Color.white);
g2d.drawRoundRect(5, 5, width-10, height-10,5,5);
// fill inner image with black
g2d.setColor(Color.black);
g2d.fillRect(5, 5, width - 10, height - 10);
// draw a question-mark in player's color.
g2d.setColor(getPlayer().color);
Font myFont = g2d.getFont().deriveFont(Font.BOLD, height / 2 );
g2d.setFont(myFont);
FontMetrics qqq = g2d.getFontMetrics();
Rectangle2D r = qqq.getStringBounds("?", g2d);
double wq = r.getWidth();
double hq = r.getHeight();
double ds = qqq.getDescent();
double w2 = (width - wq) / 2;
double h2 = (height -hq) / 2;
g2d.drawString("?", (int)w2, (int)(h2+hq-ds));
g2d.dispose();
return bufferedImage;
}
}