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,43 +76,58 @@ public class MasterMindActivity extends AppCompatActivity {
} }
public void nextTurn(){ public void nextTurn(){
if(this.tour<9){ boolean nextable = true;
//on affiche la correction if (!vide){
boolean gagne = this.afficherCorrection((LinearLayout) this.jeu.getChildAt(this.tour));
//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<>();
for(int i=0; i<anciennesPieces.getChildCount(); i++){ for(int i=0; i<anciennesPieces.getChildCount(); i++){
anciennesPieces.getChildAt(i).setOnTouchListener(null); if(((UnePiece)anciennesPieces.getChildAt(i)).getColor()==6){
combinaison.add(((UnePiece)anciennesPieces.getChildAt(i)).getColor()); nextable = false;
} break;
this.combinaisons.add(combinaison);
if (gagne){
this.finDePartie(true);
} else {
//on incremente le tour
this.tour++;
//on récupere le LinearLayout des pieces du tour
LinearLayout pieces =(LinearLayout) this.jeu.getChildAt(this.tour);
//on ajoute le listener
for(int i=0; i<pieces.getChildCount(); i++) {
UnePiece p = (UnePiece) pieces.getChildAt(i);
p.setOnTouchListener(new MonOnTouchListener(p, this.vide));
} }
} }
}
}else{
//on affiche la correction if (nextable) {
boolean gagne = this.afficherCorrection((LinearLayout) this.jeu.getChildAt(this.tour)); if (this.tour < 9) {
//on supprime les listener //on affiche la correction
if(this.tour>0){ boolean gagne = this.afficherCorrection((LinearLayout) this.jeu.getChildAt(this.tour));
LinearLayout anciennesPieces =(LinearLayout) this.jeu.getChildAt(this.tour-1); //on supprime les listener et sauvegarde la combinaison
LinearLayout anciennesPieces = (LinearLayout) this.jeu.getChildAt(this.tour);
for(int i=0; i<anciennesPieces.getChildCount(); i++){anciennesPieces.getChildAt(i).setOnTouchListener(null);}
ArrayList<Integer> combinaison = new ArrayList<>();
for (int i = 0; i < anciennesPieces.getChildCount(); i++) {
anciennesPieces.getChildAt(i).setOnTouchListener(null);
combinaison.add(((UnePiece) anciennesPieces.getChildAt(i)).getColor());
}
this.combinaisons.add(combinaison);
if (gagne) {
this.finDePartie(true);
} else {
//on incremente le tour
this.tour++;
//on récupere le LinearLayout des pieces du tour
LinearLayout pieces = (LinearLayout) this.jeu.getChildAt(this.tour);
//on ajoute le listener
for (int i = 0; i < pieces.getChildCount(); i++) {
UnePiece p = (UnePiece) pieces.getChildAt(i);
p.setOnTouchListener(new MonOnTouchListener(p, this.vide));
}
}
} else {
//on affiche la correction
boolean gagne = this.afficherCorrection((LinearLayout) this.jeu.getChildAt(this.tour));
//on supprime les listener
if (this.tour > 0) {
LinearLayout anciennesPieces = (LinearLayout) this.jeu.getChildAt(this.tour - 1);
for (int i = 0; i < anciennesPieces.getChildCount(); i++) {
anciennesPieces.getChildAt(i).setOnTouchListener(null);
}
}
this.finDePartie(gagne);
} }
this.finDePartie(gagne);
} }
} }