DEV_BUT1/DEV2.1/CTRLBLANC/Exo2/NOLAN EXO/MaGrille.java
2023-04-04 14:03:16 +02:00

48 lines
1.0 KiB
Java

public class MaGrille {
private String[][] Grille;
private int i, j, ligne, colonne, tour = 0;
public MaGrille(int li, int col) {
this.ligne = li;
this.colonne = col;
}
public MaGrille Gvide(int l, int c) {
MaGrille newGrille = new MaGrille(this.ligne, this.colonne);
String[][] grille = new String[newGrille.ligne][newGrille.colonne];
for(i=0;i<grille.length;i++) {
for(j=0;j<grille[i].length;j++) {
grille[i][j] = " ";
}
}
this.Grille = grille;
return null;
}
public String toString() {
String str = "";
for (i=0;i<Grille.length;i++) {
str += "";
for (j=0;j<Grille[i].length;j++) {
str += Grille[i][j] + "";
}
str += "\n";
}
return str + "┴─┴─┴─┴─┴─┴─┴─┴";
}
public void Jouer(int colonne) {
for (i=Grille.length-1;i>0;i--) {
if (Grille[i][colonne-1] == " ") {
if (tour%2 == 0) {
this.Grille[i][colonne-1] = "o";
tour++;
}
else {
this.Grille[i][colonne-1] = "x";
tour++;
}
}
}
}
}