-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPeao.java
74 lines (59 loc) · 2.1 KB
/
Peao.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
/**
* Escreva a descrição da classe Peao aqui.
*
* @author (seu nome)
* @version (número de versão ou data)
*/
public class Peao extends Peca
{
/**
* Construtor para objetos da classe Peao
*/
public Peao(Casa casa, CorDaPeca cor)
{
//public static final int PEAO = 5;
super(casa, TipoDaPeca.PEAO, cor);
}
@Override
public Boolean mover(Casa destino, Tabuleiro tabuleiro) {
if(this.verificaDestino(this, destino)) {
if(this.podeMover(this.casa, destino)){
this.casa.removerPeca();
destino.colocarPeca(this);
this.casa = destino;
return true;
}
return false;
}
return false;
}
private Boolean podeMover(Casa casa, Casa destino) {
// variaveis para simplificar o codigo (Andre)
int x = destino.x;
int y = destino.y;
//Verifica se o destino esta no mesmo eixo x e y. (Andre)
if(this.getCor() == CorDaPeca.BRANCO){
if(casa.x == x && (casa.y == y - 1 || casa.y == 1 && y == 3) && (destino.getPeca() == null)) {
return true;
}
else if((casa.x == x + 1 || casa.x == x - 1) && (casa.y == y - 1) && (destino.getPeca() != null)){
return true;
}
else {
return false;
}
}
if(this.getCor() == CorDaPeca.PRETO){
if(casa.x == x && (casa.y == y + 1 || casa.y == 6 && y == 4) && (destino.getPeca() == null)){
return true;
}
else if((casa.x == x + 1 || casa.x == x - 1) && (casa.y == y + 1) && (destino.getPeca() != null)){
return true;
}
else {
return false;
}
}
return false;
}
}