-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpecialCard2.java
More file actions
182 lines (160 loc) · 5.43 KB
/
SpecialCard2.java
File metadata and controls
182 lines (160 loc) · 5.43 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
package net.ddns.x444556;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.font.FontRenderContext;
import java.util.Timer;
import java.util.TimerTask;
public class SpecialCard2 extends Card{
private static final long serialVersionUID = 777930635735238405L;
private int minAlpha = 100, maxAlpha = 200, alphaStep = 4, alpha = 100;
private int r = 0, rstep = 2;
private int g = 0, gstep = 2;
private int b = 0, bstep = 2;
public SpecialCard2(String name, int health, int damage) {
super(null, null, name, health, damage);
this.hidebg = true;
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if(alpha <= minAlpha) {
alpha = minAlpha;
alphaStep *= -1;
}
else if(alpha >= maxAlpha) {
alpha = maxAlpha;
alphaStep *= -1;
}
if(r >= 200) {
r = 200;
rstep *= -1;
}
if(g >= 200) {
g = 200;
gstep *= -1;
}
if(b >= 200) {
b = 200;
bstep *= -1;
}
if(r <= 20) {
r = 20;
rstep *= -1;
}
if(g <= 20) {
g = 20;
gstep *= -1;
}
if(b <= 20) {
b = 20;
bstep *= -1;
}
r += rstep;
if(rstep < 0) g += gstep;
if(gstep < 0) b += bstep;
repaint();
alpha += alphaStep;
}
}, 0, 50);
}
public SpecialCard2(Color bgColorStart, Color bgColorEnd, String name, int health, int damage) {
super(bgColorStart, bgColorEnd, name, health, damage);
this.hidebg = true;
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if(alpha <= minAlpha) {
alpha = minAlpha;
alphaStep *= -1;
}
else if(alpha >= maxAlpha) {
alpha = maxAlpha;
alphaStep *= -1;
}
if(r >= 200) {
r = 200;
rstep *= -1;
}
if(g >= 200) {
g = 200;
gstep *= -1;
}
if(b >= 200) {
b = 200;
bstep *= -1;
}
if(r <= 20) {
r = 20;
rstep *= -1;
}
if(g <= 20) {
g = 20;
gstep *= -1;
}
if(b <= 20) {
b = 20;
bstep *= -1;
}
r += rstep;
if(rstep < 0) g += gstep;
if(gstep < 0) b += bstep;
repaint();
alpha += alphaStep;
}
}, 0, 50);
}
@Override
public void paintComponent(Graphics g) {
for(int y=0; y<getHeight(); y++) {
for(int x=0; x<getWidth(); x++) {
g.setColor(new Color(r, this.g, b, alpha));
g.drawLine(x, y, x, y);
}
}
// Name
g.setFont(new Font("SansSerif", Font.BOLD, (int)(20.0/refX*getWidth())));
g.setColor(new Color(230, 230, 230));
g.drawString(Name, (int)(6.0/refX*getWidth()), (int)(28.0/refX*getWidth()));
// Image
g.setColor(Color.black);
g.fillRect((int)(6.0/refX*getWidth()), (int)(35.0/refX*getWidth()), getWidth() - (int)(12.0/refX*getWidth()), getWidth() -
(int)(12.0/refX*getWidth()));
// Attack
g.setColor(Color.black);
g.fillRect((int)(6.0/refX*getWidth()), (int)(42.0/refX*getWidth()) + getWidth() - (int)(12.0/refX*getWidth()),
(getWidth() - (int)(12.0/refX*getWidth())) / 3, (getWidth() - (int)(12.0/refX*getWidth())) / 3);
g.setFont(new Font("SansSerif", Font.BOLD, (int)(16.0/refX*getWidth())));
g.setColor(new Color(230, 230, 230));
g.drawString(Integer.toString(Damage), (int)(6.0/refX*getWidth()) + (getWidth() - (int)(12.0/refX*getWidth())) / 6 -
(int) (g.getFont().getStringBounds(Integer.toString(Damage),
new FontRenderContext(null, true, true)).getWidth() / 2), (int)(40.0/refX*getWidth()) + getWidth() -
(int)(12.0/refX*getWidth()) + (getWidth() - (int)(12.0/refX*getWidth())) / 3);
// Defense
g.setColor(Color.black);
g.fillRect((int)(13.0/refX*getWidth()) + (getWidth() - (int)(12.0/refX*getWidth())) / 3, (int)(42.0/refX*getWidth()) + getWidth() -
(int)(12.0/refX*getWidth()) , (getWidth() - (int)(12.0/refX*getWidth())) / 3, (getWidth() - (int)(12.0/refX*getWidth())) / 3);
g.setFont(new Font("SansSerif", Font.BOLD, (int)(16.0/refX*getWidth())));
g.setColor(new Color(230, 230, 230));
g.drawString(Integer.toString(Health), (int)(13.0/refX*getWidth()) + (getWidth() - (int)(12.0/refX*getWidth())) / 3 +
(getWidth() - (int)(12.0/refX*getWidth())) / 6 -
(int) (g.getFont().getStringBounds(Integer.toString(Health),
new FontRenderContext(null, true, true)).getWidth() / 2), (int)(40.0/refX*getWidth()) + getWidth() -
(int)(12.0/refX*getWidth()) + (getWidth() - (int)(12.0/refX*getWidth())) / 3);
// Abilities
for(int i=0; i<6; i++) {
g.setColor(Color.black);
g.fillRect((int)(20.0/refX*getWidth()) + (getWidth() - (int)(12.0/refX*getWidth())) / 3 * 2 + (((getWidth() -
(int)(12.0/refX*getWidth())) / 9 + (int)(3.0/refX*getWidth())) * (i / 3)),
(int)(42.0/refX*getWidth()) + getWidth() - (int)(12.0/refX*getWidth()) + (((getWidth() - (int)(12.0/refX*getWidth())) /
9 + (int)(2.0/refX*getWidth())) * (i % 3)),
(getWidth() - (int)(12.0/refX*getWidth())) / 9, (getWidth() - (int)(12.0/refX*getWidth())) / 9);
}
if(Duell != null && ((!Duell.myTurn && DuellPane.index(this, Duell.playerHandCards) != -1) ||
((DuellPane.index(this, Duell.playerCards) != -1 || DuellPane.index(this, Duell.enemyCards) != -1) && roundsSurvived == 0))) {
g.setColor(new Color(0, 0, 0, 90));
for(int y=0; y<getHeight(); y++) {
g.drawLine(0, y, getWidth(), y);
}
}
}
}