Last active
March 31, 2018 01:49
-
-
Save JugurthaK/96162672a891c2e4b9bba5f600cf0fd5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Plateau { | |
private Ligne[] tabLignes; | |
private int nbColonne; | |
public Plateau() { | |
// This fait référence à l'objet lui-même et initialise les 2 attributs avec les paramètres | |
this(7,6); | |
} | |
public Plateau(int nbColonne, int nbLigne) { | |
this.nbColonne = nbColonne; | |
tabLignes = new Ligne[nbLigne]; | |
for (int i = 0; i < nbLigne; i++) { | |
tabLignes[i] = new Ligne(nbColonne); | |
} | |
} | |
public int getXY(int numColonne, int numLigne) { | |
return tabLignes[numLigne].getValeur(numColonne); | |
} | |
private void ajoutPion (int numColonne,int numLigne, int numJoueur){ | |
// si la ligne en dessous est occupée au même endroit ou que c'est la dernière ligne | |
if (numLigne == 0 || tabLignes[numLigne - 1].estVide(numColonne) == false){ | |
// dans ce cas on pose le pion | |
tabLignes[numLigne].setValeur(numColonne, numJoueur); | |
}else{ | |
// sinon, on recommence sur la ligne du dessous | |
ajoutPion(numColonne, numLigne-1, numJoueur); | |
} | |
} | |
// Création d'une méthode qui refait appel à ajout pion, mais qui cette fois ci ne prend que 2 paramètres | |
public void ajoutPion(int numColonne, int numJoueur){ | |
try { | |
// Défition de la valeur maximale de la ligne sur laquelle on se situe | |
int ligneMax = tabLignes[numColonne].getTaille() - 1; | |
ajoutPion(numColonne, ligneMax, numJoueur); | |
} catch (ArrayIndexOutOfBoundsException e) { | |
System.err.println("La colonne est pleine"); | |
} | |
} | |
public void gagne (int nbColonne, int nbLigne){ | |
} | |
public String toString(){ | |
String finalString = new String(); | |
for (int i = tabLignes.length - 1 ; i >= 0 ; i --){ | |
finalString += tabLignes[i].toString() + "\n"; | |
} | |
return finalString; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment