MVC
This commit is contained in:
		@@ -14,7 +14,7 @@
 | 
			
		||||
        android:theme="@style/Theme.MasterMind"
 | 
			
		||||
        tools:targetApi="31">
 | 
			
		||||
        <activity
 | 
			
		||||
            android:name=".HotSeatActivity"
 | 
			
		||||
            android:name=".GameActivity"
 | 
			
		||||
            android:exported="false" />
 | 
			
		||||
        <activity
 | 
			
		||||
            android:name=".SettingsActivity"
 | 
			
		||||
 
 | 
			
		||||
@@ -8,11 +8,12 @@ import com.example.mastermind.game.Grille;
 | 
			
		||||
import com.example.mastermind.game.Saisie;
 | 
			
		||||
 | 
			
		||||
public class HotSeatActivity extends Activity {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
        super.onCreate(savedInstanceState);
 | 
			
		||||
        boolean bot = getIntent().getBooleanExtra("bot", false);
 | 
			
		||||
        setContentView(new GameView(this, new Saisie(), new Grille(), bot));
 | 
			
		||||
        if setContentView(new ChoiceCombi(this, new Saisie()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void letsplay()
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										134
									
								
								app/src/main/java/com/example/mastermind/GameActivity.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										134
									
								
								app/src/main/java/com/example/mastermind/GameActivity.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,134 @@
 | 
			
		||||
package com.example.mastermind;
 | 
			
		||||
 | 
			
		||||
import android.app.Activity;
 | 
			
		||||
import android.graphics.Bitmap;
 | 
			
		||||
import android.graphics.Paint;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
 | 
			
		||||
import com.example.mastermind.game.Bot;
 | 
			
		||||
import com.example.mastermind.game.GameView;
 | 
			
		||||
import com.example.mastermind.game.Grille;
 | 
			
		||||
import com.example.mastermind.game.Saisie;
 | 
			
		||||
 | 
			
		||||
public class GameActivity extends Activity {
 | 
			
		||||
    private Integer[] pionsAttaquant;
 | 
			
		||||
    private Integer[] pionsDefenseur;
 | 
			
		||||
    private Integer pionVide;
 | 
			
		||||
    private Saisie saisie;
 | 
			
		||||
    private Grille grille;
 | 
			
		||||
    private boolean bot;
 | 
			
		||||
    private Bot theBot;
 | 
			
		||||
    private boolean state;
 | 
			
		||||
    private View view;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
        super.onCreate(savedInstanceState);
 | 
			
		||||
        this.bot = getIntent().getBooleanExtra("bot", false);
 | 
			
		||||
        this.state=true;
 | 
			
		||||
        this.saisie=new Saisie();
 | 
			
		||||
        this.grille=new Grille();
 | 
			
		||||
        initpions();
 | 
			
		||||
        this.theBot=new Bot(this.pionsAttaquant, this.pionsDefenseur, this.pionVide);
 | 
			
		||||
        if(!this.bot){
 | 
			
		||||
            //ChoiceCombi
 | 
			
		||||
        }
 | 
			
		||||
        this.view=new GameView(this,this.saisie, this.grille);
 | 
			
		||||
        setContentView(view);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Change l'état de soumission à notation après qu'une combinaision ai été soumise puis inversement
 | 
			
		||||
    public void changeState() {
 | 
			
		||||
        if(!this.bot) {
 | 
			
		||||
            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.view.invalidate();
 | 
			
		||||
                this.state = !this.state;
 | 
			
		||||
            } else if (this.state && this.saisie.getSizeSelection() == 4) {
 | 
			
		||||
                this.saisie.setChoix(this.pionsDefenseur);
 | 
			
		||||
                this.grille.addSoumission(this.saisie.getSelection());
 | 
			
		||||
                this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
 | 
			
		||||
                this.view.invalidate();
 | 
			
		||||
                this.state = !this.state;
 | 
			
		||||
            }
 | 
			
		||||
        } else if (this.state && this.saisie.getSizeSelection() == 4) {
 | 
			
		||||
            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((combi)));
 | 
			
		||||
            victoire();
 | 
			
		||||
            this.view.invalidate();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean getState() {
 | 
			
		||||
        return this.state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //ajoute une nouvelle couleur pour la séléction à soumettre
 | 
			
		||||
    public void addChoix(int choix){
 | 
			
		||||
        this.saisie.addSelection(choix);
 | 
			
		||||
        this.view.invalidate();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void removePion() {
 | 
			
		||||
        this.saisie.removeSelection(this.getResources().getColor(R.color.pionVide));
 | 
			
		||||
        this.view.invalidate();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void clearChoix() {
 | 
			
		||||
        this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
 | 
			
		||||
        this.view.invalidate();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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 {
 | 
			
		||||
            System.out.println("LOSE");
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //initialise les collections de pions et remplie saisie et grille de pions vides
 | 
			
		||||
    public void initpions(){
 | 
			
		||||
        //on initialise les pions
 | 
			
		||||
        //on créer une ligne de 4 pions gris représentants une ligne de pions vides
 | 
			
		||||
        this.pionVide = this.getResources().getColor(R.color.grey);
 | 
			
		||||
 | 
			
		||||
        //Le défenseur a des pions noirs et blancs
 | 
			
		||||
        this.pionsDefenseur = new Integer[2];
 | 
			
		||||
        this.pionsDefenseur[0]=this.getResources().getColor(R.color.white);
 | 
			
		||||
        this.pionsDefenseur[1]=this.getResources().getColor(R.color.black);
 | 
			
		||||
 | 
			
		||||
        //L'attaquant a des pions de couleurs
 | 
			
		||||
        this.pionsAttaquant = new Integer[6];
 | 
			
		||||
        this.pionsAttaquant[0]=this.getResources().getColor(R.color.pink);
 | 
			
		||||
        this.pionsAttaquant[1]=this.getResources().getColor(R.color.purple);
 | 
			
		||||
        this.pionsAttaquant[2]=this.getResources().getColor(R.color.blue);
 | 
			
		||||
        this.pionsAttaquant[3]=this.getResources().getColor(R.color.green);
 | 
			
		||||
        this.pionsAttaquant[4]=this.getResources().getColor(R.color.yellow);
 | 
			
		||||
        this.pionsAttaquant[5]=this.getResources().getColor(R.color.white);
 | 
			
		||||
 | 
			
		||||
        // on inisialise la saisie
 | 
			
		||||
        this.saisie.setChoix(this.pionsAttaquant);
 | 
			
		||||
        this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
 | 
			
		||||
 | 
			
		||||
        // on rempli la grille de cases grises
 | 
			
		||||
        this.grille.initGrille(this.pionVide);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -23,7 +23,7 @@ public class MainActivity extends Activity {
 | 
			
		||||
        mHotSeat.setOnClickListener(new View.OnClickListener() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onClick(View v) {
 | 
			
		||||
                Intent HotSeat = new Intent(MainActivity.this, HotSeatActivity.class);
 | 
			
		||||
                Intent HotSeat = new Intent(MainActivity.this, GameActivity.class);
 | 
			
		||||
                HotSeat.putExtra("bot", false);
 | 
			
		||||
                startActivity(HotSeat);
 | 
			
		||||
            }
 | 
			
		||||
@@ -31,7 +31,7 @@ public class MainActivity extends Activity {
 | 
			
		||||
        mORDI.setOnClickListener(new View.OnClickListener() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onClick(View v) {
 | 
			
		||||
                Intent ordi = new Intent(MainActivity.this, HotSeatActivity.class);
 | 
			
		||||
                Intent ordi = new Intent(MainActivity.this, GameActivity.class);
 | 
			
		||||
                ordi.putExtra("bot", true);
 | 
			
		||||
                startActivity(ordi);
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ import android.graphics.Color;
 | 
			
		||||
import android.graphics.Paint;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
 | 
			
		||||
import com.example.mastermind.GameActivity;
 | 
			
		||||
import com.example.mastermind.R;
 | 
			
		||||
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
@@ -16,29 +17,18 @@ import java.util.LinkedList;
 | 
			
		||||
 | 
			
		||||
public class GameView extends View {
 | 
			
		||||
 | 
			
		||||
    private Integer[] pionsAttaquant;
 | 
			
		||||
    private Integer[] pionsDefenseur;
 | 
			
		||||
    private Integer pionVide;
 | 
			
		||||
    private Saisie saisie;
 | 
			
		||||
    private Grille grille;
 | 
			
		||||
    private boolean bot;
 | 
			
		||||
    private Bot theBot;
 | 
			
		||||
    private Paint circle;
 | 
			
		||||
    private boolean state;
 | 
			
		||||
    private Bitmap cancelBtn;
 | 
			
		||||
    private Bitmap backBtn;
 | 
			
		||||
    private Bitmap validBtn;
 | 
			
		||||
    public GameView(Context context,Saisie saisie,Grille grille, boolean bot) {
 | 
			
		||||
    public GameView(GameActivity context, Saisie saisie, Grille grille) {
 | 
			
		||||
        super(context);
 | 
			
		||||
        this.saisie=saisie;
 | 
			
		||||
        this.grille=grille;
 | 
			
		||||
        this.bot=bot;
 | 
			
		||||
        initpions();
 | 
			
		||||
        this.theBot=new Bot(this.pionsAttaquant, this.pionsDefenseur, this.pionVide);
 | 
			
		||||
        this.setOnTouchListener(new TouchListener(this));
 | 
			
		||||
        //on initialise les collections de pions
 | 
			
		||||
        this.setOnTouchListener(new TouchListener(context));
 | 
			
		||||
        //state indique true si le joueur soumet une combinaison ou false si elle est noté
 | 
			
		||||
        this.state=true;
 | 
			
		||||
        this.circle = new Paint();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -46,15 +36,28 @@ public class GameView extends View {
 | 
			
		||||
    protected void onDraw(Canvas canvas){
 | 
			
		||||
        super.onDraw(canvas);
 | 
			
		||||
        this.setBackgroundColor(this.getResources().getColor(R.color.grey));
 | 
			
		||||
        //affichage des anciennes soumissions
 | 
			
		||||
        //copie des soumissions
 | 
			
		||||
        LinkedList<Integer> grille = new LinkedList<Integer>();
 | 
			
		||||
        grille.addAll(this.grille.getSoumissions());
 | 
			
		||||
        for (int y=0; y<10;y++) {
 | 
			
		||||
            for (int x=0;x<4;x++) {
 | 
			
		||||
                this.circle.setColor(grille.pop());
 | 
			
		||||
                //TODO: coordonnées propres
 | 
			
		||||
                canvas.drawCircle(( x*this.getWidth()/8+(this.getWidth()*21/68)),(y*this.getHeight()/14+this.getHeight()/21), this.getWidth()/17, this.circle);
 | 
			
		||||
        if(this.grille!=null) {
 | 
			
		||||
            //affichage des anciennes soumissions
 | 
			
		||||
            //copie des soumissions
 | 
			
		||||
            LinkedList<Integer> grille = new LinkedList<Integer>();
 | 
			
		||||
            grille.addAll(this.grille.getSoumissions());
 | 
			
		||||
            for (int y = 0; y < 10; y++) {
 | 
			
		||||
                for (int x = 0; x < 4; x++) {
 | 
			
		||||
                    this.circle.setColor(grille.pop());
 | 
			
		||||
                    canvas.drawCircle((x * this.getWidth() / 8 + (this.getWidth() * 21 / 68)), (y * this.getHeight() / 14 + this.getHeight() / 21), this.getWidth() / 17, this.circle);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            LinkedList<Integer> notation = new LinkedList<Integer>();
 | 
			
		||||
            notation.addAll(this.grille.getNotations());
 | 
			
		||||
            for(int y=0; y<10; y++) {
 | 
			
		||||
                for(int x=0; x<2; x++) { // colonne gauche
 | 
			
		||||
                    this.circle.setColor(notation.pop());
 | 
			
		||||
                    canvas.drawCircle((x*this.getWidth()/11+(this.getWidth()/11)),(y*this.getHeight()/14+getHeight()/21), this.getWidth()/26, this.circle);
 | 
			
		||||
                }
 | 
			
		||||
                for(int x=0; x<2; x++) { // colonne droite
 | 
			
		||||
                    this.circle.setColor(notation.pop());
 | 
			
		||||
                    canvas.drawCircle((x*this.getWidth()/11+(this.getWidth()*4/5)),(y*this.getHeight()/14+getHeight()/21), this.getWidth()/26, this.circle);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        // affichage de la zone de saisie
 | 
			
		||||
@@ -62,7 +65,6 @@ public class GameView extends View {
 | 
			
		||||
        Integer[] saisie = this.saisie.getSelection();
 | 
			
		||||
        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);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -72,36 +74,16 @@ public class GameView extends View {
 | 
			
		||||
        couleurs.addAll(this.saisie.getChoix());
 | 
			
		||||
        for (int i=0;i<this.saisie.getChoix().size();i++){
 | 
			
		||||
            this.circle.setColor(couleurs.pop());
 | 
			
		||||
            //TODO: coordonnées propres (encore)
 | 
			
		||||
            canvas.drawCircle((i*this.getWidth()*2/13+this.getWidth()/8),this.getHeight()-this.getHeight()/7, this.getWidth()/16, this.circle);
 | 
			
		||||
        }
 | 
			
		||||
        //TODO: ajout des colonnes de notation
 | 
			
		||||
        LinkedList<Integer> notation = new LinkedList<Integer>();
 | 
			
		||||
        notation.addAll(this.grille.getNotations());
 | 
			
		||||
        for(int y=0; y<10; y++) {
 | 
			
		||||
            for(int x=0; x<2; x++) { // colonne gauche
 | 
			
		||||
                this.circle.setColor(notation.pop());
 | 
			
		||||
                canvas.drawCircle((x*this.getWidth()/11+(this.getWidth()/11)),(y*this.getHeight()/14+getHeight()/21), this.getWidth()/26, this.circle);
 | 
			
		||||
            }
 | 
			
		||||
            for(int x=0; x<2; x++) { // colonne droite
 | 
			
		||||
                this.circle.setColor(notation.pop());
 | 
			
		||||
                canvas.drawCircle((x*this.getWidth()/11+(this.getWidth()*4/5)),(y*this.getHeight()/14+getHeight()/21), this.getWidth()/26, this.circle);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // bouton valider
 | 
			
		||||
        /*this.circle.setColor(this.getResources().getColor(R.color.green)); // version dessin
 | 
			
		||||
        canvas.drawCircle((this.getWidth()/2)+(getWidth()/11)*2,this.getHeight()-this.getHeight()/16, this.getWidth()/13, this.circle);*/
 | 
			
		||||
        validBtn = decodeSampledBitmapFromResource(getResources(), R.drawable.valid_button, getWidth()/13, getWidth()/13); // version img
 | 
			
		||||
        canvas.drawBitmap(validBtn, this.getWidth()/2+(this.getWidth()/11)*2-getWidth()/13, this.getHeight()/2+this.getHeight()*2/5, null);
 | 
			
		||||
        // bouton retour
 | 
			
		||||
       /* this.circle.setColor(this.getResources().getColor(R.color.blue));
 | 
			
		||||
        canvas.drawCircle((this.getWidth()/2), this.getHeight()-this.getHeight()/16, this.getWidth()/13, this.circle);*/
 | 
			
		||||
        backBtn = decodeSampledBitmapFromResource(getResources(), R.drawable.back_button, getWidth()/13, getWidth()/13);
 | 
			
		||||
        canvas.drawBitmap(backBtn, this.getWidth()/2-getWidth()/13, this.getHeight()/2+this.getHeight()*2/5, null);
 | 
			
		||||
        // bouton annuler
 | 
			
		||||
        /*this.circle.setColor(this.getResources().getColor(R.color.red));
 | 
			
		||||
        canvas.drawCircle((this.getWidth()/2)-(getWidth()/11)*2, this.getHeight()-this.getHeight()/16, this.getWidth()/13, this.circle);*/
 | 
			
		||||
        cancelBtn = decodeSampledBitmapFromResource(getResources(), R.drawable.cancel_button, getWidth()/13, getWidth()/13);
 | 
			
		||||
        canvas.drawBitmap(cancelBtn, this.getWidth()/2-(getWidth()/11)*2-getWidth()/13, this.getHeight()/2+this.getHeight()*2/5, null);
 | 
			
		||||
    }
 | 
			
		||||
@@ -130,97 +112,4 @@ public class GameView extends View {
 | 
			
		||||
        options.inJustDecodeBounds = false;
 | 
			
		||||
        return BitmapFactory.decodeResource(res, resId, options);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Change l'état de soumission à notation après qu'une combinaision ai été soumise puis inversement
 | 
			
		||||
    public void changeState() {
 | 
			
		||||
        if(!this.bot) {
 | 
			
		||||
            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;
 | 
			
		||||
            } else if (this.state && this.saisie.getSizeSelection() == 4) {
 | 
			
		||||
                this.saisie.setChoix(this.pionsDefenseur);
 | 
			
		||||
                this.grille.addSoumission(this.saisie.getSelection());
 | 
			
		||||
                this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
 | 
			
		||||
                invalidate();
 | 
			
		||||
                this.state = !this.state;
 | 
			
		||||
            }
 | 
			
		||||
        } else if (this.state && this.saisie.getSizeSelection() == 4) {
 | 
			
		||||
            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((combi)));
 | 
			
		||||
            victoire();
 | 
			
		||||
            invalidate();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean getState() {
 | 
			
		||||
        return this.state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //ajoute une nouvelle couleur pour la séléction à soumettre
 | 
			
		||||
    public void addChoix(int choix){
 | 
			
		||||
        this.saisie.addSelection(choix);
 | 
			
		||||
        this.invalidate();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void removePion() {
 | 
			
		||||
        this.saisie.removeSelection(this.getResources().getColor(R.color.pionVide));
 | 
			
		||||
        this.invalidate();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void clearChoix() {
 | 
			
		||||
        this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
 | 
			
		||||
        this.invalidate();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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 {
 | 
			
		||||
            System.out.println("LOSE");
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //initialise les collections de pions et remplie saisie et grille de pions vides
 | 
			
		||||
    public void initpions(){
 | 
			
		||||
        //on initialise les pions
 | 
			
		||||
        //on créer une ligne de 4 pions gris représentants une ligne de pions vides
 | 
			
		||||
        this.pionVide = this.getResources().getColor(R.color.grey);
 | 
			
		||||
 | 
			
		||||
        //Le défenseur a des pions noirs et blancs
 | 
			
		||||
        this.pionsDefenseur = new Integer[2];
 | 
			
		||||
        this.pionsDefenseur[0]=this.getResources().getColor(R.color.white);
 | 
			
		||||
        this.pionsDefenseur[1]=this.getResources().getColor(R.color.black);
 | 
			
		||||
 | 
			
		||||
        //L'attaquant a des pions de couleurs
 | 
			
		||||
        this.pionsAttaquant = new Integer[6];
 | 
			
		||||
        this.pionsAttaquant[0]=this.getResources().getColor(R.color.pink);
 | 
			
		||||
        this.pionsAttaquant[1]=this.getResources().getColor(R.color.purple);
 | 
			
		||||
        this.pionsAttaquant[2]=this.getResources().getColor(R.color.blue);
 | 
			
		||||
        this.pionsAttaquant[3]=this.getResources().getColor(R.color.green);
 | 
			
		||||
        this.pionsAttaquant[4]=this.getResources().getColor(R.color.yellow);
 | 
			
		||||
        this.pionsAttaquant[5]=this.getResources().getColor(R.color.white);
 | 
			
		||||
 | 
			
		||||
        // on inisialise la saisie
 | 
			
		||||
        saisie.setChoix(this.pionsAttaquant);
 | 
			
		||||
        saisie.initSelection(this.getResources().getColor(R.color.pionVide));
 | 
			
		||||
 | 
			
		||||
        // on rempli la grille de cases grises
 | 
			
		||||
        grille.initGrille(this.pionVide);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,11 +3,13 @@ package com.example.mastermind.game;
 | 
			
		||||
import android.view.MotionEvent;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
 | 
			
		||||
import com.example.mastermind.GameActivity;
 | 
			
		||||
 | 
			
		||||
public class TouchListener implements View.OnTouchListener{
 | 
			
		||||
    private GameView view;
 | 
			
		||||
    private GameActivity context;
 | 
			
		||||
    private int i = 0;
 | 
			
		||||
    public TouchListener(GameView view) {
 | 
			
		||||
        this.view=view;
 | 
			
		||||
    public TouchListener(GameActivity context) {
 | 
			
		||||
        this.context=context;
 | 
			
		||||
    }
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onTouch(View v, MotionEvent event) {
 | 
			
		||||
@@ -20,30 +22,30 @@ public class TouchListener implements View.OnTouchListener{
 | 
			
		||||
            //Surveille quel bouton de couleur est choisi
 | 
			
		||||
            if (v.getHeight()-v.getHeight()/7-v.getWidth()/16<y && y<v.getHeight()-v.getHeight()/7+v.getWidth()/16){
 | 
			
		||||
                if(v.getWidth()/8-v.getWidth()/15<x && x<v.getWidth()/8+v.getWidth()/15){
 | 
			
		||||
                    this.view.addChoix(0);
 | 
			
		||||
                    this.context.addChoix(0);
 | 
			
		||||
                } else if(v.getWidth()*2/13+v.getWidth()/8-v.getWidth()/15<x && x<v.getWidth()*2/13+v.getWidth()/8+v.getWidth()/15){
 | 
			
		||||
                    this.view.addChoix(1);
 | 
			
		||||
                    if(!this.view.getState()) {
 | 
			
		||||
                    this.context.addChoix(1);
 | 
			
		||||
                    if(!this.context.getState()) {
 | 
			
		||||
                        i++;
 | 
			
		||||
                    }
 | 
			
		||||
                } else if(2*v.getWidth()*2/13+v.getWidth()/8-v.getWidth()/15<x && x<2*v.getWidth()*2/13+v.getWidth()/8+v.getWidth()/15) {
 | 
			
		||||
                    this.view.addChoix(2);
 | 
			
		||||
                    this.context.addChoix(2);
 | 
			
		||||
                } else if(3*v.getWidth()*2/13+v.getWidth()/8-v.getWidth()/15<x && x<3*v.getWidth()*2/13+v.getWidth()/8+v.getWidth()/15){
 | 
			
		||||
                    this.view.addChoix(3);
 | 
			
		||||
                    this.context.addChoix(3);
 | 
			
		||||
                } else if(4*v.getWidth()*2/13+v.getWidth()/8-v.getWidth()/15<x && x<4*v.getWidth()*2/13+v.getWidth()/8+v.getWidth()/15) {
 | 
			
		||||
                    this.view.addChoix(4);
 | 
			
		||||
                    this.context.addChoix(4);
 | 
			
		||||
                } else if(5*v.getWidth()*2/13+v.getWidth()/8-v.getWidth()/15<x && x<5*v.getWidth()*2/13+v.getWidth()/8+v.getWidth()/15){
 | 
			
		||||
                    this.view.addChoix(5);
 | 
			
		||||
                    this.context.addChoix(5);
 | 
			
		||||
                }
 | 
			
		||||
            // 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
 | 
			
		||||
                    this.view.changeState();
 | 
			
		||||
                    this.context.changeState();
 | 
			
		||||
                    i = 0;
 | 
			
		||||
                } else if (v.getWidth()/2-v.getWidth()/13<x && x<v.getWidth()/2+v.getWidth()/13) { // retour
 | 
			
		||||
                    this.view.removePion();
 | 
			
		||||
                    this.context.removePion();
 | 
			
		||||
                } else if (v.getWidth()/2-(v.getWidth()/11)*2-v.getWidth()/13<x && x<v.getWidth()/2-(v.getWidth()/11)*2+v.getWidth()/13) { // annuler
 | 
			
		||||
                    this.view.clearChoix();
 | 
			
		||||
                    this.context.clearChoix();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -25,7 +25,8 @@
 | 
			
		||||
            android:text="Mastermind"
 | 
			
		||||
            android:gravity="center"
 | 
			
		||||
            android:textColor="#eee"
 | 
			
		||||
            android:padding="50dp"
 | 
			
		||||
            android:paddingHorizontal="10dp"
 | 
			
		||||
            android:paddingVertical="40dp"
 | 
			
		||||
            android:textSize="50dp"
 | 
			
		||||
            android:autoSizeMaxTextSize="100dp"
 | 
			
		||||
            android:autoSizeMinTextSize="10dp">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user