44 lines
787 B
Java
44 lines
787 B
Java
import java.util.Arrays;
|
|
|
|
public class Configuration {
|
|
|
|
private char[][] grille;
|
|
|
|
|
|
public Configuration() {
|
|
this.grille = new char[3][3];
|
|
for(char[] ligne : grille) {
|
|
Arrays.fill(ligne, ' ');
|
|
}
|
|
}
|
|
|
|
|
|
public boolean estLibre(int x, int y) {
|
|
return this.grille[x][y] == ' ';
|
|
}
|
|
|
|
|
|
public Configuration jouer(int joueur, int x, int y) {
|
|
Configuration nouvelleConfig = this;
|
|
if (joueur == 1) {
|
|
nouvelleConfig.grille[x][y] = 'X';
|
|
return nouvelleConfig;
|
|
}
|
|
nouvelleConfig.grille[x][y] = 'O';
|
|
return nouvelleConfig;
|
|
}
|
|
|
|
// Pas demandé
|
|
public char[][] getGrille() {
|
|
return this.grille;
|
|
}
|
|
|
|
// Pas demandé
|
|
public String toString() {
|
|
String resultat = "";
|
|
for (char[] ligne : this.grille) {
|
|
resultat += Arrays.toString(ligne);
|
|
}
|
|
return resultat;
|
|
}
|
|
} |