maj grille et saisie, onDraw appele deux fois ???
This commit is contained in:
		@@ -12,6 +12,6 @@ public class HotSeatActivity extends Activity {
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
        super.onCreate(savedInstanceState);
 | 
			
		||||
        setContentView(new GameView(this, new Saisie(0), new Grille()));
 | 
			
		||||
        setContentView(new GameView(this, new Saisie(), new Grille()));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -2,16 +2,76 @@ package com.example.mastermind.game;
 | 
			
		||||
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.graphics.Canvas;
 | 
			
		||||
import android.graphics.Color;
 | 
			
		||||
import android.graphics.Paint;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
 | 
			
		||||
import com.example.mastermind.R;
 | 
			
		||||
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
import java.util.LinkedList;
 | 
			
		||||
 | 
			
		||||
public class GameView extends View {
 | 
			
		||||
 | 
			
		||||
    private Collection<Integer> pionsAttaquant;
 | 
			
		||||
    private Collection<Integer> pionsDefenseur;
 | 
			
		||||
    private Collection<Integer> pionsPasPlaces;
 | 
			
		||||
    private Saisie saisie;
 | 
			
		||||
    private Grille grille;
 | 
			
		||||
    private Paint circle;
 | 
			
		||||
    public GameView(Context context,Saisie saisie,Grille grille) {
 | 
			
		||||
        super(context);
 | 
			
		||||
        this.saisie=saisie;
 | 
			
		||||
        this.grille=grille;
 | 
			
		||||
        //on initialise les collections de pions
 | 
			
		||||
        initpions();
 | 
			
		||||
        this.circle = new Paint();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void onDraw(Canvas canvas){
 | 
			
		||||
        super.onDraw(canvas);
 | 
			
		||||
        this.setBackgroundColor(this.getResources().getColor(R.color.grey));
 | 
			
		||||
        LinkedList<Integer> grille = (LinkedList<Integer>) this.grille.getSoumissions();
 | 
			
		||||
        System.out.println("test?");
 | 
			
		||||
        for (int y=0; y<10;y++) {
 | 
			
		||||
            for (int x=0;x<4;x++) {
 | 
			
		||||
                /*this.circle.setColor(grille.pop());
 | 
			
		||||
                canvas.drawCircle(x*10,y*10, 50, this.circle);
 | 
			
		||||
                System.out.println("rond grille");*/
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void redraw(){
 | 
			
		||||
        invalidate();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //initialise les collections de pions
 | 
			
		||||
    public void initpions(){
 | 
			
		||||
        //on initialise les pions
 | 
			
		||||
        this.pionsPasPlaces = new LinkedList<Integer>();
 | 
			
		||||
        for (int i=0;i<4;i++){
 | 
			
		||||
            this.pionsPasPlaces.add(this.getResources().getColor(R.color.pionVide));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        this.pionsDefenseur = new LinkedList<Integer>();
 | 
			
		||||
        this.pionsDefenseur.add(this.getResources().getColor(R.color.white));
 | 
			
		||||
        this.pionsDefenseur.add(this.getResources().getColor(R.color.black));
 | 
			
		||||
 | 
			
		||||
        this.pionsAttaquant = new LinkedList<Integer>();
 | 
			
		||||
        this.pionsAttaquant.add(this.getResources().getColor(R.color.pink));
 | 
			
		||||
        this.pionsAttaquant.add(this.getResources().getColor(R.color.purple));
 | 
			
		||||
        this.pionsAttaquant.add(this.getResources().getColor(R.color.blue));
 | 
			
		||||
        this.pionsAttaquant.add(this.getResources().getColor(R.color.green));
 | 
			
		||||
        this.pionsAttaquant.add(this.getResources().getColor(R.color.yellow));
 | 
			
		||||
        this.pionsAttaquant.add(this.getResources().getColor(R.color.white));
 | 
			
		||||
 | 
			
		||||
        // on inisialise la saisie
 | 
			
		||||
        saisie.setSelection(this.pionsAttaquant);
 | 
			
		||||
        saisie.setChoix(this.pionsPasPlaces);
 | 
			
		||||
 | 
			
		||||
        // on rempli la grille de cases grises
 | 
			
		||||
        grille.initGrille(this.pionsPasPlaces);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,43 @@
 | 
			
		||||
package com.example.mastermind.game;
 | 
			
		||||
 | 
			
		||||
import android.graphics.Color;
 | 
			
		||||
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
import java.util.Deque;
 | 
			
		||||
import java.util.LinkedList;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
représente la grille de jeu à savoir la liste des soumissions ainsi que leur notation
 | 
			
		||||
 */
 | 
			
		||||
public class Grille {
 | 
			
		||||
    private LinkedList<Integer> soumissions;
 | 
			
		||||
    private LinkedList<Integer> notations;
 | 
			
		||||
 | 
			
		||||
    public Grille(){
 | 
			
		||||
        this.soumissions=new LinkedList<Integer>();
 | 
			
		||||
        this.notations=new LinkedList<Integer>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void addSoumission(Collection<Integer> newSub){
 | 
			
		||||
        this.soumissions.addAll((this.soumissions.size()-4),newSub);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void initGrille(Collection<Integer> SubToCopy){
 | 
			
		||||
        for(int i=0;i<10;i++){
 | 
			
		||||
            this.soumissions.addAll(SubToCopy);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void addNotation(Collection<Integer> newNot){
 | 
			
		||||
        this.notations.addAll(newNot);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Collection<Integer> getSoumissions(){
 | 
			
		||||
        return this.soumissions;
 | 
			
		||||
    }
 | 
			
		||||
    public Collection<Integer> getNotations(){
 | 
			
		||||
        return this.notations;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,49 +1,43 @@
 | 
			
		||||
package com.example.mastermind.game;
 | 
			
		||||
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.graphics.Color;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
import java.util.LinkedList;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
* Classe qui correspond à uen zone de saisie (soumission d'une combinaison ou notation)
 | 
			
		||||
* choix correspond aux couleurs pouvant être saisies en fonction de la situation et selection à la combinaison choisie
 | 
			
		||||
 */
 | 
			
		||||
public class Saisie {
 | 
			
		||||
 | 
			
		||||
    private Color[] choix;
 | 
			
		||||
    private Color[] selection;
 | 
			
		||||
    public Saisie(int state){
 | 
			
		||||
        // state correspond à si on soumet une combinaison ou si on la note (0 combi, 1 notation)
 | 
			
		||||
        if (state==0){
 | 
			
		||||
            choixCombinaison();
 | 
			
		||||
        } else if (state==1){
 | 
			
		||||
            notation();
 | 
			
		||||
        } // eventuellement signaler une erreur si on a une autre valeur
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // rempli le tableau de couleur avec les pions de l'attaquant
 | 
			
		||||
    public void choixCombinaison(){
 | 
			
		||||
        this.choix = new Color[6];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Rempli le tableau de couleur avec les pions du défenseur
 | 
			
		||||
    public void notation(){
 | 
			
		||||
        this.choix = new Color[2];
 | 
			
		||||
    private LinkedList<Integer> choix;
 | 
			
		||||
    private LinkedList<Integer> selection;
 | 
			
		||||
    public Saisie(){
 | 
			
		||||
        this.choix=new LinkedList<Integer>();
 | 
			
		||||
        this.selection=new LinkedList<Integer>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // getters et setters
 | 
			
		||||
 | 
			
		||||
    public void setChoix(Color[] colorsToChose){
 | 
			
		||||
        this.choix=colorsToChose;
 | 
			
		||||
    public void setChoix(Collection<Integer> chosenColors){
 | 
			
		||||
        this.choix.addAll(chosenColors);
 | 
			
		||||
    }
 | 
			
		||||
    public void setChoix(Integer chosenColors, int index){
 | 
			
		||||
        this.choix.set(index, chosenColors);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Color[] getChoix(){
 | 
			
		||||
    public Collection<Integer> getChoix(){
 | 
			
		||||
        return this.choix;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSelection(Color[] colorsSelected){
 | 
			
		||||
        this.selection=colorsSelected;
 | 
			
		||||
    public void setSelection(Collection<Integer> colorsSelected){
 | 
			
		||||
        this.selection.addAll(colorsSelected);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Color[] getSelection(){
 | 
			
		||||
    public Collection<Integer> getSelection(){
 | 
			
		||||
        return this.selection;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -33,7 +33,7 @@
 | 
			
		||||
        </TextView>
 | 
			
		||||
 | 
			
		||||
        <Button
 | 
			
		||||
            android:id="@+id/ORDI"
 | 
			
		||||
            android:id="@+id/HotSeat"
 | 
			
		||||
            android:layout_width="match_parent"
 | 
			
		||||
            android:layout_height="wrap_content"
 | 
			
		||||
            android:padding="20dp"
 | 
			
		||||
@@ -44,7 +44,7 @@
 | 
			
		||||
        </Button>
 | 
			
		||||
 | 
			
		||||
        <Button
 | 
			
		||||
            android:id="@+id/HotSeat"
 | 
			
		||||
            android:id="@+id/ORDI"
 | 
			
		||||
            android:layout_width="match_parent"
 | 
			
		||||
            android:layout_height="wrap_content"
 | 
			
		||||
            android:padding="20dp"
 | 
			
		||||
 
 | 
			
		||||
@@ -13,5 +13,7 @@
 | 
			
		||||
    <color name="green">#FFA8F387</color>
 | 
			
		||||
    <color name="yellow">#FFFEC603</color>
 | 
			
		||||
    <color name="grey">#FF333333</color>
 | 
			
		||||
    <color name="pionVide">#FF999999</color>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
</resources>
 | 
			
		||||
		Reference in New Issue
	
	Block a user