Compare commits
No commits in common. "master" and "miseEnPlaceBot" have entirely different histories.
master
...
miseEnPlac
Binary file not shown.
@ -14,7 +14,7 @@
|
||||
android:theme="@style/Theme.MasterMind"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".GameActivity"
|
||||
android:name=".HotSeatActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".SettingsActivity"
|
||||
@ -25,12 +25,6 @@
|
||||
android:name="android.app.lib_name"
|
||||
android:value="" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".RulesActivity"
|
||||
android:exported="false"/>
|
||||
<activity
|
||||
android:name=".ChoiceCombi"
|
||||
android:exported="false"/>
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
|
@ -1,78 +0,0 @@
|
||||
package com.example.mastermind;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.example.mastermind.game.GameView;
|
||||
import com.example.mastermind.game.Saisie;
|
||||
|
||||
public class ChoiceCombi extends Activity implements SaisieActivity {
|
||||
private Saisie saisie;
|
||||
private Integer[] combiGagnante;
|
||||
private Integer[] pions;
|
||||
private boolean emptyPion;
|
||||
private View view;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
int[] tab = getIntent().getIntArrayExtra("pions");
|
||||
this.emptyPion = getIntent().getBooleanExtra("emptyPion", false);
|
||||
if(emptyPion) {
|
||||
this.pions=new Integer[7];
|
||||
} else {
|
||||
this.pions=new Integer[6];
|
||||
}
|
||||
for (int i=0;i<tab.length;i++) {
|
||||
this.pions[i] = tab[i];
|
||||
}
|
||||
this.saisie=new Saisie();
|
||||
this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
|
||||
this.saisie.setChoix(this.pions);
|
||||
this.view=new GameView(this,this,this.saisie, null);
|
||||
this.view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
setContentView(R.layout.activity_game);
|
||||
LinearLayout linearLayout = findViewById(R.id.layout);
|
||||
linearLayout.addView(this.view);
|
||||
}
|
||||
|
||||
public void changeState(){
|
||||
if(this.saisie.getSizeSelection()==4) {
|
||||
Intent returnIntent = new Intent();
|
||||
int[] tabpions;
|
||||
if(emptyPion) {
|
||||
tabpions=new int[7];
|
||||
} else {
|
||||
tabpions=new int[6];
|
||||
}
|
||||
for (int i=0;i<this.saisie.getSizeSelection();i++) {
|
||||
tabpions[i] = this.saisie.getSelection()[i];
|
||||
}
|
||||
returnIntent.putExtra("choix", tabpions);
|
||||
setResult(Activity.RESULT_OK, returnIntent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
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 int getNbrPion() {
|
||||
return this.saisie.getSizeChoix();
|
||||
}
|
||||
}
|
@ -1,220 +0,0 @@
|
||||
package com.example.mastermind;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.mastermind.end.EndView;
|
||||
import com.example.mastermind.game.Bot;
|
||||
import com.example.mastermind.game.GameView;
|
||||
import com.example.mastermind.game.Grille;
|
||||
import com.example.mastermind.game.Saisie;
|
||||
import com.example.mastermind.game.TapListener;
|
||||
|
||||
public class GameActivity extends Activity implements SaisieActivity {
|
||||
private Integer[] pionsAttaquant;
|
||||
private Integer[] pionsDefenseur;
|
||||
private Integer[] combiGagnante;
|
||||
private Integer pionVide;
|
||||
private Saisie saisie;
|
||||
private Grille grille;
|
||||
private boolean bot;
|
||||
private Bot theBot;
|
||||
private boolean emptyPion;
|
||||
private boolean state;
|
||||
private View view;
|
||||
private LinearLayout rootView;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.bot = getIntent().getBooleanExtra("bot", false);
|
||||
this.emptyPion = getIntent().getBooleanExtra("pionVide", false);
|
||||
this.state=true;
|
||||
this.saisie=new Saisie();
|
||||
this.grille=new Grille();
|
||||
initpions();
|
||||
if (this.bot){
|
||||
this.theBot=new Bot(this.pionsAttaquant, this.pionsDefenseur, this.pionVide);
|
||||
this.combiGagnante=this.theBot.getCollectionWin();
|
||||
} else if(!this.bot){
|
||||
Intent choiceCombi = new Intent(this, ChoiceCombi.class);
|
||||
int[] tabpions;
|
||||
if(emptyPion) {
|
||||
tabpions=new int[7];
|
||||
} else {
|
||||
tabpions=new int[6];
|
||||
}
|
||||
for (int i=0;i<this.pionsAttaquant.length;i++) {
|
||||
tabpions[i] = this.pionsAttaquant[i];
|
||||
}
|
||||
choiceCombi.putExtra("emptyPion", emptyPion);
|
||||
choiceCombi.putExtra("pions", tabpions);
|
||||
startActivityForResult(choiceCombi, 1);
|
||||
}
|
||||
this.view=new GameView(this,this,this.saisie, this.grille);
|
||||
this.view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
setContentView(R.layout.activity_game);
|
||||
this.rootView = findViewById(R.id.layout);
|
||||
this.rootView.addView(this.view);
|
||||
this.rootView.setOnTouchListener(new TapListener(this));
|
||||
}
|
||||
|
||||
@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");
|
||||
if(emptyPion) {
|
||||
this.combiGagnante=new Integer[7];
|
||||
} else {
|
||||
this.combiGagnante=new Integer[6];
|
||||
}
|
||||
for (int i=0;i<tab.length;i++) {
|
||||
this.combiGagnante[i] = tab[i];
|
||||
}
|
||||
}
|
||||
if(resultCode == Activity.RESULT_CANCELED) {
|
||||
this.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getNbrPion() {
|
||||
return this.saisie.getSizeChoix();
|
||||
}
|
||||
|
||||
//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());
|
||||
if(end()){return;}
|
||||
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)));
|
||||
if(end()){return;}
|
||||
this.view.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
//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 end (){
|
||||
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");
|
||||
victoire(true);
|
||||
return true;
|
||||
} else if (this.grille.getSizeSubs()==10){
|
||||
System.out.println("LOSE");
|
||||
victoire(false);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void victoire(boolean gagne){
|
||||
for (int i=0;i<4;i++){
|
||||
this.saisie.addSelection(this.combiGagnante[i]);
|
||||
}
|
||||
EndView lastview=new EndView(this, this.grille, this.combiGagnante, this.rootView);
|
||||
this.view=lastview;
|
||||
this.rootView.removeAllViews();
|
||||
this.view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
this.view.setBackgroundColor(this.getResources().getColor(R.color.grey));
|
||||
this.rootView.addView(this.view);
|
||||
|
||||
TextView textView = new TextView(this);
|
||||
textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
textView.setGravity(Gravity.CENTER);
|
||||
if (gagne){
|
||||
textView.setText("Victoire de l'attaquant en "+this.grille.getSizeSubs()+" coups");
|
||||
} else {
|
||||
textView.setText("Victoire du défenseur");
|
||||
}
|
||||
this.rootView.addView(textView);
|
||||
System.out.println(textView.getX() + " : " + textView.getY());
|
||||
this.rootView.invalidate();
|
||||
}
|
||||
|
||||
//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
|
||||
if(emptyPion) {
|
||||
this.pionsAttaquant = new Integer[7];
|
||||
} else {
|
||||
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);
|
||||
if(emptyPion) {
|
||||
this.pionsAttaquant[6]=this.getResources().getColor(R.color.vide);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.example.mastermind;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.example.mastermind.game.GameView;
|
||||
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);
|
||||
setContentView(new GameView(this, new Saisie(), new Grille()));
|
||||
}
|
||||
}
|
@ -10,8 +10,7 @@ public class MainActivity extends Activity {
|
||||
private Button mHotSeat;
|
||||
private Button mORDI;
|
||||
private Button mSettings;
|
||||
private Button mRules;
|
||||
private boolean pionV;
|
||||
//private Button mRules;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -20,47 +19,34 @@ public class MainActivity extends Activity {
|
||||
mHotSeat = findViewById(R.id.HotSeat);
|
||||
mORDI = findViewById(R.id.ORDI);
|
||||
mSettings = findViewById(R.id.Settings);
|
||||
mRules = findViewById(R.id.Rules);
|
||||
//mRules = findViewById(R.id.Rules);
|
||||
mHotSeat.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent HotSeat = new Intent(MainActivity.this, GameActivity.class);
|
||||
HotSeat.putExtra("bot", false);
|
||||
HotSeat.putExtra("pionVide", pionV);
|
||||
startActivity(HotSeat);
|
||||
Intent tp1Intent = new Intent(MainActivity.this, HotSeatActivity.class);
|
||||
startActivity(tp1Intent);
|
||||
}
|
||||
});
|
||||
mORDI.setOnClickListener(new View.OnClickListener() {
|
||||
/*mORDI.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent ordi = new Intent(MainActivity.this, GameActivity.class);
|
||||
ordi.putExtra("bot", true);
|
||||
ordi.putExtra("pionVide", pionV);
|
||||
startActivity(ordi);
|
||||
Intent tp2Intent = new Intent(MainActivity.this, ORDI.class);
|
||||
startActivity(tp2Intent);
|
||||
}
|
||||
});
|
||||
});*/
|
||||
mSettings.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent settings = new Intent(MainActivity.this, SettingsActivity.class);
|
||||
startActivityForResult(settings, 2);
|
||||
Intent tp3Intent = new Intent(MainActivity.this, SettingsActivity.class);
|
||||
startActivity(tp3Intent);
|
||||
}
|
||||
});
|
||||
mRules.setOnClickListener(new View.OnClickListener() {
|
||||
/*mTP4.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent rules = new Intent(MainActivity.this, RulesActivity.class);
|
||||
startActivity(rules);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if(requestCode == 2) {
|
||||
pionV = data.getBooleanExtra("pionV", false);
|
||||
Intent tp4Intent = new Intent(MainActivity.this, TP4.class);
|
||||
startActivity(tp4Intent);
|
||||
}
|
||||
});*/
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.example.mastermind;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class RulesActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle saveInstanceState) {
|
||||
super.onCreate(saveInstanceState);
|
||||
setContentView(R.layout.activity_rules);
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.example.mastermind;
|
||||
|
||||
public interface SaisieActivity {
|
||||
public void addChoix(int index);
|
||||
|
||||
void changeState();
|
||||
|
||||
void removePion();
|
||||
|
||||
void clearChoix();
|
||||
|
||||
int getNbrPion();
|
||||
}
|
||||
|
@ -1,44 +1,33 @@
|
||||
package com.example.mastermind;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.Switch;
|
||||
|
||||
public class SettingsActivity extends Activity {
|
||||
private Button mButton;
|
||||
private Switch mSwitch;
|
||||
private boolean pionV;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.settings_activity);
|
||||
if (savedInstanceState == null) {
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.settings, new SettingsFragment())
|
||||
.commit();
|
||||
}
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
mButton = findViewById(R.id.backButton);
|
||||
mSwitch = findViewById(R.id.switchPion);
|
||||
|
||||
mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
public static class SettingsFragment extends PreferenceFragmentCompat {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if(isChecked) {
|
||||
pionV = true;
|
||||
} else {
|
||||
pionV = false;
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
setPreferencesFromResource(R.xml.root_preferences, rootKey);
|
||||
}
|
||||
}
|
||||
});
|
||||
mButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("pionV", pionV);
|
||||
setResult(2, intent);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
package com.example.mastermind.end;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.example.mastermind.GameActivity;
|
||||
import com.example.mastermind.R;
|
||||
import com.example.mastermind.SaisieActivity;
|
||||
import com.example.mastermind.game.Grille;
|
||||
import com.example.mastermind.game.Saisie;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class EndView extends View {
|
||||
|
||||
private Integer[] combiWin;
|
||||
private Grille grille;
|
||||
private Paint circle;
|
||||
private int nbcoups;
|
||||
private LinearLayout rootView;
|
||||
public EndView(Context context, Grille grille, Integer[] combiWin, LinearLayout rootView) {
|
||||
super(context);
|
||||
this.combiWin=combiWin;
|
||||
this.grille=grille;
|
||||
this.circle = new Paint();
|
||||
this.rootView = rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas){
|
||||
super.onDraw(canvas);
|
||||
//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.rootView.getHeight() / 14 + this.rootView.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.rootView.getHeight()/14+this.rootView.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.rootView.getHeight()/14+this.rootView.getHeight()/21), this.getWidth()/26, this.circle);
|
||||
}
|
||||
}
|
||||
// affichage de la zone de saisie
|
||||
//copie de la zone de saisie
|
||||
for (int i=0;i<4;i++){
|
||||
this.circle.setColor(this.combiWin[i]);
|
||||
canvas.drawCircle((i*this.getWidth()/5+this.getWidth()/5),this.rootView.getHeight()*7/9, this.getWidth()/14, this.circle);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
|
||||
int desiredWidth = this.getWidth();
|
||||
int desiredHeight = this.rootView.getHeight()*7/9+this.getWidth()/5+this.rootView.getWidth()/7;
|
||||
|
||||
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
|
||||
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
|
||||
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
||||
|
||||
int width;
|
||||
int height;
|
||||
|
||||
if (widthMode == MeasureSpec.EXACTLY) {
|
||||
width = widthSize;
|
||||
} else if (widthMode == MeasureSpec.AT_MOST) {
|
||||
width = Math.min(desiredWidth, widthSize);
|
||||
} else {
|
||||
width = desiredWidth;
|
||||
}
|
||||
|
||||
if (heightMode == MeasureSpec.EXACTLY) {
|
||||
height = heightSize;
|
||||
} else if (heightMode == MeasureSpec.AT_MOST) {
|
||||
height = Math.min(desiredHeight, heightSize);
|
||||
} else {
|
||||
height = desiredHeight;
|
||||
}
|
||||
setMeasuredDimension(width, height);
|
||||
System.out.println("Voulu : "+width+" par "+height);
|
||||
}
|
||||
|
||||
}
|
@ -19,65 +19,42 @@ public class Bot {
|
||||
private Integer pionVide;
|
||||
private Integer[] pionsNotation;
|
||||
|
||||
public Bot(Integer[] pionsAutorisés, Integer[] pionsNotation, Integer pionVide){
|
||||
public Bot(Collection<Integer> pionsAutorisés, Integer[] pionsNotation, Integer pionVide){
|
||||
this.collectionWin = new Integer[4];
|
||||
this.pionVide=pionVide;
|
||||
this.pionsNotation=pionsNotation;
|
||||
generationCombiWin(pionsAutorisés);
|
||||
}
|
||||
|
||||
protected void generationCombiWin(Integer[] pions){
|
||||
protected void generationCombiWin(Collection<Integer> pions){
|
||||
Random rand = new Random();
|
||||
int nbPions = pions.length;
|
||||
int nbPions = pions.size();
|
||||
Integer[] tabPions=(Integer[]) pions.toArray();
|
||||
for (int i=0;i<4;i++){
|
||||
this.collectionWin[i]=pions[rand.nextInt(nbPions)];
|
||||
this.collectionWin[i]=tabPions[rand.nextInt(nbPions)];
|
||||
}
|
||||
}
|
||||
|
||||
public Integer[] notation(Integer[] soumission){
|
||||
LinkedList<Integer> note=new LinkedList<>();
|
||||
Integer[] copyCombi = new Integer[4];
|
||||
System.arraycopy(this.collectionWin, 0, copyCombi, 0,4);
|
||||
|
||||
//noirs
|
||||
public Collection<Integer> notation(Integer[] soumission){
|
||||
Collection<Integer> note=new LinkedList<Integer>();
|
||||
for(int i=0; i<4;i++) {
|
||||
if (copyCombi[i]==soumission[i]) {
|
||||
if (this.collectionWin[i] == soumission[i]) {
|
||||
note.add(this.pionsNotation[1]);
|
||||
copyCombi[i]=null;
|
||||
soumission[i]=null;
|
||||
}
|
||||
}
|
||||
|
||||
//blancs
|
||||
//On crée une copie de la combinaison gagnante pour la modifier et éviter la fausse répétition de pions blancs
|
||||
Integer[] copyCombi = this.collectionWin;
|
||||
for(int i=0; i<4;i++) {
|
||||
if(soumission[i]!=null){
|
||||
for (int y=0;y<4;y++){
|
||||
if (soumission[i]==copyCombi[y]) {
|
||||
for (int y=0; y<4;y++) {
|
||||
if (i!=y){
|
||||
if (this.collectionWin[y] == soumission[i]){
|
||||
note.add(this.pionsNotation[0]);
|
||||
copyCombi[y] = null;
|
||||
soumission[i] = null;
|
||||
System.out.println(i+" "+y);
|
||||
break;
|
||||
this.collectionWin[y]=null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// On complête avec des cases vides
|
||||
while (note.size()<4){
|
||||
note.addLast(this.pionVide);
|
||||
}
|
||||
|
||||
Integer[] tabnote = new Integer[4];
|
||||
//fill tab
|
||||
Random rand = new Random();
|
||||
for(int i=0; i<4;i++) {
|
||||
tabnote[i]=note.get(i);
|
||||
}
|
||||
return tabnote;
|
||||
}
|
||||
|
||||
public Integer[] getCollectionWin(){
|
||||
return this.collectionWin;
|
||||
return note;
|
||||
}
|
||||
}
|
||||
|
@ -1,72 +1,60 @@
|
||||
package com.example.mastermind.game;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.view.View;
|
||||
|
||||
import com.example.mastermind.GameActivity;
|
||||
import com.example.mastermind.R;
|
||||
import com.example.mastermind.SaisieActivity;
|
||||
|
||||
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;
|
||||
private Bitmap cancelBtn;
|
||||
private Bitmap backBtn;
|
||||
private Bitmap validBtn;
|
||||
private SaisieActivity activity;
|
||||
public GameView(Context con, SaisieActivity context, Saisie saisie, Grille grille) {
|
||||
super(con);
|
||||
this.activity=context;
|
||||
private boolean state;
|
||||
public GameView(Context context,Saisie saisie,Grille grille) {
|
||||
super(context);
|
||||
this.saisie=saisie;
|
||||
this.grille=grille;
|
||||
this.setOnTouchListener(new TouchListener(context));
|
||||
this.setOnTouchListener(new TouchListener(this));
|
||||
//on initialise les collections de pions
|
||||
initpions();
|
||||
//state indique true si le joueur soumet une combinaison ou false si elle est noté
|
||||
this.state=true;
|
||||
this.circle = new Paint();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas){
|
||||
super.onDraw(canvas);
|
||||
if(this.grille!=null) {
|
||||
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++) {
|
||||
System.out.println(grille.size());
|
||||
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);
|
||||
}
|
||||
//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);
|
||||
}
|
||||
}
|
||||
// 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]);
|
||||
LinkedList<Integer> saisie = new LinkedList<Integer>();
|
||||
saisie.addAll(this.saisie.getSelection());
|
||||
for (int i=0;i<this.saisie.getSelection().size();i++){
|
||||
this.circle.setColor(saisie.pop());
|
||||
//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);
|
||||
}
|
||||
|
||||
@ -74,51 +62,71 @@ public class GameView extends View {
|
||||
//copie des couleurs dispos
|
||||
LinkedList<Integer> couleurs = new LinkedList<Integer>();
|
||||
couleurs.addAll(this.saisie.getChoix());
|
||||
if(this.saisie.getChoix().size() == 6 || this.saisie.getChoix().size() == 2) {
|
||||
for (int i = 0; i < this.saisie.getChoix().size(); i++) {
|
||||
System.out.println(couleurs.size());
|
||||
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);
|
||||
//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);
|
||||
}
|
||||
} else if(this.saisie.getChoix().size() == 7) {
|
||||
for (int i = 0; i < this.saisie.getChoix().size(); i++) {
|
||||
this.circle.setColor(couleurs.pop());
|
||||
canvas.drawCircle((i * this.getWidth() * 2 / 14 + this.getWidth() / 14), this.getHeight() - this.getHeight() / 7, this.getWidth() / 19, this.circle);
|
||||
}
|
||||
}
|
||||
|
||||
// bouton valider
|
||||
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);
|
||||
//TODO: ajout des colonnes de notation
|
||||
//TODO: ajout des boutons
|
||||
//Test de bouton valider
|
||||
this.circle.setColor(this.getResources().getColor(R.color.green));
|
||||
canvas.drawCircle((this.getWidth()/2),this.getHeight()-this.getHeight()/16, this.getWidth()/13, this.circle);
|
||||
// bouton retour
|
||||
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
|
||||
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);
|
||||
/* this.circle.setColor(this.getResources().getColor(R.color.blue));
|
||||
canvas.drawCircle((this.getWidth()/2), this.getHeight()-this.getHeight()/16, this.getWidth()/13, this.circle);*/
|
||||
}
|
||||
|
||||
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
|
||||
final int height = options.outHeight;
|
||||
final int width = options.outWidth;
|
||||
int inSampleSize = 1;
|
||||
|
||||
if (height > reqHeight || width > reqWidth) {
|
||||
final int halfHeight = height / 2;
|
||||
final int halfWidth = width / 2;
|
||||
|
||||
while ((halfHeight / inSampleSize) >= reqHeight && (halfWidth / inSampleSize) >= reqWidth) {
|
||||
inSampleSize *= 3;
|
||||
//Change l'état de soumission à notation après qu'une combinaision ai été soumise puis inversement
|
||||
public void changeState() {
|
||||
if (this.saisie.getSizeSelection() == 4) {
|
||||
//partie à décommenter pour acceder à la notation
|
||||
/*this.state = !this.state;
|
||||
if (this.state) {
|
||||
this.saisie.setChoix(this.pionsAttaquant);
|
||||
} else if (!this.state) {
|
||||
this.saisie.setChoix(this.pionsDefenseur);
|
||||
}*/
|
||||
this.grille.addSoumission(this.saisie.getSelection());
|
||||
this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
|
||||
this.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
return inSampleSize;
|
||||
//ajoute une nouvelle couleur pour la séléction à soumettre
|
||||
public void addChoix(int choix){
|
||||
this.saisie.addSelection(choix);
|
||||
this.invalidate();
|
||||
}
|
||||
public Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int width, int height) {
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeResource(res, resId, options);
|
||||
options.inSampleSize = calculateInSampleSize(options, width, height);
|
||||
options.inJustDecodeBounds = false;
|
||||
return BitmapFactory.decodeResource(res, resId, options);
|
||||
//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.pionsPasPlaces = new LinkedList<Integer>();
|
||||
for (int i=0;i<4;i++){
|
||||
this.pionsPasPlaces.add(this.getResources().getColor(R.color.pionVide));
|
||||
}
|
||||
|
||||
//Le défenseur a des pions noirs et blancs
|
||||
this.pionsDefenseur = new LinkedList<Integer>();
|
||||
this.pionsDefenseur.add(this.getResources().getColor(R.color.white));
|
||||
this.pionsDefenseur.add(this.getResources().getColor(R.color.black));
|
||||
|
||||
//L'attaquant a des pions de couleurs
|
||||
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.setChoix(this.pionsAttaquant);
|
||||
saisie.initSelection(this.getResources().getColor(R.color.pionVide));
|
||||
|
||||
// on rempli la grille de cases grises
|
||||
grille.initGrille(this.pionsPasPlaces);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import java.util.LinkedList;
|
||||
représente la grille de jeu à savoir la liste des soumissions ainsi que leur notation
|
||||
*/
|
||||
public class Grille {
|
||||
private Integer pionVide;
|
||||
//sizeSubs indique le nombre de soumissions dans la grille. Il permet de limiter ce nombre à 10
|
||||
private int sizeSubs;
|
||||
// soumission représente la liste des soumissions réalisées ainsi que des cases grises pour compléter la grille
|
||||
@ -24,48 +23,38 @@ public class Grille {
|
||||
}
|
||||
|
||||
// Méthode permettant d'ajouter une soumission
|
||||
public void addSoumission(Integer[] newSub){
|
||||
public void addSoumission(LinkedList<Integer> newSub){
|
||||
//le nombre de soumissions ne doit pas dépasser 10
|
||||
if (this.sizeSubs<10) {
|
||||
for (int i=0; i<4; i++) {
|
||||
//On retire une ligne vide en haut pour remonter l'affichage
|
||||
this.soumissions.remove(0);
|
||||
this.notations.remove(0);
|
||||
//On ajoute ensuite une deriere ligne qui correspond à la nouvelle soumission
|
||||
this.soumissions.addLast(newSub[i]);
|
||||
//Et une ligne vide pour les notations
|
||||
this.notations.addLast(this.pionVide);
|
||||
|
||||
this.soumissions.addLast(newSub.poll());
|
||||
}
|
||||
this.sizeSubs += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Méthode qui permet d'initialiser la grille vide
|
||||
public void initGrille(Integer pionVide){
|
||||
this.pionVide=pionVide;
|
||||
public void initGrille(Collection<Integer> SubToCopy){
|
||||
//On réécupère une ligne de la couleur qui correspond à l'absence de pion et on remplit la grille avec (soumissions et notations
|
||||
for(int i=0;i<10;i++){
|
||||
for(int y=0;y<4;y++) {
|
||||
this.soumissions.add(pionVide);
|
||||
this.notations.add(pionVide);
|
||||
}
|
||||
this.soumissions.addAll(SubToCopy);
|
||||
this.notations.addAll(SubToCopy);
|
||||
}
|
||||
// Au début il n'y a pas de soumission
|
||||
this.sizeSubs=0;
|
||||
}
|
||||
|
||||
// Méthode qui permet d'ajouter des notations comme pour les soumissions
|
||||
public void addNotation(Integer[] newNot){
|
||||
public void addNotation(LinkedList<Integer> newNot){
|
||||
for (int i=0; i<4; i++) {
|
||||
//On retire la derniere ligne vide
|
||||
this.notations.removeLast();
|
||||
//On retire une ligne vide en haut pour remonter l'affichage
|
||||
this.notations.remove(0);
|
||||
//On ajoute ensuite une deriere ligne qui correspond à la nouvelle soumission
|
||||
this.notations.addLast(newNot.poll());
|
||||
}
|
||||
for (int i=0; i<4; i++) {
|
||||
//On ajoute ensuite une deriere ligne qui correspond à la nouvelle note
|
||||
this.notations.addLast(newNot[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//getters des soumissions et notations
|
||||
@ -76,15 +65,5 @@ public class Grille {
|
||||
return this.notations;
|
||||
}
|
||||
|
||||
public Integer[] getLastNotation(){
|
||||
Integer[] lastNotation = new Integer[4];
|
||||
for (int i=0;i<4;i++){
|
||||
lastNotation[i]=this.notations.get(this.notations.size()-i-1);
|
||||
}
|
||||
return lastNotation;
|
||||
}
|
||||
public int getSizeSubs(){
|
||||
return this.sizeSubs;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,39 +28,23 @@ public class Saisie {
|
||||
// getters et setters
|
||||
|
||||
//récupère la couleur d'un pion vide pour remplir la zone de saisie avec
|
||||
public void initSelection(Integer pionVide){
|
||||
public void initSelection(Integer chosenColors){
|
||||
this.selection.removeAll(this.selection);
|
||||
for (int i=0;i<4;i++){
|
||||
this.selection.add(pionVide);
|
||||
this.selection.add(chosenColors);
|
||||
}
|
||||
//au début la zone de séléction est vide
|
||||
this.sizeSelection=0;
|
||||
|
||||
}
|
||||
//addSelection permet d'ajouter un pion par index à la zone de saisie
|
||||
public void addSelection(int indexcolor){
|
||||
//On vérifie qu'il n'y a pas déjà 4 pions
|
||||
if (this.sizeSelection<4&&this.choix.size()>indexcolor){
|
||||
this.selection.set(this.sizeSelection,this.choix.get(indexcolor));
|
||||
this.sizeSelection+=1;
|
||||
}
|
||||
}
|
||||
|
||||
//addSelection permet d'ajouter un pion par index à la zone de saisie
|
||||
public void addSelection(Integer color){
|
||||
//addSelection permet d'ajouter un pion à la zone de saisie
|
||||
public void addSelection(Integer chosenColors){
|
||||
//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++;
|
||||
}
|
||||
this.selection.set(this.sizeSelection,this.choix.get(chosenColors));
|
||||
this.sizeSelection+=1;
|
||||
}
|
||||
|
||||
public void removeSelection(Integer pionVide) {
|
||||
if(this.sizeSelection>0) {
|
||||
this.selection.remove(this.sizeSelection-1);
|
||||
this.selection.add(pionVide);
|
||||
this.sizeSelection--;
|
||||
}
|
||||
}
|
||||
|
||||
public int getSizeSelection(){
|
||||
@ -72,23 +56,13 @@ public class Saisie {
|
||||
}
|
||||
|
||||
//Méthode qui permet depuis GameView de changer la liste des choix de couleur en fonction de l'état de la partie
|
||||
public void setChoix(Integer[] colorsSelected){
|
||||
public void setChoix(Collection<Integer> colorsSelected){
|
||||
this.choix.removeAll(this.choix);
|
||||
for (int i=0;i<colorsSelected.length;i++){
|
||||
this.choix.add(colorsSelected[i]);
|
||||
}
|
||||
this.choix.addAll(colorsSelected);
|
||||
}
|
||||
|
||||
public int getSizeChoix() {
|
||||
return this.choix.size();
|
||||
}
|
||||
|
||||
public Integer[] getSelection(){
|
||||
Integer[] selectiontab=new Integer[4];
|
||||
for (int i=0;i<this.selection.size();i++){
|
||||
selectiontab[i]=this.selection.get(i);
|
||||
}
|
||||
return selectiontab;
|
||||
public LinkedList<Integer> getSelection(){
|
||||
return this.selection;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
package com.example.mastermind.game;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import com.example.mastermind.GameActivity;
|
||||
import com.example.mastermind.SaisieActivity;
|
||||
|
||||
public class TapListener implements View.OnTouchListener{
|
||||
private Activity context;
|
||||
public TapListener(Activity context) {
|
||||
this.context=context;
|
||||
}
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
int action = event.getActionMasked();
|
||||
|
||||
if (action == MotionEvent.ACTION_UP) {
|
||||
this.context.finish();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -3,13 +3,10 @@ package com.example.mastermind.game;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import com.example.mastermind.GameActivity;
|
||||
import com.example.mastermind.SaisieActivity;
|
||||
|
||||
public class TouchListener implements View.OnTouchListener{
|
||||
private SaisieActivity context;
|
||||
public TouchListener(SaisieActivity context) {
|
||||
this.context=context;
|
||||
private GameView view;
|
||||
public TouchListener(GameView view) {
|
||||
this.view=view;
|
||||
}
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
@ -21,47 +18,22 @@ 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(this.context.getNbrPion() == 6 || this.context.getNbrPion() == 2) {
|
||||
if (v.getWidth() / 8 - v.getWidth() / 15 < x && x < v.getWidth() / 8 + v.getWidth() / 15) {
|
||||
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.context.addChoix(1);
|
||||
} 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.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.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.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.context.addChoix(5);
|
||||
}
|
||||
} else if(this.context.getNbrPion() == 7) {
|
||||
if (v.getWidth() / 8 - v.getWidth() / 15 < x && x < v.getWidth() / 8 + v.getWidth() / 15) {
|
||||
this.context.addChoix(0);
|
||||
} else if (v.getWidth() * 2 / 14 + v.getWidth() / 14 - v.getWidth() / 18 < x && x < v.getWidth() * 2 / 14 + v.getWidth() / 14 + v.getWidth() / 18) {
|
||||
this.context.addChoix(1);
|
||||
} else if (2 * v.getWidth() * 2 / 14 + v.getWidth() / 14 - v.getWidth() / 18 < x && x < 2 * v.getWidth() * 2 / 14 + v.getWidth() / 14 + v.getWidth() / 18) {
|
||||
this.context.addChoix(2);
|
||||
} else if (3 * v.getWidth() * 2 / 14 + v.getWidth() / 14 - v.getWidth() / 18 < x && x < 3 * v.getWidth() * 2 / 14 + v.getWidth() / 14 + v.getWidth() / 18) {
|
||||
this.context.addChoix(3);
|
||||
} else if (4 * v.getWidth() * 2 / 14 + v.getWidth() / 14 - v.getWidth() / 18 < x && x < 4 * v.getWidth() * 2 / 14 + v.getWidth() / 14 + v.getWidth() / 18) {
|
||||
this.context.addChoix(4);
|
||||
} else if (5 * v.getWidth() * 2 / 14 + v.getWidth() / 14 - v.getWidth() / 18 < x && x < 5 * v.getWidth() * 2 / 14 + v.getWidth() / 14 + v.getWidth() / 18) {
|
||||
this.context.addChoix(5);
|
||||
} else if(6 * v.getWidth() * 2 / 14 + v.getWidth() / 14 - v.getWidth() / 18 < x && x < 6 * v.getWidth() * 2 / 14 + v.getWidth() / 14 + v.getWidth() / 18) {
|
||||
this.context.addChoix(6);
|
||||
}
|
||||
}
|
||||
|
||||
// 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.context.changeState();
|
||||
} else if (v.getWidth()/2-v.getWidth()/13<x && x<v.getWidth()/2+v.getWidth()/13) { // retour
|
||||
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.context.clearChoix();
|
||||
if(v.getWidth()/8-v.getWidth()/15<x && x<v.getWidth()/8+v.getWidth()/15){
|
||||
this.view.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);
|
||||
} 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);
|
||||
} 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);
|
||||
} 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);
|
||||
} 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);
|
||||
}
|
||||
// surveille si un bouton de controlle est cliqué (ici seule la soumission est gérée)
|
||||
} else if (v.getHeight()-v.getWidth()/9-v.getWidth()/10<y && y<v.getHeight()-v.getWidth()/9+v.getWidth()/10){
|
||||
this.view.changeState();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 35 KiB |
Binary file not shown.
Before Width: | Height: | Size: 37 KiB |
Binary file not shown.
Before Width: | Height: | Size: 31 KiB |
@ -1,11 +0,0 @@
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/grey"
|
||||
tools:context=".GameActivity"
|
||||
android:orientation="vertical">
|
||||
|
||||
</LinearLayout>
|
@ -25,8 +25,7 @@
|
||||
android:text="Mastermind"
|
||||
android:gravity="center"
|
||||
android:textColor="#eee"
|
||||
android:paddingHorizontal="10dp"
|
||||
android:paddingVertical="40dp"
|
||||
android:padding="50dp"
|
||||
android:textSize="50dp"
|
||||
android:autoSizeMaxTextSize="100dp"
|
||||
android:autoSizeMinTextSize="10dp">
|
||||
|
@ -1,70 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/cardview_dark_background"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/title_rules_activity"
|
||||
android:textColor="#eee"
|
||||
android:textSize="40dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title_gen"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:padding="5dp"
|
||||
android:text="@string/title_gen_rules"
|
||||
android:textColor="#eee"
|
||||
android:textSize="20dp"/>
|
||||
<TextView
|
||||
android:id="@+id/gen"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp"
|
||||
android:text="@string/general_rules"
|
||||
android:textColor="#eee"
|
||||
android:textSize="16dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title_hot"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="30dp"
|
||||
android:padding="5dp"
|
||||
android:text="@string/title_hotseat"
|
||||
android:textColor="#eee"
|
||||
android:textSize="20dp"/>
|
||||
<TextView
|
||||
android:id="@+id/hot"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp"
|
||||
android:text="@string/rules_hotseat"
|
||||
android:textColor="#eee"
|
||||
android:textSize="16dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title_bot"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="30dp"
|
||||
android:padding="5dp"
|
||||
android:text="@string/title_bot"
|
||||
android:textColor="#eee"
|
||||
android:textSize="20dp"/>
|
||||
<TextView
|
||||
android:id="@+id/bot"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp"
|
||||
android:text="@string/rules_bot"
|
||||
android:textColor="#eee"
|
||||
android:textSize="16dp"/>
|
||||
</LinearLayout>
|
@ -1,46 +1,10 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/cardview_dark_background"
|
||||
android:orientation="vertical"
|
||||
tools:ignore="UseSwitchCompatOrMaterialXml">
|
||||
android:background="@color/cardview_dark_background">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/header"
|
||||
android:textColor="#eee"
|
||||
android:textSize="40dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/backButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="60dp"
|
||||
android:background="#aaa"
|
||||
android:padding="7dp"
|
||||
android:text="@string/back_menu"/>
|
||||
|
||||
<Switch
|
||||
android:id="@+id/switchPion"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="50dp"
|
||||
android:text="@string/pions_title"
|
||||
android:textColor="#eee"
|
||||
android:textSize="20dp"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="40dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginRight="40dp"
|
||||
android:text="@string/summary"
|
||||
android:textColor="#eee"
|
||||
android:textSize="15dp"/>
|
||||
<FrameLayout
|
||||
android:id="@+id/settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
@ -14,6 +14,6 @@
|
||||
<color name="yellow">#FFFEC603</color>
|
||||
<color name="grey">#FF333333</color>
|
||||
<color name="pionVide">#FF999999</color>
|
||||
<color name="vide">#FF889998</color>
|
||||
<color name="red">#d32f2f</color>
|
||||
|
||||
|
||||
</resources>
|
@ -1,25 +1,11 @@
|
||||
<resources>
|
||||
<string name="app_name">MasterMind</string>
|
||||
<string name="title_activity_settings">SettingsActivity</string>
|
||||
<string name="title_rules_activity">Règles</string>
|
||||
|
||||
<!-- Preference Titles -->
|
||||
<string name="header">Paramètres</string>
|
||||
|
||||
<!-- Sync Preferences -->
|
||||
<string name="back_menu">< Retour au menu</string>
|
||||
<string name="pions_title">Autoriser les pions vides</string>
|
||||
<string name="summary">Cette fonctionnalité augmente la difficulté du jeu pour l\'attaquant</string>
|
||||
|
||||
<!-- Rules -->
|
||||
<string name="title_gen_rules">Règles générales :</string>
|
||||
<string name="general_rules">Le mastermind est un jeu qui se joue généralement à deux, un défenseur doit choisir un code couleur que l\'attaquant devra deviner.
|
||||
Pour se faire, une fois le code choisi par le 1er joueur, le 2nd a 10 tentatives pour le retrouver, après chaque essai la proposition est évalué.
|
||||
Avec des pions noirs il indique les couleurs bien placées, et avec des pions blancs des couleurs mal placées, s\'il ne place pas de pion c\'est que la couleur
|
||||
de la proposition n\'est pas dans le code à trouver.</string>
|
||||
<string name="title_hotseat">Mode 1 vs 1 :</string>
|
||||
<string name="rules_hotseat">Mode de jeu classique, le défenseur choisit un code, l\'attaquant fait ces propositions et la notation de chaque tentative est faite à la main par le défenseur.</string>
|
||||
<string name="title_bot">Mode 1 vs Ordi :</string>
|
||||
<string name="rules_bot">Dans ce mode de jeu, le code couleur est choisi aléatoirement par un bot, et les notations des essaies est sont faites de manière automatique.</string>
|
||||
|
||||
<string name="summary">Cette fonctionnalité augmente la difficultédu jeu pour l\'attaquant</string>
|
||||
</resources>
|
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<PreferenceCategory app:title="@string/header">
|
||||
<SwitchPreferenceCompat
|
||||
app:key="switchPion"
|
||||
app:title="@string/pions_title"
|
||||
app:summaryOff="@string/summary"
|
||||
app:summaryOn="@string/summary" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user