demande de la combi gagnante et affichage de la combi en fin de partie
This commit is contained in:
		@@ -18,21 +18,28 @@ public class ChoiceCombi extends Activity  implements SaisieActivity {
 | 
				
			|||||||
        super.onCreate(savedInstanceState);
 | 
					        super.onCreate(savedInstanceState);
 | 
				
			||||||
        int[] tab = getIntent().getIntArrayExtra("pions");
 | 
					        int[] tab = getIntent().getIntArrayExtra("pions");
 | 
				
			||||||
        this.pions=new Integer[6];
 | 
					        this.pions=new Integer[6];
 | 
				
			||||||
        for (int i=0;i<tab.length-1;i++) {
 | 
					        for (int i=0;i<tab.length;i++) {
 | 
				
			||||||
            this.pions[i] = tab[i];
 | 
					            this.pions[i] = tab[i];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        this.saisie=new Saisie();
 | 
					        this.saisie=new Saisie();
 | 
				
			||||||
        this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
 | 
					        this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
 | 
				
			||||||
        this.saisie.setChoix(this.pions);
 | 
					        this.saisie.setChoix(this.pions);
 | 
				
			||||||
        this.view=new GameView(this,this,this.saisie, null);
 | 
					        this.view=new GameView(this,this,this.saisie, null);
 | 
				
			||||||
 | 
					        setContentView(view);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void changeState(){
 | 
					    public void changeState(){
 | 
				
			||||||
 | 
					        if(this.saisie.getSizeSelection()==4) {
 | 
				
			||||||
            Intent returnIntent = new Intent();
 | 
					            Intent returnIntent = new Intent();
 | 
				
			||||||
        returnIntent.putExtra("choix",this.saisie.getSelection());
 | 
					            int[] tabpions=new int[6];
 | 
				
			||||||
        setResult(Activity.RESULT_OK,returnIntent);
 | 
					            for (int i=0;i<this.saisie.getSizeSelection();i++) {
 | 
				
			||||||
 | 
					                tabpions[i] = this.saisie.getSelection()[i];
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            returnIntent.putExtra("choix", this.saisie.getSelection());
 | 
				
			||||||
 | 
					            setResult(Activity.RESULT_OK, returnIntent);
 | 
				
			||||||
            finish();
 | 
					            finish();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void addChoix(int choix){
 | 
					    public void addChoix(int choix){
 | 
				
			||||||
        this.saisie.addSelection(choix);
 | 
					        this.saisie.addSelection(choix);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,6 +15,7 @@ import com.example.mastermind.game.Saisie;
 | 
				
			|||||||
public class GameActivity extends Activity implements SaisieActivity  {
 | 
					public class GameActivity extends Activity implements SaisieActivity  {
 | 
				
			||||||
    private Integer[] pionsAttaquant;
 | 
					    private Integer[] pionsAttaquant;
 | 
				
			||||||
    private Integer[] pionsDefenseur;
 | 
					    private Integer[] pionsDefenseur;
 | 
				
			||||||
 | 
					    private Integer[] combiGagnante;
 | 
				
			||||||
    private Integer pionVide;
 | 
					    private Integer pionVide;
 | 
				
			||||||
    private Saisie saisie;
 | 
					    private Saisie saisie;
 | 
				
			||||||
    private Grille grille;
 | 
					    private Grille grille;
 | 
				
			||||||
@@ -32,8 +33,10 @@ public class GameActivity extends Activity implements SaisieActivity  {
 | 
				
			|||||||
        this.saisie=new Saisie();
 | 
					        this.saisie=new Saisie();
 | 
				
			||||||
        this.grille=new Grille();
 | 
					        this.grille=new Grille();
 | 
				
			||||||
        initpions();
 | 
					        initpions();
 | 
				
			||||||
 | 
					        if (this.bot){
 | 
				
			||||||
            this.theBot=new Bot(this.pionsAttaquant, this.pionsDefenseur, this.pionVide);
 | 
					            this.theBot=new Bot(this.pionsAttaquant, this.pionsDefenseur, this.pionVide);
 | 
				
			||||||
        if(!this.bot){
 | 
					            this.combiGagnante=this.theBot.getCollectionWin();
 | 
				
			||||||
 | 
					        } else if(!this.bot){
 | 
				
			||||||
            Intent choiceCombi = new Intent(this, ChoiceCombi.class);
 | 
					            Intent choiceCombi = new Intent(this, ChoiceCombi.class);
 | 
				
			||||||
            int[] tabpions=new int[6];
 | 
					            int[] tabpions=new int[6];
 | 
				
			||||||
            for (int i=0;i<this.pionsAttaquant.length;i++) {
 | 
					            for (int i=0;i<this.pionsAttaquant.length;i++) {
 | 
				
			||||||
@@ -46,13 +49,28 @@ public class GameActivity extends Activity implements SaisieActivity  {
 | 
				
			|||||||
        setContentView(view);
 | 
					        setContentView(view);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 | 
				
			||||||
 | 
					        super.onActivityResult(requestCode, resultCode, data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (requestCode == 1) {
 | 
				
			||||||
 | 
					            if(resultCode == Activity.RESULT_OK){
 | 
				
			||||||
 | 
					                int[] tab = data.getIntArrayExtra("choix");
 | 
				
			||||||
 | 
					                this.combiGagnante=new Integer[6];
 | 
				
			||||||
 | 
					                for (int i=0;i<tab.length;i++) {
 | 
				
			||||||
 | 
					                    this.combiGagnante[i] = tab[i];
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Change l'état de soumission à notation après qu'une combinaision ai été soumise puis inversement
 | 
					    //Change l'état de soumission à notation après qu'une combinaision ai été soumise puis inversement
 | 
				
			||||||
    public void changeState() {
 | 
					    public void changeState() {
 | 
				
			||||||
        if(!this.bot) {
 | 
					        if(!this.bot) {
 | 
				
			||||||
            if (!this.state) {
 | 
					            if (!this.state) {
 | 
				
			||||||
                this.saisie.setChoix(this.pionsAttaquant);
 | 
					                this.saisie.setChoix(this.pionsAttaquant);
 | 
				
			||||||
                this.grille.addNotation(this.saisie.getSelection());
 | 
					                this.grille.addNotation(this.saisie.getSelection());
 | 
				
			||||||
                victoire();
 | 
					                end();
 | 
				
			||||||
                this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
 | 
					                this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
 | 
				
			||||||
                this.view.invalidate();
 | 
					                this.view.invalidate();
 | 
				
			||||||
                this.state = !this.state;
 | 
					                this.state = !this.state;
 | 
				
			||||||
@@ -69,7 +87,7 @@ public class GameActivity extends Activity implements SaisieActivity  {
 | 
				
			|||||||
            this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
 | 
					            this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
 | 
				
			||||||
            //On fait noter la combinaison au Bot
 | 
					            //On fait noter la combinaison au Bot
 | 
				
			||||||
            this.grille.addNotation(this.theBot.notation((combi)));
 | 
					            this.grille.addNotation(this.theBot.notation((combi)));
 | 
				
			||||||
            victoire();
 | 
					            end();
 | 
				
			||||||
            this.view.invalidate();
 | 
					            this.view.invalidate();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -90,7 +108,7 @@ public class GameActivity extends Activity implements SaisieActivity  {
 | 
				
			|||||||
        this.view.invalidate();
 | 
					        this.view.invalidate();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public boolean victoire (){
 | 
					    public void end (){
 | 
				
			||||||
        Integer[] lastNotation = this.grille.getLastNotation();
 | 
					        Integer[] lastNotation = this.grille.getLastNotation();
 | 
				
			||||||
        int nbWin=0;
 | 
					        int nbWin=0;
 | 
				
			||||||
        for (int i=0;i<4;i++){
 | 
					        for (int i=0;i<4;i++){
 | 
				
			||||||
@@ -100,10 +118,16 @@ public class GameActivity extends Activity implements SaisieActivity  {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        if(nbWin==4) {
 | 
					        if(nbWin==4) {
 | 
				
			||||||
            System.out.println("WIN");
 | 
					            System.out.println("WIN");
 | 
				
			||||||
            return true;
 | 
					            victoire(true);
 | 
				
			||||||
        } else {
 | 
					        } else if (this.grille.getSizeSubs()==10){
 | 
				
			||||||
            System.out.println("LOSE");
 | 
					            System.out.println("LOSE");
 | 
				
			||||||
            return false;
 | 
					            victoire(false);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void victoire(boolean gagne){
 | 
				
			||||||
 | 
					        for (int i=0;i<4;i++){
 | 
				
			||||||
 | 
					            this.saisie.addSelection(this.combiGagnante[i]);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -74,4 +74,8 @@ public class Bot {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        return tabnote;
 | 
					        return tabnote;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Integer[] getCollectionWin(){
 | 
				
			||||||
 | 
					        return this.collectionWin;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,12 +25,13 @@ public class GameView extends View {
 | 
				
			|||||||
    private Bitmap cancelBtn;
 | 
					    private Bitmap cancelBtn;
 | 
				
			||||||
    private Bitmap backBtn;
 | 
					    private Bitmap backBtn;
 | 
				
			||||||
    private Bitmap validBtn;
 | 
					    private Bitmap validBtn;
 | 
				
			||||||
 | 
					    private SaisieActivity activity;
 | 
				
			||||||
    public GameView(Context con, SaisieActivity context, Saisie saisie, Grille grille) {
 | 
					    public GameView(Context con, SaisieActivity context, Saisie saisie, Grille grille) {
 | 
				
			||||||
        super(con);
 | 
					        super(con);
 | 
				
			||||||
 | 
					        this.activity=context;
 | 
				
			||||||
        this.saisie=saisie;
 | 
					        this.saisie=saisie;
 | 
				
			||||||
        this.grille=grille;
 | 
					        this.grille=grille;
 | 
				
			||||||
        this.setOnTouchListener(new TouchListener(context));
 | 
					        this.setOnTouchListener(new TouchListener(context));
 | 
				
			||||||
        //state indique true si le joueur soumet une combinaison ou false si elle est noté
 | 
					 | 
				
			||||||
        this.circle = new Paint();
 | 
					        this.circle = new Paint();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -83,5 +83,8 @@ public class Grille {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        return lastNotation;
 | 
					        return lastNotation;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    public int getSizeSubs(){
 | 
				
			||||||
 | 
					        return this.sizeSubs;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,14 +37,22 @@ public class Saisie {
 | 
				
			|||||||
        this.sizeSelection=0;
 | 
					        this.sizeSelection=0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    //addSelection permet d'ajouter un pion à la zone de saisie
 | 
					    //addSelection permet d'ajouter un pion par index à la zone de saisie
 | 
				
			||||||
    public void addSelection(int indexcolor){
 | 
					    public void addSelection(int indexcolor){
 | 
				
			||||||
        //On vérifie qu'il n'y a pas déjà 4 pions
 | 
					        //On vérifie qu'il n'y a pas déjà 4 pions
 | 
				
			||||||
        if (this.sizeSelection<4){
 | 
					        if (this.sizeSelection<4){
 | 
				
			||||||
            this.selection.set(this.sizeSelection,this.choix.get(indexcolor));
 | 
					            this.selection.set(this.sizeSelection,this.choix.get(indexcolor));
 | 
				
			||||||
            this.sizeSelection+=1;
 | 
					            this.sizeSelection+=1;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //addSelection permet d'ajouter un pion par index à la zone de saisie
 | 
				
			||||||
 | 
					    public void addSelection(Integer color){
 | 
				
			||||||
 | 
					        //On vérifie qu'il n'y a pas déjà 4 pions
 | 
				
			||||||
 | 
					        if (this.sizeSelection<4){
 | 
				
			||||||
 | 
					            this.selection.set(this.sizeSelection,color);
 | 
				
			||||||
 | 
					            this.sizeSelection++;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void removeSelection(Integer pionVide) {
 | 
					    public void removeSelection(Integer pionVide) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user