-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCasaGUI.java
More file actions
194 lines (152 loc) · 5.65 KB
/
Copy pathCasaGUI.java
File metadata and controls
194 lines (152 loc) · 5.65 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
189
190
191
192
193
194
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
/**
* Interface Grafica de uma Casa no tabuleiro do jogo.
*
* @author Alan Moraes <alan@ci.ufpb.br>
* @author Leonardo Villeth <lvilleth@cc.ci.ufpb.br>
*/
public class CasaGUI extends JButton {
// Constantes
public static final Color COR_CLARA = new Color(182, 155, 76);
public static final Color COR_ESCURA = new Color(65, 41, 1);
private static final Color COR_DESTAQUE = new Color(0, 1, 0, 0.4f);
// Icones das pecas
private static final Icon PEDRA_BRANCA = new ImageIcon("imagens/pedra_branca.png");
private static final Icon DAMA_BRANCA = new ImageIcon("imagens/dama_branca.png");
private static final Icon PEDRA_VERMELHA = new ImageIcon("imagens/pedra_vermelha.png");
private static final Icon DAMA_VERMELHA = new ImageIcon("imagens/dama_vermelha.png");
// Icones Pecas Xadrez
private static final Icon TORRE_BRANCA = new ImageIcon("imagens/torre_branca.png");
private static final Icon CAVALO_BRANCO = new ImageIcon("imagens/cavalo_branco.png");
private static final Icon BISPO_BRANCO = new ImageIcon("imagens/bispo_branco.png");
private static final Icon RAINHA_BRANCA = new ImageIcon("imagens/rainha_branca.png");
private static final Icon REI_BRANCO = new ImageIcon("imagens/rei_branco.png");
private static final Icon PEAO_BRANCO = new ImageIcon("imagens/peao_branco.png");
private static final Icon TORRE_PRETA = new ImageIcon("imagens/torre_preta.png");
private static final Icon CAVALO_PRETO = new ImageIcon("imagens/cavalo_preto.png");
private static final Icon BISPO_PRETO = new ImageIcon("imagens/bispo_preto.png");
private static final Icon RAINHA_PRETA = new ImageIcon("imagens/rainha_preta.png");
private static final Icon REI_PRETO = new ImageIcon("imagens/rei_preto.png");
private static final Icon PEAO_PRETO = new ImageIcon("imagens/peao_preto.png");
// Cores das pecas
public static final int SEM_PECA = -1;
public static final int PECA_BRANCA = 0;
public static final int PECA_PRETA = 1;
private int x;
private int y;
private Color cor;
public CasaGUI(int x, int y, Color cor, TabuleiroGUI tabuleiro) {
this.x = x;
this.y = y;
this.cor = cor;
setIcon(null);
// Layout e cor
setBackground(cor);
setOpaque(false);
setBorder(BorderFactory.createLineBorder(cor, 1));
setContentAreaFilled(false);
addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
tabuleiro.getJanela().reagir((CasaGUI) e.getSource());
}
});
}
public int getPosicaoX() {
return x;
}
public int getPosicaoY() {
return y;
}
//Desenhar pecas brancas
public void desenharTorreBranca() {
setIcon(TORRE_BRANCA);
}
public void desenharCavaloBranco() {
setIcon(CAVALO_BRANCO);
}
public void desenharBispoBranco() {
setIcon(BISPO_BRANCO);
}
public void desenharRainhaBranca() {
setIcon(RAINHA_BRANCA);
}
public void desenharReiBranco() {
setIcon(REI_BRANCO);
}
public void desenharPeaoBranco() {
setIcon(PEAO_BRANCO);
}
//Desenhar pecas pretas
public void desenharTorrePreta() {
setIcon(TORRE_PRETA);
}
public void desenharCavaloPreto() {
setIcon(CAVALO_PRETO);
}
public void desenharBispoPreto() {
setIcon(BISPO_PRETO);
}
public void desenharRainhaPreta() {
setIcon(RAINHA_PRETA);
}
public void desenharReiPreto() {
setIcon(REI_PRETO);
}
public void desenharPeaoPreto() {
setIcon(PEAO_PRETO);
}
public void apagarPeca() {
setIcon(null);
}
public boolean possuiPeca() {
return getIcon() != null;
}
public int getCorPeca() {
Icon icone = getIcon();
if (icone == TORRE_BRANCA || icone == CAVALO_BRANCO || icone == BISPO_BRANCO || icone == RAINHA_BRANCA
|| icone == REI_BRANCO || icone == PEAO_BRANCO) {
return PECA_BRANCA;
}
else if (icone == TORRE_PRETA || icone == CAVALO_PRETO || icone == BISPO_PRETO || icone == RAINHA_PRETA
|| icone == REI_PRETO || icone == PEAO_PRETO) {
return PECA_PRETA;
}
else {
return SEM_PECA;
}
}
//para poder comparar e controlar o highlighting na janela principal (Daniel)
//Ou pelo menos eu to tentando :(
public int getCor(){
if(getCorPeca() == PECA_BRANCA){
return 0; //indice da peça branca em outros arquivos
}
else if(getCorPeca() == PECA_PRETA){
return 6; //indice da peça preta em outros arquivos
}
return 1;
}
public void destacar() {
setBackground(COR_DESTAQUE);
}
public void atenuar() {
setBackground(cor);
}
/**
* Pinta o componente com a cor de fundo, aceita valores RGBA
*/
@Override
protected void paintComponent(Graphics g) {
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());
super.paintComponent(g);
}
}