-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReine.java
More file actions
181 lines (123 loc) · 5.03 KB
/
Copy pathReine.java
File metadata and controls
181 lines (123 loc) · 5.03 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
public class Reine extends Piece{
public Reine(int couleur, int i,int j){
super("Reine",couleur,i,j,5);
}
public boolean mouvement_possible(int horizontal, int vertical){
/* on combine le fou et la tour */
return Math.abs(horizontal) == Math.abs(vertical)
||
Math.abs(horizontal)* Math.abs(vertical) == 0;
}
//cette fonction va nous dire si on peut gray ou pas
public boolean manger_possible(Case case_dest ,int horizontal, int vertical){
/* si le mouv est possible, et que la case est occupee, alors on teste si elle
est occupee par une piece adverse*/
if ((mouvement_possible(horizontal,vertical) && case_dest.estOccupe()) == true ){
if ( case_dest.getPiece().getCouleur() != this.getCouleur()){
/* on test si c'est une piece adverse que tu veux manger*/
return true;
}
}
return false;
}
//cette fonction nous dira si la voie est libre pour faire notre deplacement
public boolean chemin_libre(Case case_dest, Plateau p, int horizontal, int vertical){
if (Math.abs(horizontal)==Math.abs(vertical)) {
if (case_dest.geti() < this.geti()) {
if (case_dest.getj() < this.getj()) {
for (int ind =1; this.geti()-ind>case_dest.geti(); ind++) {
if (p.getCase( (this.geti()-ind)*8 + (this.getj()-ind)).getPiece() != null) {
return false;
}
}
}
if (case_dest.getj() > this.getj()) {
for (int ind =1; this.geti()-ind>case_dest.geti(); ind++) {
if (p.getCase( (this.geti()-ind)*8 + (this.getj()+ind)).getPiece() != null) {
return false;
}
}
}
}
if (case_dest.geti() > this.geti()) {
if (case_dest.getj() < this.getj()) {
for (int ind =1; this.geti()+ind<case_dest.geti(); ind++) {
if (p.getCase( (this.geti()+ind)*8 + (this.getj()-ind)).getPiece() != null) {
return false;
}
}
}
if (case_dest.getj() > this.getj()) {
for (int ind =1; this.geti()+ind<case_dest.geti(); ind++) {
if (p.getCase((this.geti()+ind)*8 + (this.getj()+ind)).getPiece() != null) {
return false;
}
}
}
}
}
else {
if (case_dest.geti() < this.geti()) {
for (int ind =1; this.geti()-ind>case_dest.geti(); ind++) {
if (p.getCase( (this.geti()-ind)*8 + (this.getj())).getPiece() != null) {
return false;
}
}
}
if (case_dest.geti() > this.geti()) {
for (int ind =1; this.geti()+ind<case_dest.geti(); ind++) {
if (p.getCase( (this.geti()+ind)*8 + (this.getj())).getPiece() != null) {
return false;
}
}
}
if (case_dest.getj() < this.getj()) {
for (int ind =1; this.getj()-ind>case_dest.getj(); ind++) {
if (p.getCase( (this.geti())*8 + (this.getj()-ind)).getPiece() != null) {
return false;
}
}
}
if (case_dest.getj() > this.getj()) {
for (int ind =1; this.getj()+ind<case_dest.getj(); ind++) {
if (p.getCase( (this.geti())*8 + (this.getj()+ind)).getPiece() != null) {
return false;
}
}
}
}
return true;
}
//La fonction qui va nous permettre de deplacer notre Reine.
public String deplacer(Case case_dest,Plateau p){
String historique = ""; /* historique de coup quon va renvoyer*/
/* mtn on va recuperer ce qui sépare notre case de la case darrivee*/
int horizontal = Math.abs(case_dest.geti()) - this.geti();
int vertical = Math.abs(case_dest.getj()) - this.getj();
//on test tout dabbord si le chemin est libre.
if(chemin_libre(case_dest , p, horizontal, vertical)){
// on test si on peut manger, si oui alors on se deplace.
if(manger_possible(case_dest,horizontal,vertical)){
Piece piece_manger = case_dest.getPiece(); // on sauve la piece manger
int current_position = this.getPosition(); // on sauve la position courrante
p.getCase(current_position).setPiece(null); //on vide la case de depart
case_dest.setPiece(this); // on remplace la piece manger par la notre
historique = "nous avons manger un " + piece_manger.getNom();
// on renvoit la piece manger
super.setI(case_dest.geti());
super.setJ(case_dest.getj());
}
/* on test si le mouvement est possible, si oui alors on se deplace*/
else if(mouvement_possible(horizontal,vertical) && (! case_dest.estOccupe()) ){
int current_position = this.getPosition(); /* on sauve la position courrante*/
p.getCase(current_position).setPiece(null);/* on vide la case de depart*/
case_dest.setPiece(this); /* on place notre pion dans la case darrivee*/
historique = "Tu tes deplacer a la position:" + case_dest.getPositon();
//on renvois la position darriver
super.setI(case_dest.geti());
super.setJ(case_dest.getj());
}
}
return historique; //on retourne lhistorique
}
}