mode solo fonctionnel + fix bug nettoyage + verif victoire

This commit is contained in:
Haïssous Kayyissa 2023-04-07 16:35:47 +02:00
parent 9b08b28846
commit 89d4de7fa8
4 changed files with 42 additions and 20 deletions

View File

@ -35,10 +35,11 @@ public class Bot {
}
public Integer[] notation(Integer[] soumission){
Integer[] note=new Integer[4];
LinkedList<Integer> note=new LinkedList<>();
for(int i=0; i<4;i++) {
if (this.collectionWin[i] == soumission[i]) {
note[i]=(this.pionsNotation[1]);
if (this.collectionWin[i]==soumission[i]) {
note.add(this.pionsNotation[1]);
System.out.println(note.getLast()+" good");
}
}
//On crée une copie de la combinaison gagnante pour la modifier et éviter la fausse répétition de pions blancs
@ -47,13 +48,24 @@ public class Bot {
for (int y=0; y<4;y++) {
if (i!=y){
if (copyCombi[y] == soumission[i]){
note[i]=(copyCombi[0]);
note.add(this.pionsNotation[0]);
System.out.println(note.getLast()+" almost");
copyCombi[y]=null;
}
}
}
}
// On complête avec des cases vides
while (note.size()<4){
note.addLast(this.pionVide);
}
return note;
Integer[] tabnote = new Integer[4];
//fill tab TODO: and shuffle
Random rand = new Random();
for(int i=0; i<4;i++) {
tabnote[i]=note.get(i);
}
return tabnote;
}
}

View File

@ -44,7 +44,6 @@ public class GameView extends View {
//copie des soumissions
LinkedList<Integer> grille = new LinkedList<Integer>();
grille.addAll(this.grille.getSoumissions());
//System.out.println(grille.size());
for (int y=0; y<10;y++) {
for (int x=0;x<4;x++) {
this.circle.setColor(grille.pop());
@ -55,7 +54,7 @@ public class GameView extends View {
// affichage de la zone de saisie
//copie de la zone de saisie
Integer[] saisie = this.saisie.getSelection();
for (int i=0;i<this.saisie.getSelection().length;i++){
for (int i=0;i<4;i++){
this.circle.setColor(saisie[i]);
//TODO: coordonnées propres (encore)
canvas.drawCircle((i*this.getWidth()/5+this.getWidth()/5),this.getHeight()-this.getHeight()*2/9, this.getWidth()/14, this.circle);
@ -65,7 +64,6 @@ public class GameView extends View {
//copie des couleurs dispos
LinkedList<Integer> couleurs = new LinkedList<Integer>();
couleurs.addAll(this.saisie.getChoix());
//System.out.println(couleurs.size());
for (int i=0;i<this.saisie.getChoix().size();i++){
this.circle.setColor(couleurs.pop());
//TODO: coordonnées propres (encore)
@ -103,6 +101,7 @@ public class GameView extends View {
if (!this.state) {
this.saisie.setChoix(this.pionsAttaquant);
this.grille.addNotation(this.saisie.getSelection());
victoire();
this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
this.invalidate();
this.state = !this.state;
@ -110,17 +109,17 @@ public class GameView extends View {
this.saisie.setChoix(this.pionsDefenseur);
this.grille.addSoumission(this.saisie.getSelection());
this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
this.invalidate();
invalidate();
this.state = !this.state;
}
} else if (this.state && this.saisie.getSizeSelection() == 4) {
this.saisie.setChoix(this.pionsDefenseur);
this.grille.addSoumission(this.saisie.getSelection());
Integer[] combi = this.saisie.getSelection();
this.grille.addSoumission(combi);
this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
//On fait noter la combinaison au Bot
this.grille.addNotation(this.theBot.notation((this.saisie.getSelection())));
this.invalidate();
this.grille.addNotation(this.theBot.notation((combi)));
victoire();
invalidate();
}
}
@ -140,12 +139,19 @@ public class GameView extends View {
}*/
public void clearChoix() {
this.saisie.initSelection(R.color.pionVide);
this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
this.invalidate();
}
public boolean conditionVictoire(int choix) {
if(choix==4) {
public boolean victoire (){
Integer[] lastNotation = this.grille.getLastNotation();
int nbWin=0;
for (int i=0;i<4;i++){
if (lastNotation[i]==this.pionsDefenseur[1]){
nbWin++;
}
}
if(nbWin==4) {
System.out.println("WIN");
return true;
} else {

View File

@ -76,5 +76,12 @@ public class Grille {
return this.notations;
}
public Integer[] getLastNotation(){
Integer[] lastNotation = new Integer[4];
for (int i=0;i<4;i++){
lastNotation[i]=this.notations.get(this.notations.size()-i-1);
}
return lastNotation;
}
}

View File

@ -38,9 +38,6 @@ public class TouchListener implements View.OnTouchListener{
// surveille si un bouton de controle est cliqué
} else if (v.getHeight()-v.getWidth()/16-v.getWidth()/13<y && y<v.getHeight()-v.getHeight()/16+v.getWidth()/13){
if(v.getWidth()/2+(v.getWidth()/11)*2-v.getWidth()/13<x && x<v.getWidth()/2+(v.getWidth()/11)*2+v.getWidth()/13) { // soumettre
if(!this.view.getState()) {
this.view.conditionVictoire(i);
}
this.view.changeState();
i = 0;
} else if (v.getWidth()/2-v.getWidth()/13<x && x<v.getWidth()/2+v.getWidth()/13) { // retour