Merge remote-tracking branch 'origin/master'

This commit is contained in:
Johann
2019-05-27 20:08:09 +02:00
6 changed files with 122 additions and 22 deletions

View File

@ -1,5 +1,43 @@
package piecesEchiquier;
//voir equalsIgnoreCase
/*
* Dans cette classes et bien d'autres, nous utilsons la méthode equalsIgnoreCase, voici sa documentation
*
* Compares this {@code String} to another {@code String}, ignoring case
* considerations. Two strings are considered equal ignoring case if they
* are of the same length and corresponding characters in the two strings
* are equal ignoring case.
*
* <p> Two characters {@code c1} and {@code c2} are considered the same
* ignoring case if at least one of the following is true:
* <ul>
* <li> The two characters are the same (as compared by the
* {@code ==} operator)
* <li> Applying the method {@link
* java.lang.Character#toUpperCase(char)} to each character
* produces the same result
* <li> Applying the method {@link
* java.lang.Character#toLowerCase(char)} to each character
* produces the same result
* </ul>
*
* @param anotherString
* The {@code String} to compare this {@code String} against
*
* @return {@code true} if the argument is not {@code null} and it
* represents an equivalent {@code String} ignoring case; {@code
* false} otherwise
*
* @see #equals(Object)
*
* public boolean equalsIgnoreCase(String anotherString) {
* return (this == anotherString) ? true
* : (anotherString != null)
* && (anotherString.value.length == value.length)
* && regionMatches(true, 0, anotherString, 0, value.length);
* }
*/
import joueurs.Joueur;
public class Echiquier {
@ -100,6 +138,13 @@ public class Echiquier {
public boolean verificationMouvement(Joueur J, String A, String B) // FONCTION TRADUCTION, VERIF + DEPLACEMENTS SI POSSIBLE
{// String A = coordonées de A; String B = coordonées de B
/**
* Converts all of the characters in this String to lowercase using the rules of the default locale. This is equivalent to calling toLowerCase(Locale.getDefault()).
* Note: This method is locale sensitive, and may produce unexpectedresults if used for strings that are intended to be interpreted localeindependently.Examples are programming language identifiers, protocol keys, and HTMLtags.For instance, "TITLE".toLowerCase() in a Turkish localereturns "t\u0131tle", where '\u0131' is theLATIN SMALL LETTER DOTLESS I character.To obtain correct results for locale insensitive strings, use toLowerCase(Locale.ROOT).
*
* Ceci est pour forcer le passage en minuscule au cas ou la méthode dans le main ne fonctionne pas
*/
A.toLowerCase();
B.toLowerCase();

View File

@ -27,9 +27,15 @@ public class main {
// déclaration des joueurs
System.out.println("Entrez le nom du joueur 1 : ");
Joueur j1 = new Joueur(sc.nextLine(), null);
if(j1.getNom().isEmpty()) {
j1.setNom("Joueur Par défaut 1");
}
System.out.println("Entrez le nom du joueur 2 : ");
Joueur j2 = new Joueur(sc.nextLine(), null);
if(j2.getNom().isEmpty()) {
j2.setNom("Joueur Par défaut 2");
}
Joueur jTemp = new Joueur(null, null); // ce joueur sert de mémoire pour le choix de l'odre de jeu
@ -83,7 +89,9 @@ public class main {
j1.setCouleur("Noir");
System.out.println("Le joueur " + j2.getNom() + " jouera les blancs et le joueur " + j1.getNom()
+ " jouera les noirs.");
/*
* Alors ici on utilise un joueur temporaire pour faire passe le deuxième joueur en joueur numéro 1
*/
jTemp.setNom(j1.getNom());
jTemp.setCouleur(j1.getCouleur());
@ -142,18 +150,24 @@ public class main {
}
else {
do {
System.out.println(
"Quelle pièce voulez-vous déplacer ? Donnez le code correspondant de la pièce à déplacer(ex : A1).\n");
A = sc.nextLine();
cA = A.charAt(0);
pA = A.charAt(1);
char cAl = Character.toLowerCase(cA);
sA = "" + cAl + pA;
System.out.println(
"À quel endroit la poser ? Donnez le code correspondant à l'endroit où poser la pièce.\n");
B = sc.nextLine();
System.out.println(
"Quelle pièce voulez-vous déplacer ? Donnez le code correspondant de la pièce à déplacer(ex : A1).\n");
A = sc.nextLine();
if(A.isEmpty()) {
A = "Z99";
}
cA = A.charAt(0);//ici on récupère le premier caractère du String
pA = A.charAt(1);//ici on récupère le second caratère
char cAl = Character.toLowerCase(cA); //ici on convertis un 'A' en 'a'
sA = "" + cAl + pA; //ici on concatène dans un nouveau string le a transformé avec le chiffre récupéré.
System.out.println(
"À quel endroit la poser ? Donnez le code correspondant à l'endroit où poser la pièce.\n");
B = sc.nextLine();
if(B.isEmpty()) {
B = "Z99";
}
}while(e.verificationMouvement(j1, sA, B) != true );
@ -208,10 +222,10 @@ public class main {
"Quelle pièce voulez-vous déplacer ? Donnez le code correspondant de la pièce à déplacer(ex : A1).\n");
A = sc.nextLine();
cA = A.charAt(0);
pA = A.charAt(1);
char cAl = Character.toLowerCase(cA);
sA = "" + cAl + pA;
cA = A.charAt(0);//ici on récupère le premier caractère du String
pA = A.charAt(1);//ici on récupère le second caratère
char cAl = Character.toLowerCase(cA); //ici on convertis un 'A' en 'a'
sA = "" + cAl + pA; //ici on concatène dans un nouveau string le a transformé avec le chiffre récupéré.
System.out.println(
"À quel endroit la poser ? Donnez le code correspondant à l'endroit où poser la pièce.\n");
@ -219,8 +233,7 @@ public class main {
}while(e.verificationMouvement(j2, sA, B) != true );
}
} // Tant que le mouvement n'est pas faisable on demande 2 coordonnées
// VERIF ECHECMAT