Compare commits
33 Commits
viewIsJava
...
master
Author | SHA1 | Date | |
---|---|---|---|
fbcb77fb3a | |||
2fb6989c67 | |||
|
2538749068 | ||
|
bfb83c514e | ||
e2b69773c7 | |||
|
df84ff5644 | ||
e87e252360 | |||
e44c528a73 | |||
03f89a8f32 | |||
04f5c17704 | |||
30fd4f018e | |||
f9d020a741 | |||
|
bbeca7dee9 | ||
43864b6a63 | |||
|
38d267b8b2 | ||
8b8ff56069 | |||
db5dfdb21b | |||
|
cd3bcb4176 | ||
d3550eb8d1 | |||
89d4de7fa8 | |||
|
f267e9efc2 | ||
9b08b28846 | |||
402db64b6b | |||
5e84efc0b4 | |||
|
e49234ef91 | ||
|
335918a8ce | ||
|
4e94a324f5 | ||
|
c14ad27b85 | ||
|
405c41e2d3 | ||
ef0b698a77 | |||
dfc3a84cd3 | |||
75ac209aef | |||
e34c000f65 |
BIN
Rapport_SAE4_Gobert_Haissous.pdf
Normal file
BIN
Rapport_SAE4_Gobert_Haissous.pdf
Normal file
Binary file not shown.
@ -14,7 +14,7 @@
|
||||
android:theme="@style/Theme.MasterMind"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".HotSeatActivity"
|
||||
android:name=".GameActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".SettingsActivity"
|
||||
@ -25,6 +25,12 @@
|
||||
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">
|
||||
|
78
app/src/main/java/com/example/mastermind/ChoiceCombi.java
Normal file
78
app/src/main/java/com/example/mastermind/ChoiceCombi.java
Normal file
@ -0,0 +1,78 @@
|
||||
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();
|
||||
}
|
||||
}
|
220
app/src/main/java/com/example/mastermind/GameActivity.java
Normal file
220
app/src/main/java/com/example/mastermind/GameActivity.java
Normal file
@ -0,0 +1,220 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
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,7 +10,8 @@ public class MainActivity extends Activity {
|
||||
private Button mHotSeat;
|
||||
private Button mORDI;
|
||||
private Button mSettings;
|
||||
//private Button mRules;
|
||||
private Button mRules;
|
||||
private boolean pionV;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -19,34 +20,47 @@ 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 tp1Intent = new Intent(MainActivity.this, HotSeatActivity.class);
|
||||
startActivity(tp1Intent);
|
||||
Intent HotSeat = new Intent(MainActivity.this, GameActivity.class);
|
||||
HotSeat.putExtra("bot", false);
|
||||
HotSeat.putExtra("pionVide", pionV);
|
||||
startActivity(HotSeat);
|
||||
}
|
||||
});
|
||||
/*mORDI.setOnClickListener(new View.OnClickListener() {
|
||||
mORDI.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent tp2Intent = new Intent(MainActivity.this, ORDI.class);
|
||||
startActivity(tp2Intent);
|
||||
Intent ordi = new Intent(MainActivity.this, GameActivity.class);
|
||||
ordi.putExtra("bot", true);
|
||||
ordi.putExtra("pionVide", pionV);
|
||||
startActivity(ordi);
|
||||
}
|
||||
});*/
|
||||
});
|
||||
mSettings.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent tp3Intent = new Intent(MainActivity.this, SettingsActivity.class);
|
||||
startActivity(tp3Intent);
|
||||
Intent settings = new Intent(MainActivity.this, SettingsActivity.class);
|
||||
startActivityForResult(settings, 2);
|
||||
}
|
||||
});
|
||||
/*mTP4.setOnClickListener(new View.OnClickListener() {
|
||||
mRules.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent tp4Intent = new Intent(MainActivity.this, TP4.class);
|
||||
startActivity(tp4Intent);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
14
app/src/main/java/com/example/mastermind/RulesActivity.java
Normal file
14
app/src/main/java/com/example/mastermind/RulesActivity.java
Normal file
@ -0,0 +1,14 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
14
app/src/main/java/com/example/mastermind/SaisieActivity.java
Normal file
14
app/src/main/java/com/example/mastermind/SaisieActivity.java
Normal file
@ -0,0 +1,14 @@
|
||||
package com.example.mastermind;
|
||||
|
||||
public interface SaisieActivity {
|
||||
public void addChoix(int index);
|
||||
|
||||
void changeState();
|
||||
|
||||
void removePion();
|
||||
|
||||
void clearChoix();
|
||||
|
||||
int getNbrPion();
|
||||
}
|
||||
|
@ -1,33 +1,44 @@
|
||||
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;
|
||||
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
public class SettingsActivity extends Activity {
|
||||
private Button mButton;
|
||||
private Switch mSwitch;
|
||||
private boolean pionV;
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SettingsFragment extends PreferenceFragmentCompat {
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
setPreferencesFromResource(R.xml.root_preferences, rootKey);
|
||||
}
|
||||
mButton = findViewById(R.id.backButton);
|
||||
mSwitch = findViewById(R.id.switchPion);
|
||||
|
||||
mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if(isChecked) {
|
||||
pionV = true;
|
||||
} else {
|
||||
pionV = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
mButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("pionV", pionV);
|
||||
setResult(2, intent);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
104
app/src/main/java/com/example/mastermind/end/EndView.java
Normal file
104
app/src/main/java/com/example/mastermind/end/EndView.java
Normal file
@ -0,0 +1,104 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
83
app/src/main/java/com/example/mastermind/game/Bot.java
Normal file
83
app/src/main/java/com/example/mastermind/game/Bot.java
Normal file
@ -0,0 +1,83 @@
|
||||
package com.example.mastermind.game;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
/* TODO: Modifs pour GameView :
|
||||
- création d'un Bot si le mode de jeu est solo
|
||||
- création d'une méthode redraw(){invalidate()}
|
||||
- variable qui :
|
||||
+ interdit le switch de state
|
||||
+ demande de verif si victoire au Bot lors des soumissions
|
||||
+ soumet à grille sa notation
|
||||
*/
|
||||
public class Bot {
|
||||
private Integer[] collectionWin;
|
||||
private Integer pionVide;
|
||||
private Integer[] pionsNotation;
|
||||
|
||||
public Bot(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){
|
||||
Random rand = new Random();
|
||||
int nbPions = pions.length;
|
||||
for (int i=0;i<4;i++){
|
||||
this.collectionWin[i]=pions[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
|
||||
for(int i=0; i<4;i++) {
|
||||
if (copyCombi[i]==soumission[i]) {
|
||||
note.add(this.pionsNotation[1]);
|
||||
copyCombi[i]=null;
|
||||
soumission[i]=null;
|
||||
}
|
||||
}
|
||||
|
||||
//blancs
|
||||
for(int i=0; i<4;i++) {
|
||||
if(soumission[i]!=null){
|
||||
for (int y=0;y<4;y++){
|
||||
if (soumission[i]==copyCombi[y]) {
|
||||
note.add(this.pionsNotation[0]);
|
||||
copyCombi[y] = null;
|
||||
soumission[i] = null;
|
||||
System.out.println(i+" "+y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
@ -1,129 +1,124 @@
|
||||
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 boolean state;
|
||||
public GameView(Context context,Saisie saisie,Grille grille) {
|
||||
super(context);
|
||||
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;
|
||||
this.saisie=saisie;
|
||||
this.grille=grille;
|
||||
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.setOnTouchListener(new TouchListener(context));
|
||||
this.circle = new Paint();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas){
|
||||
super.onDraw(canvas);
|
||||
this.setBackgroundColor(this.getResources().getColor(R.color.grey));
|
||||
//affichage des anciennes soumissions
|
||||
//copie des soumissions
|
||||
LinkedList<Integer> grille = new LinkedList<Integer>();
|
||||
grille.addAll(this.grille.getSoumissions());
|
||||
System.out.println(grille.size());
|
||||
for (int y=0; y<10;y++) {
|
||||
for (int x=0;x<4;x++) {
|
||||
this.circle.setColor(grille.pop());
|
||||
//TODO: coordonnées propres
|
||||
canvas.drawCircle(( x*this.getWidth()/8+(this.getWidth()*21/68)),(y*this.getWidth()/8+this.getWidth()/10), this.getWidth()/17, this.circle);
|
||||
if(this.grille!=null) {
|
||||
//affichage des anciennes soumissions
|
||||
//copie des soumissions
|
||||
LinkedList<Integer> grille = new LinkedList<Integer>();
|
||||
grille.addAll(this.grille.getSoumissions());
|
||||
for (int y = 0; y < 10; y++) {
|
||||
for (int x = 0; x < 4; x++) {
|
||||
this.circle.setColor(grille.pop());
|
||||
canvas.drawCircle((x * this.getWidth() / 8 + (this.getWidth() * 21 / 68)), (y * this.getHeight() / 14 + this.getHeight() / 21), this.getWidth() / 17, this.circle);
|
||||
}
|
||||
}
|
||||
LinkedList<Integer> notation = new LinkedList<Integer>();
|
||||
notation.addAll(this.grille.getNotations());
|
||||
for(int y=0; y<10; y++) {
|
||||
for(int x=0; x<2; x++) { // colonne gauche
|
||||
this.circle.setColor(notation.pop());
|
||||
canvas.drawCircle((x*this.getWidth()/11+(this.getWidth()/11)),(y*this.getHeight()/14+getHeight()/21), this.getWidth()/26, this.circle);
|
||||
}
|
||||
for(int x=0; x<2; x++) { // colonne droite
|
||||
this.circle.setColor(notation.pop());
|
||||
canvas.drawCircle((x*this.getWidth()/11+(this.getWidth()*4/5)),(y*this.getHeight()/14+getHeight()/21), this.getWidth()/26, this.circle);
|
||||
}
|
||||
}
|
||||
}
|
||||
// affichage de la zone de saisie
|
||||
//copie de la zone de saisie
|
||||
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.getWidth()*58/40, this.getWidth()/12, this.circle);
|
||||
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());
|
||||
System.out.println(couleurs.size());
|
||||
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.getWidth()*689/420, this.getWidth()/15, this.circle);
|
||||
}
|
||||
//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.getWidth()/9, this.getWidth()/10, this.circle);
|
||||
}
|
||||
|
||||
//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();
|
||||
}
|
||||
}
|
||||
|
||||
//ajoute une nouvelle couleur pour la séléction à soumettre
|
||||
public void addChoix(int choix){
|
||||
this.saisie.addSelection(choix);
|
||||
this.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.pionsPasPlaces = new LinkedList<Integer>();
|
||||
for (int i=0;i<4;i++){
|
||||
this.pionsPasPlaces.add(this.getResources().getColor(R.color.pionVide));
|
||||
if(this.saisie.getChoix().size() == 6 || this.saisie.getChoix().size() == 2) {
|
||||
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);
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
//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));
|
||||
// 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);
|
||||
// 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);
|
||||
}
|
||||
|
||||
//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));
|
||||
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
|
||||
final int height = options.outHeight;
|
||||
final int width = options.outWidth;
|
||||
int inSampleSize = 1;
|
||||
|
||||
// on inisialise la saisie
|
||||
saisie.setChoix(this.pionsAttaquant);
|
||||
saisie.initSelection(this.getResources().getColor(R.color.pionVide));
|
||||
if (height > reqHeight || width > reqWidth) {
|
||||
final int halfHeight = height / 2;
|
||||
final int halfWidth = width / 2;
|
||||
|
||||
// on rempli la grille de cases grises
|
||||
grille.initGrille(this.pionsPasPlaces);
|
||||
while ((halfHeight / inSampleSize) >= reqHeight && (halfWidth / inSampleSize) >= reqWidth) {
|
||||
inSampleSize *= 3;
|
||||
}
|
||||
}
|
||||
|
||||
return inSampleSize;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ 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
|
||||
@ -23,38 +24,48 @@ public class Grille {
|
||||
}
|
||||
|
||||
// Méthode permettant d'ajouter une soumission
|
||||
public void addSoumission(LinkedList<Integer> newSub){
|
||||
public void addSoumission(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.poll());
|
||||
this.soumissions.addLast(newSub[i]);
|
||||
//Et une ligne vide pour les notations
|
||||
this.notations.addLast(this.pionVide);
|
||||
|
||||
}
|
||||
this.sizeSubs += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Méthode qui permet d'initialiser la grille vide
|
||||
public void initGrille(Collection<Integer> SubToCopy){
|
||||
public void initGrille(Integer pionVide){
|
||||
this.pionVide=pionVide;
|
||||
//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++){
|
||||
this.soumissions.addAll(SubToCopy);
|
||||
this.notations.addAll(SubToCopy);
|
||||
for(int y=0;y<4;y++) {
|
||||
this.soumissions.add(pionVide);
|
||||
this.notations.add(pionVide);
|
||||
}
|
||||
}
|
||||
// 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(LinkedList<Integer> newNot){
|
||||
public void addNotation(Integer[] newNot){
|
||||
for (int i=0; i<4; i++) {
|
||||
//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());
|
||||
//On retire la derniere ligne vide
|
||||
this.notations.removeLast();
|
||||
}
|
||||
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
|
||||
@ -65,5 +76,15 @@ 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,23 +28,39 @@ 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 chosenColors){
|
||||
public void initSelection(Integer pionVide){
|
||||
this.selection.removeAll(this.selection);
|
||||
for (int i=0;i<4;i++){
|
||||
this.selection.add(chosenColors);
|
||||
this.selection.add(pionVide);
|
||||
}
|
||||
//au début la zone de séléction est vide
|
||||
this.sizeSelection=0;
|
||||
|
||||
}
|
||||
//addSelection permet d'ajouter un pion à la zone de saisie
|
||||
public void addSelection(Integer chosenColors){
|
||||
//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.selection.set(this.sizeSelection,this.choix.get(chosenColors));
|
||||
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){
|
||||
//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) {
|
||||
if(this.sizeSelection>0) {
|
||||
this.selection.remove(this.sizeSelection-1);
|
||||
this.selection.add(pionVide);
|
||||
this.sizeSelection--;
|
||||
}
|
||||
}
|
||||
|
||||
public int getSizeSelection(){
|
||||
@ -56,13 +72,23 @@ 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(Collection<Integer> colorsSelected){
|
||||
public void setChoix(Integer[] colorsSelected){
|
||||
this.choix.removeAll(this.choix);
|
||||
this.choix.addAll(colorsSelected);
|
||||
for (int i=0;i<colorsSelected.length;i++){
|
||||
this.choix.add(colorsSelected[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public LinkedList<Integer> getSelection(){
|
||||
return this.selection;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
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,10 +3,13 @@ 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 GameView view;
|
||||
public TouchListener(GameView view) {
|
||||
this.view=view;
|
||||
private SaisieActivity context;
|
||||
public TouchListener(SaisieActivity context) {
|
||||
this.context=context;
|
||||
}
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
@ -17,23 +20,48 @@ public class TouchListener implements View.OnTouchListener{
|
||||
if (action==MotionEvent.ACTION_UP)
|
||||
{
|
||||
//Surveille quel bouton de couleur est choisi
|
||||
if (v.getWidth()*689/420-v.getWidth()/15<y && y<v.getWidth()*689/420+v.getWidth()/15){
|
||||
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);
|
||||
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();
|
||||
}
|
||||
// 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;
|
||||
|
BIN
app/src/main/res/drawable/back_button.png
Normal file
BIN
app/src/main/res/drawable/back_button.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
BIN
app/src/main/res/drawable/cancel_button.png
Normal file
BIN
app/src/main/res/drawable/cancel_button.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
BIN
app/src/main/res/drawable/valid_button.png
Normal file
BIN
app/src/main/res/drawable/valid_button.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
11
app/src/main/res/layout/activity_game.xml
Normal file
11
app/src/main/res/layout/activity_game.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<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>
|
@ -4,7 +4,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#333"
|
||||
android:padding="10dp"
|
||||
tools:context=".MainActivity"
|
||||
>
|
||||
|
||||
@ -26,7 +25,8 @@
|
||||
android:text="Mastermind"
|
||||
android:gravity="center"
|
||||
android:textColor="#eee"
|
||||
android:padding="50dp"
|
||||
android:paddingHorizontal="10dp"
|
||||
android:paddingVertical="40dp"
|
||||
android:textSize="50dp"
|
||||
android:autoSizeMaxTextSize="100dp"
|
||||
android:autoSizeMinTextSize="10dp">
|
||||
|
70
app/src/main/res/layout/activity_rules.xml
Normal file
70
app/src/main/res/layout/activity_rules.xml
Normal file
@ -0,0 +1,70 @@
|
||||
<?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,10 +1,46 @@
|
||||
<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:background="@color/cardview_dark_background"
|
||||
android:orientation="vertical"
|
||||
tools:ignore="UseSwitchCompatOrMaterialXml">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
<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"/>
|
||||
</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,11 +1,25 @@
|
||||
<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>
|
||||
<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>
|
||||
|
||||
</resources>
|
14
app/src/main/res/xml/preferences.xml
Normal file
14
app/src/main/res/xml/preferences.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?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