diff --git a/app/src/main/java/com/example/mastermind/game/GameView.java b/app/src/main/java/com/example/mastermind/game/GameView.java index 0cc3a3b..bc872e2 100644 --- a/app/src/main/java/com/example/mastermind/game/GameView.java +++ b/app/src/main/java/com/example/mastermind/game/GameView.java @@ -24,10 +24,9 @@ public class GameView extends View { super(context); this.saisie=saisie; this.grille=grille; - //this.setOnTouchListener(new TouchListener()); + this.setOnTouchListener(new TouchListener(this)); //on initialise les collections de pions initpions(); - initSizes(); //state indique si le joueur soumet une combinaison ou false si elle est noté this.state=true; this.circle = new Paint(); @@ -50,12 +49,10 @@ public class GameView extends View { // affichage de la zone de saisie LinkedList saisie = new LinkedList(); saisie.addAll(this.saisie.getSelection()); - System.out.println(saisie.size()); for (int i=0;i soumissions; private LinkedList notations; public Grille(){ this.soumissions=new LinkedList(); this.notations=new LinkedList(); + this.sizeSubs=0; } - public void addSoumission(Collection newSub){ - this.soumissions.addAll((this.soumissions.size()-4),newSub); + public void addSoumission(LinkedList newSub){ + for (int i=4;i>0;i--){ + System.out.println("i="+i+", new sub="+newSub); + this.soumissions.set(this.soumissions.size()-this.sizeSubs*4-i,newSub.pop()); + } + this.sizeSubs+=1; } public void initGrille(Collection SubToCopy){ diff --git a/app/src/main/java/com/example/mastermind/game/Saisie.java b/app/src/main/java/com/example/mastermind/game/Saisie.java index ca2582b..defe853 100644 --- a/app/src/main/java/com/example/mastermind/game/Saisie.java +++ b/app/src/main/java/com/example/mastermind/game/Saisie.java @@ -13,6 +13,7 @@ import java.util.LinkedList; */ public class Saisie { + private int sizeSelection; private LinkedList choix; private LinkedList selection; public Saisie(){ @@ -22,11 +23,24 @@ public class Saisie { // getters et setters - public void setSelection(Collection chosenColors){ - this.selection.addAll(chosenColors); + public void initSelection(Integer chosenColors){ + this.selection.removeAll(this.selection); + for (int i=0;i<4;i++){ + this.selection.add(chosenColors); + } + this.sizeSelection=0; + } - public void setSelection(Integer chosenColors, int index){ - this.selection.set(index, chosenColors); + public void addSelection(Integer chosenColors){ + if (this.sizeSelection<4){ + this.selection.set(this.sizeSelection,this.choix.get(chosenColors)); + this.sizeSelection+=1; + } + + } + + public int getSizeSelection(){ + return this.sizeSelection; } public Collection getChoix(){ @@ -34,10 +48,11 @@ public class Saisie { } public void setChoix(Collection colorsSelected){ + this.choix.removeAll(this.choix); this.choix.addAll(colorsSelected); } - public Collection getSelection(){ + public LinkedList getSelection(){ return this.selection; } diff --git a/app/src/main/java/com/example/mastermind/game/TouchListener.java b/app/src/main/java/com/example/mastermind/game/TouchListener.java index 5d9f135..f90e813 100644 --- a/app/src/main/java/com/example/mastermind/game/TouchListener.java +++ b/app/src/main/java/com/example/mastermind/game/TouchListener.java @@ -4,9 +4,10 @@ import android.view.MotionEvent; import android.view.View; public class TouchListener implements View.OnTouchListener{ - - public TouchListener(){} - + private GameView view; + public TouchListener(GameView view) { + this.view=view; + } @Override public boolean onTouch(View v, MotionEvent event) { int action = event.getActionMasked(); @@ -15,7 +16,23 @@ public class TouchListener implements View.OnTouchListener{ if (action==MotionEvent.ACTION_UP) { - + if (v.getWidth()*689/420-v.getWidth()/15