MVC
This commit is contained in:
parent
bbeca7dee9
commit
f9d020a741
@ -14,7 +14,7 @@
|
|||||||
android:theme="@style/Theme.MasterMind"
|
android:theme="@style/Theme.MasterMind"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
<activity
|
<activity
|
||||||
android:name=".HotSeatActivity"
|
android:name=".GameActivity"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".SettingsActivity"
|
android:name=".SettingsActivity"
|
||||||
|
@ -8,11 +8,12 @@ import com.example.mastermind.game.Grille;
|
|||||||
import com.example.mastermind.game.Saisie;
|
import com.example.mastermind.game.Saisie;
|
||||||
|
|
||||||
public class HotSeatActivity extends Activity {
|
public class HotSeatActivity extends Activity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
boolean bot = getIntent().getBooleanExtra("bot", false);
|
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() {
|
mHotSeat.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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);
|
HotSeat.putExtra("bot", false);
|
||||||
startActivity(HotSeat);
|
startActivity(HotSeat);
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ public class MainActivity extends Activity {
|
|||||||
mORDI.setOnClickListener(new View.OnClickListener() {
|
mORDI.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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);
|
ordi.putExtra("bot", true);
|
||||||
startActivity(ordi);
|
startActivity(ordi);
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import android.graphics.Color;
|
|||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.example.mastermind.GameActivity;
|
||||||
import com.example.mastermind.R;
|
import com.example.mastermind.R;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -16,29 +17,18 @@ import java.util.LinkedList;
|
|||||||
|
|
||||||
public class GameView extends View {
|
public class GameView extends View {
|
||||||
|
|
||||||
private Integer[] pionsAttaquant;
|
|
||||||
private Integer[] pionsDefenseur;
|
|
||||||
private Integer pionVide;
|
|
||||||
private Saisie saisie;
|
private Saisie saisie;
|
||||||
private Grille grille;
|
private Grille grille;
|
||||||
private boolean bot;
|
|
||||||
private Bot theBot;
|
|
||||||
private Paint circle;
|
private Paint circle;
|
||||||
private boolean state;
|
|
||||||
private Bitmap cancelBtn;
|
private Bitmap cancelBtn;
|
||||||
private Bitmap backBtn;
|
private Bitmap backBtn;
|
||||||
private Bitmap validBtn;
|
private Bitmap validBtn;
|
||||||
public GameView(Context context,Saisie saisie,Grille grille, boolean bot) {
|
public GameView(GameActivity context, Saisie saisie, Grille grille) {
|
||||||
super(context);
|
super(context);
|
||||||
this.saisie=saisie;
|
this.saisie=saisie;
|
||||||
this.grille=grille;
|
this.grille=grille;
|
||||||
this.bot=bot;
|
this.setOnTouchListener(new TouchListener(context));
|
||||||
initpions();
|
|
||||||
this.theBot=new Bot(this.pionsAttaquant, this.pionsDefenseur, this.pionVide);
|
|
||||||
this.setOnTouchListener(new TouchListener(this));
|
|
||||||
//on initialise les collections de pions
|
|
||||||
//state indique true si le joueur soumet une combinaison ou false si elle est noté
|
//state indique true si le joueur soumet une combinaison ou false si elle est noté
|
||||||
this.state=true;
|
|
||||||
this.circle = new Paint();
|
this.circle = new Paint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +36,7 @@ public class GameView extends View {
|
|||||||
protected void onDraw(Canvas canvas){
|
protected void onDraw(Canvas canvas){
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
this.setBackgroundColor(this.getResources().getColor(R.color.grey));
|
this.setBackgroundColor(this.getResources().getColor(R.color.grey));
|
||||||
|
if(this.grille!=null) {
|
||||||
//affichage des anciennes soumissions
|
//affichage des anciennes soumissions
|
||||||
//copie des soumissions
|
//copie des soumissions
|
||||||
LinkedList<Integer> grille = new LinkedList<Integer>();
|
LinkedList<Integer> grille = new LinkedList<Integer>();
|
||||||
@ -53,29 +44,9 @@ public class GameView extends View {
|
|||||||
for (int y = 0; y < 10; y++) {
|
for (int y = 0; y < 10; y++) {
|
||||||
for (int x = 0; x < 4; x++) {
|
for (int x = 0; x < 4; x++) {
|
||||||
this.circle.setColor(grille.pop());
|
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);
|
canvas.drawCircle((x * this.getWidth() / 8 + (this.getWidth() * 21 / 68)), (y * this.getHeight() / 14 + this.getHeight() / 21), this.getWidth() / 17, this.circle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// affichage de la zone de saisie
|
|
||||||
//copie de la zone de saisie
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// affichage des couleurs choisissables
|
|
||||||
//copie des couleurs dispos
|
|
||||||
LinkedList<Integer> couleurs = new LinkedList<Integer>();
|
|
||||||
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>();
|
LinkedList<Integer> notation = new LinkedList<Integer>();
|
||||||
notation.addAll(this.grille.getNotations());
|
notation.addAll(this.grille.getNotations());
|
||||||
for(int y=0; y<10; y++) {
|
for(int y=0; y<10; y++) {
|
||||||
@ -88,20 +59,31 @@ public class GameView extends View {
|
|||||||
canvas.drawCircle((x*this.getWidth()/11+(this.getWidth()*4/5)),(y*this.getHeight()/14+getHeight()/21), this.getWidth()/26, this.circle);
|
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
|
||||||
|
//copie de la zone de saisie
|
||||||
|
Integer[] saisie = this.saisie.getSelection();
|
||||||
|
for (int i=0;i<4;i++){
|
||||||
|
this.circle.setColor(saisie[i]);
|
||||||
|
canvas.drawCircle((i*this.getWidth()/5+this.getWidth()/5),this.getHeight()-this.getHeight()*2/9, this.getWidth()/14, this.circle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// affichage des couleurs choisissables
|
||||||
|
//copie des couleurs dispos
|
||||||
|
LinkedList<Integer> couleurs = new LinkedList<Integer>();
|
||||||
|
couleurs.addAll(this.saisie.getChoix());
|
||||||
|
for (int i=0;i<this.saisie.getChoix().size();i++){
|
||||||
|
this.circle.setColor(couleurs.pop());
|
||||||
|
canvas.drawCircle((i*this.getWidth()*2/13+this.getWidth()/8),this.getHeight()-this.getHeight()/7, this.getWidth()/16, this.circle);
|
||||||
|
}
|
||||||
|
|
||||||
// bouton valider
|
// 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
|
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);
|
canvas.drawBitmap(validBtn, this.getWidth()/2+(this.getWidth()/11)*2-getWidth()/13, this.getHeight()/2+this.getHeight()*2/5, null);
|
||||||
// bouton retour
|
// 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);
|
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);
|
canvas.drawBitmap(backBtn, this.getWidth()/2-getWidth()/13, this.getHeight()/2+this.getHeight()*2/5, null);
|
||||||
// bouton annuler
|
// 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);
|
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);
|
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;
|
options.inJustDecodeBounds = false;
|
||||||
return BitmapFactory.decodeResource(res, resId, options);
|
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.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.example.mastermind.GameActivity;
|
||||||
|
|
||||||
public class TouchListener implements View.OnTouchListener{
|
public class TouchListener implements View.OnTouchListener{
|
||||||
private GameView view;
|
private GameActivity context;
|
||||||
private int i = 0;
|
private int i = 0;
|
||||||
public TouchListener(GameView view) {
|
public TouchListener(GameActivity context) {
|
||||||
this.view=view;
|
this.context=context;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
@ -20,30 +22,30 @@ public class TouchListener implements View.OnTouchListener{
|
|||||||
//Surveille quel bouton de couleur est choisi
|
//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.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){
|
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){
|
} 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);
|
this.context.addChoix(1);
|
||||||
if(!this.view.getState()) {
|
if(!this.context.getState()) {
|
||||||
i++;
|
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) {
|
} 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){
|
} 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) {
|
} 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){
|
} 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é
|
// 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){
|
} 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(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;
|
i = 0;
|
||||||
} else if (v.getWidth()/2-v.getWidth()/13<x && x<v.getWidth()/2+v.getWidth()/13) { // retour
|
} 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
|
} 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:text="Mastermind"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:textColor="#eee"
|
android:textColor="#eee"
|
||||||
android:padding="50dp"
|
android:paddingHorizontal="10dp"
|
||||||
|
android:paddingVertical="40dp"
|
||||||
android:textSize="50dp"
|
android:textSize="50dp"
|
||||||
android:autoSizeMaxTextSize="100dp"
|
android:autoSizeMaxTextSize="100dp"
|
||||||
android:autoSizeMinTextSize="10dp">
|
android:autoSizeMinTextSize="10dp">
|
||||||
|
Loading…
Reference in New Issue
Block a user