This commit is contained in:
EmmanuelTiamzon
2025-09-30 09:43:41 +02:00
parent f7de13bc2a
commit 7019a3b7ea
176 changed files with 9458 additions and 149 deletions

View File

@@ -1,27 +1,43 @@
public class Configuration {
private char[9] grille;
private char[] grille;
/*
On veut que chaque case soit un x ou un o et que si elle est vide alors n
la première case est 1 la deuxième 2, etc...
*/
public Configuration() {
this.grille = {'n','n','n','n','n','n','n','n','n'};
this.grille = new char[]{'n','n','n','n','n','n','n','n','n'};
}
public static int estLibre(int posGrille) {
if(this.grille[posGrille-1] == 'n') {
return true;
}
public boolean estLibre(int posGrille) {
if (posGrille < 1 || posGrille > 9) {
throw new IllegalArgumentException("La position doit être entre 1 et 9.");
}
return this.grille[posGrille - 1] == 'n';
}
public void jouer(int position, char joueur) {
if(joueur == 'x') {
this.grille[position-1] = 'x';
} else if(joueur == 'o') {
this.grille[position-1] = 'o';
}
}
if (position < 1 || position > 9) {
throw new IllegalArgumentException("La position doit être entre 1 et 9.");
}
if (joueur != 'x' && joueur != 'o') {
throw new IllegalArgumentException("Le joueur doit être 'x' ou 'o'.");
}
if (!estLibre(position)) {
throw new IllegalArgumentException("Cette case est déjà occupée.");
}
this.grille[position - 1] = joueur;
}
public void afficherGrille() {
for (int i = 0; i < 9; i++) {
System.out.print(this.grille[i] + " ");
if ((i + 1) % 3 == 0) {
System.out.println();
}
}
}
}