2019-03-20 14:13:47 +01:00
|
|
|
package piecesEchiquier;
|
|
|
|
|
2019-05-03 18:32:02 +02:00
|
|
|
import joueurs.Joueur;
|
|
|
|
|
2019-03-20 14:13:47 +01:00
|
|
|
public class Echiquier {
|
2019-05-09 09:30:32 +02:00
|
|
|
|
2019-03-20 14:13:47 +01:00
|
|
|
private String[][] codes =
|
2019-05-03 18:32:02 +02:00
|
|
|
{
|
2019-05-03 23:11:52 +02:00
|
|
|
{"A8","B8","C8","D8","E8","F8","G8","H8"},
|
|
|
|
{"A7","B7","C7","D7","E7","F7","G7","H7"},
|
|
|
|
{"A6","B6","C6","D6","E6","F6","G6","H6"},
|
|
|
|
{"A5","B5","C5","D5","E5","F5","G5","H5"},
|
|
|
|
{"A4","B4","C4","D4","E4","F4","G4","H4"},
|
|
|
|
{"A3","B3","C3","D3","E3","F3","G3","H3"},
|
|
|
|
{"A2","B2","C2","D2","E2","F2","G2","H2"},
|
|
|
|
{"A1","B1","C1","D1","E1","F1","G1","H1"}
|
2019-03-20 14:13:47 +01:00
|
|
|
};
|
2019-05-09 19:58:45 +02:00
|
|
|
|
2019-05-04 21:08:15 +02:00
|
|
|
private Pion pionB1 = new Pion("Blanc","PB",new Position(1,2));
|
|
|
|
private Pion pionB2 = new Pion("Blanc","PB",new Position(2,2));
|
|
|
|
private Pion pionB3 = new Pion("Blanc","PB",new Position(3,2));
|
|
|
|
private Pion pionB4 = new Pion("Blanc","PB",new Position(4,2));
|
|
|
|
private Pion pionB5 = new Pion("Blanc","PB",new Position(5,2));
|
|
|
|
private Pion pionB6 = new Pion("Blanc","PB",new Position(6,2));
|
|
|
|
private Pion pionB7 = new Pion("Blanc","PB",new Position(7,2));
|
|
|
|
private Pion pionB8 = new Pion("Blanc","PB",new Position(8,2));
|
|
|
|
|
|
|
|
private Pion pionN1 = new Pion("Noir","PN",new Position(1,7));
|
|
|
|
private Pion pionN2 = new Pion("Noir","PN",new Position(2,7));
|
|
|
|
private Pion pionN3 = new Pion("Noir","PN",new Position(3,7));
|
|
|
|
private Pion pionN4 = new Pion("Noir","PN",new Position(4,7));
|
|
|
|
private Pion pionN5 = new Pion("Noir","PN",new Position(5,7));
|
|
|
|
private Pion pionN6 = new Pion("Noir","PN",new Position(6,7));
|
|
|
|
private Pion pionN7 = new Pion("Noir","PN",new Position(7,7));
|
|
|
|
private Pion pionN8 = new Pion("Noir","PN",new Position(8,7));
|
|
|
|
|
|
|
|
private Tour TourB1 = new Tour("Blanc","TB",new Position(1,1));
|
|
|
|
private Tour TourB2 = new Tour("Blanc","TB",new Position(8,1));
|
|
|
|
private Tour TourN1 = new Tour("Noir","TN",new Position(1,8));
|
|
|
|
private Tour TourN2 = new Tour("Noir","TN",new Position(8,8));
|
|
|
|
|
|
|
|
private Cavalier CavalierB1 = new Cavalier("Blanc","CB",new Position(2,1));
|
|
|
|
private Cavalier CavalierB2 = new Cavalier("Blanc","CB",new Position(7,1));
|
|
|
|
private Cavalier CavalierN1 = new Cavalier("Noir","CN",new Position(2,8));
|
|
|
|
private Cavalier CavalierN2 = new Cavalier("Noir","CN",new Position(7,8));
|
|
|
|
|
|
|
|
private Fou FouB1 = new Fou("Blanc","FB",new Position(3,1));
|
|
|
|
private Fou FouB2 = new Fou("Blanc","FB",new Position(6,1));
|
|
|
|
private Fou FouN1 = new Fou("Noir","FN",new Position(3,8));
|
|
|
|
private Fou FouN2 = new Fou("Noir","FN",new Position(6,8));
|
|
|
|
|
|
|
|
private Reine ReineB1 = new Reine("Blanc","RB",new Position(4,1));
|
|
|
|
private Reine ReineN1 = new Reine("Noir","RN",new Position(4,8));
|
|
|
|
|
|
|
|
private Roi RoiB1 = new Roi("Blanc","KB",new Position(5,1));
|
|
|
|
private Roi RoiN1 = new Roi("Noir","KN",new Position(5,8));
|
2019-03-20 14:13:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
private Piece[][] echiquier =
|
|
|
|
{
|
|
|
|
{TourN1,CavalierN1,FouN1,RoiN1,ReineN1,FouN2,CavalierN2,TourN2},
|
|
|
|
{pionN1,pionN2,pionN3,pionN4,pionN5,pionN6,pionN7,pionN8},
|
2019-05-03 19:19:37 +02:00
|
|
|
{new Piece(new Position(1,6)),new Piece(new Position(2,6)),new Piece(new Position(3,6)),new Piece(new Position(4,6)),new Piece(new Position(5,6)),new Piece(new Position(6,6)),new Piece(new Position(7,6)),new Piece(new Position(8,6))},
|
|
|
|
{new Piece(new Position(1,5)),new Piece(new Position(2,5)),new Piece(new Position(3,5)),new Piece(new Position(4,5)),new Piece(new Position(5,5)),new Piece(new Position(6,5)),new Piece(new Position(7,5)),new Piece(new Position(8,5))},
|
|
|
|
{new Piece(new Position(1,4)),new Piece(new Position(2,4)),new Piece(new Position(3,4)),new Piece(new Position(4,4)),new Piece(new Position(5,4)),new Piece(new Position(6,4)),new Piece(new Position(7,4)),new Piece(new Position(8,4))},
|
|
|
|
{new Piece(new Position(1,3)),new Piece(new Position(2,3)),new Piece(new Position(3,3)),new Piece(new Position(4,3)),new Piece(new Position(5,3)),new Piece(new Position(6,3)),new Piece(new Position(7,3)),new Piece(new Position(8,3))},
|
2019-03-20 14:13:47 +01:00
|
|
|
{pionB1,pionB2,pionB3,pionB4,pionB5,pionB6,pionB7,pionB8},
|
|
|
|
{TourB1,CavalierB1,FouB1,RoiB1,ReineB1,FouB2,CavalierB2,TourB2}
|
|
|
|
};
|
|
|
|
|
2019-05-03 19:19:37 +02:00
|
|
|
|
2019-05-09 09:30:32 +02:00
|
|
|
public Echiquier() {
|
|
|
|
|
2019-03-20 14:13:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Piece[][] getEchiquier() {
|
|
|
|
return echiquier;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-03 18:32:02 +02:00
|
|
|
public String[][] getCodes() {
|
|
|
|
return codes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-20 14:13:47 +01:00
|
|
|
|
2019-05-09 19:58:45 +02:00
|
|
|
public String toString() // FONCTION AFFICHAGE
|
2019-03-20 14:13:47 +01:00
|
|
|
{
|
2019-05-04 12:57:53 +02:00
|
|
|
char alphabet[]= {'A','B','C','D','E','F','G','H'};
|
2019-03-20 14:13:47 +01:00
|
|
|
String echec = "";
|
2019-05-04 12:57:53 +02:00
|
|
|
int compteur=8;
|
2019-03-20 14:13:47 +01:00
|
|
|
for (int i = 0; i < 8;i++)
|
|
|
|
{
|
2019-05-04 12:57:53 +02:00
|
|
|
echec+= compteur + " ";
|
2019-03-20 14:13:47 +01:00
|
|
|
for (int j = 0; j < 8;j++)
|
|
|
|
{
|
2019-05-09 19:58:45 +02:00
|
|
|
echec +=echiquier[i][j].getNom();
|
2019-05-04 12:57:53 +02:00
|
|
|
echec += " ";
|
2019-03-20 14:13:47 +01:00
|
|
|
}
|
|
|
|
echec += "\n";
|
2019-05-04 12:57:53 +02:00
|
|
|
compteur--;
|
|
|
|
}
|
|
|
|
for (int i=0; i<8;i++)
|
|
|
|
{
|
|
|
|
echec+= " " + alphabet[i];
|
2019-03-20 14:13:47 +01:00
|
|
|
}
|
|
|
|
return echec;
|
|
|
|
}
|
2019-05-03 18:32:02 +02:00
|
|
|
|
2019-05-09 19:58:45 +02:00
|
|
|
public boolean VerifFinale(Joueur J, String A, String B) // FONCTION TRADUCTION, VERIF + DEPLACEMENTS SI POSSIBLE
|
2019-05-03 18:32:02 +02:00
|
|
|
{
|
|
|
|
int i = -1;
|
|
|
|
int j = -1;
|
|
|
|
int k;
|
|
|
|
int l;
|
2019-05-10 00:10:06 +02:00
|
|
|
//int stockX;
|
|
|
|
//int stockY;
|
|
|
|
//int stockX2;
|
|
|
|
//int stockY2;
|
|
|
|
Position stock;
|
|
|
|
Position stock2;
|
2019-05-03 18:32:02 +02:00
|
|
|
|
2019-05-09 19:58:45 +02:00
|
|
|
do { /// TEST 1ERE COORS
|
2019-05-03 18:32:02 +02:00
|
|
|
i++;
|
|
|
|
j = -1;
|
2019-05-09 10:54:41 +02:00
|
|
|
|
|
|
|
|
2019-05-03 18:32:02 +02:00
|
|
|
do {
|
|
|
|
j++;
|
2019-05-09 19:58:45 +02:00
|
|
|
if (getCodes()[i][j].equals(A)) //Cherche dans la matrice code si on trouve une string = celle donnée par le joueur
|
2019-05-03 18:32:02 +02:00
|
|
|
{
|
2019-05-09 10:54:41 +02:00
|
|
|
if (this.getEchiquier()[i][j].getClass().getName().equals("Piece")) // Verifie si la case choisie n'est pas vide
|
2019-05-03 18:32:02 +02:00
|
|
|
{
|
|
|
|
System.out.println("Vous avez choisi une case vide. Recommencez.");
|
|
|
|
return false;
|
|
|
|
}
|
2019-05-09 10:54:41 +02:00
|
|
|
else if (this.getEchiquier()[i][j].getCouleur() != J.getCouleur()) // Verifie si la piece choisie n'est pas de la faction opposée
|
2019-05-03 18:32:02 +02:00
|
|
|
{
|
|
|
|
System.out.println("Le pion choisi n'est pas de votre faction. Recommencez.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}while(( (getCodes()[i][j].equals(A)) == false) && (j+1 < codes.length));
|
|
|
|
}while((getCodes()[i][j].equals(A) == false) && (i+1 < codes.length));
|
2019-05-09 10:54:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-05-03 18:32:02 +02:00
|
|
|
|
2019-05-09 19:58:45 +02:00
|
|
|
for (k = 0; k < codes.length;k++) /// TEST 2EME COORS
|
2019-05-03 18:32:02 +02:00
|
|
|
{
|
2019-05-09 10:54:41 +02:00
|
|
|
for (l = 0; l < codes.length;l++)
|
|
|
|
{
|
2019-05-03 18:32:02 +02:00
|
|
|
if (getCodes()[k][l].equals(B) == true)
|
|
|
|
{
|
2019-05-09 10:54:41 +02:00
|
|
|
if (this.getEchiquier()[k][l].getCouleur() == J.getCouleur()) // Verifie que la piece visée n'est pas de ta faction
|
2019-05-03 18:32:02 +02:00
|
|
|
{
|
|
|
|
System.out.println("Le pion que vous voulez manger est de votre faction. Recommencez.");
|
|
|
|
return false;
|
2019-05-09 10:54:41 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
else if (this.getEchiquier()[i][j].deplacable(this,this.getEchiquier()[k][l]) == false) // VERIFICATION AVEC FONCTION DEPLACABLE
|
2019-05-03 18:32:02 +02:00
|
|
|
{
|
2019-05-09 19:58:45 +02:00
|
|
|
System.out.println("Déplacement impossible. Recommencez.");
|
2019-05-03 18:32:02 +02:00
|
|
|
return false;
|
2019-05-09 10:54:41 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
else
|
2019-05-03 18:32:02 +02:00
|
|
|
{
|
2019-05-09 09:30:32 +02:00
|
|
|
System.out.println("Choix validés. déplacement en cours.");
|
2019-05-10 00:10:06 +02:00
|
|
|
stock = new Position(l+1,8-k);
|
|
|
|
stock2 = new Position(j+1,8-i);
|
2019-05-03 23:11:52 +02:00
|
|
|
this.getEchiquier()[k][l] = this.getEchiquier()[i][j];
|
2019-05-10 00:10:06 +02:00
|
|
|
this.getEchiquier()[k][l].setPosition(stock);
|
|
|
|
this.getEchiquier()[i][j] = new Piece(stock2);
|
2019-05-03 18:32:02 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-09 19:58:45 +02:00
|
|
|
System.out.println("Un de vos codes est faux. Recommencez."); // SI COORS INEXISTANTE (EX : A)
|
2019-05-03 18:32:02 +02:00
|
|
|
return false;
|
2019-05-03 23:53:45 +02:00
|
|
|
}
|
2019-05-09 09:30:32 +02:00
|
|
|
|
|
|
|
public boolean estVide(Position position) {
|
|
|
|
int x = position.getX();
|
|
|
|
int y = position.getY();
|
2019-05-09 19:58:45 +02:00
|
|
|
|
|
|
|
if(this.echiquier[x][y].getNom()=="..") {
|
|
|
|
return true;
|
|
|
|
}
|
2019-05-09 09:30:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-05-03 23:53:45 +02:00
|
|
|
}
|