Correction bug > Validation d'une proposition avec une pièce vide possible alors que non autorisée

This commit is contained in:
2023-04-08 18:22:26 +02:00
parent 2ef6863791
commit ece9929f4f
7 changed files with 47 additions and 32 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -76,45 +76,60 @@ public class MasterMindActivity extends AppCompatActivity {
} }
public void nextTurn(){ public void nextTurn(){
if(this.tour<9){ boolean nextable = true;
if (!vide){
LinearLayout anciennesPieces =(LinearLayout) this.jeu.getChildAt(this.tour);
for(int i=0; i<anciennesPieces.getChildCount(); i++){
if(((UnePiece)anciennesPieces.getChildAt(i)).getColor()==6){
nextable = false;
break;
}
}
}
if (nextable) {
if (this.tour < 9) {
//on affiche la correction //on affiche la correction
boolean gagne = this.afficherCorrection((LinearLayout) this.jeu.getChildAt(this.tour)); boolean gagne = this.afficherCorrection((LinearLayout) this.jeu.getChildAt(this.tour));
//on supprime les listener et sauvegarde la combinaison //on supprime les listener et sauvegarde la combinaison
LinearLayout anciennesPieces =(LinearLayout) this.jeu.getChildAt(this.tour); LinearLayout anciennesPieces = (LinearLayout) this.jeu.getChildAt(this.tour);
ArrayList<Integer> combinaison = new ArrayList<>(); ArrayList<Integer> combinaison = new ArrayList<>();
for(int i=0; i<anciennesPieces.getChildCount(); i++){ for (int i = 0; i < anciennesPieces.getChildCount(); i++) {
anciennesPieces.getChildAt(i).setOnTouchListener(null); anciennesPieces.getChildAt(i).setOnTouchListener(null);
combinaison.add(((UnePiece)anciennesPieces.getChildAt(i)).getColor()); combinaison.add(((UnePiece) anciennesPieces.getChildAt(i)).getColor());
} }
this.combinaisons.add(combinaison); this.combinaisons.add(combinaison);
if (gagne){ if (gagne) {
this.finDePartie(true); this.finDePartie(true);
} else { } else {
//on incremente le tour //on incremente le tour
this.tour++; this.tour++;
//on récupere le LinearLayout des pieces du tour //on récupere le LinearLayout des pieces du tour
LinearLayout pieces =(LinearLayout) this.jeu.getChildAt(this.tour); LinearLayout pieces = (LinearLayout) this.jeu.getChildAt(this.tour);
//on ajoute le listener //on ajoute le listener
for(int i=0; i<pieces.getChildCount(); i++) { for (int i = 0; i < pieces.getChildCount(); i++) {
UnePiece p = (UnePiece) pieces.getChildAt(i); UnePiece p = (UnePiece) pieces.getChildAt(i);
p.setOnTouchListener(new MonOnTouchListener(p, this.vide)); p.setOnTouchListener(new MonOnTouchListener(p, this.vide));
} }
} }
}else{ } else {
//on affiche la correction //on affiche la correction
boolean gagne = this.afficherCorrection((LinearLayout) this.jeu.getChildAt(this.tour)); boolean gagne = this.afficherCorrection((LinearLayout) this.jeu.getChildAt(this.tour));
//on supprime les listener //on supprime les listener
if(this.tour>0){ if (this.tour > 0) {
LinearLayout anciennesPieces =(LinearLayout) this.jeu.getChildAt(this.tour-1); LinearLayout anciennesPieces = (LinearLayout) this.jeu.getChildAt(this.tour - 1);
for(int i=0; i<anciennesPieces.getChildCount(); i++){anciennesPieces.getChildAt(i).setOnTouchListener(null);} for (int i = 0; i < anciennesPieces.getChildCount(); i++) {
anciennesPieces.getChildAt(i).setOnTouchListener(null);
}
} }
this.finDePartie(gagne); this.finDePartie(gagne);
} }
} }
}
public boolean afficherCorrection(LinearLayout pieces){ public boolean afficherCorrection(LinearLayout pieces){
int[] colorpiece=new int[4]; int[] colorpiece=new int[4];