mise en place activite choixcombi (startactivityforresult)
This commit is contained in:
parent
f9d020a741
commit
30fd4f018e
@ -28,6 +28,9 @@
|
||||
<activity
|
||||
android:name=".RulesActivity"
|
||||
android:exported="false"/>
|
||||
<activity
|
||||
android:name=".ChoiceCombi"
|
||||
android:exported="false"/>
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
|
@ -1,19 +1,51 @@
|
||||
package com.example.mastermind;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import com.example.mastermind.game.GameView;
|
||||
import com.example.mastermind.game.Grille;
|
||||
import com.example.mastermind.game.Saisie;
|
||||
|
||||
public class HotSeatActivity extends Activity {
|
||||
public class ChoiceCombi extends Activity implements SaisieActivity {
|
||||
private Saisie saisie;
|
||||
private Integer[] combiGagnante;
|
||||
private Integer[] pions;
|
||||
private View view;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
boolean bot = getIntent().getBooleanExtra("bot", false);
|
||||
if setContentView(new ChoiceCombi(this, new Saisie()));
|
||||
int[] tab = getIntent().getIntArrayExtra("pions");
|
||||
this.pions=new Integer[6];
|
||||
for (int i=0;i<tab.length-1;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);
|
||||
}
|
||||
|
||||
public void letsplay()
|
||||
public void changeState(){
|
||||
Intent returnIntent = new Intent();
|
||||
returnIntent.putExtra("choix",this.saisie.getSelection());
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.example.mastermind;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Bundle;
|
||||
@ -11,7 +12,7 @@ import com.example.mastermind.game.GameView;
|
||||
import com.example.mastermind.game.Grille;
|
||||
import com.example.mastermind.game.Saisie;
|
||||
|
||||
public class GameActivity extends Activity {
|
||||
public class GameActivity extends Activity implements SaisieActivity {
|
||||
private Integer[] pionsAttaquant;
|
||||
private Integer[] pionsDefenseur;
|
||||
private Integer pionVide;
|
||||
@ -33,9 +34,15 @@ public class GameActivity extends Activity {
|
||||
initpions();
|
||||
this.theBot=new Bot(this.pionsAttaquant, this.pionsDefenseur, this.pionVide);
|
||||
if(!this.bot){
|
||||
//ChoiceCombi
|
||||
Intent choiceCombi = new Intent(this, ChoiceCombi.class);
|
||||
int[] tabpions=new int[6];
|
||||
for (int i=0;i<this.pionsAttaquant.length;i++) {
|
||||
tabpions[i] = this.pionsAttaquant[i];
|
||||
}
|
||||
this.view=new GameView(this,this.saisie, this.grille);
|
||||
choiceCombi.putExtra("pions", tabpions);
|
||||
startActivityForResult(choiceCombi, 1);
|
||||
}
|
||||
this.view=new GameView(this,this,this.saisie, this.grille);
|
||||
setContentView(view);
|
||||
}
|
||||
|
||||
@ -67,10 +74,6 @@ public class GameActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
//ajoute une nouvelle couleur pour la séléction à soumettre
|
||||
public void addChoix(int choix){
|
||||
this.saisie.addSelection(choix);
|
||||
|
12
app/src/main/java/com/example/mastermind/SaisieActivity.java
Normal file
12
app/src/main/java/com/example/mastermind/SaisieActivity.java
Normal file
@ -0,0 +1,12 @@
|
||||
package com.example.mastermind;
|
||||
|
||||
public interface SaisieActivity {
|
||||
public void addChoix(int index);
|
||||
|
||||
void changeState();
|
||||
|
||||
void removePion();
|
||||
|
||||
void clearChoix();
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.example.mastermind.game;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
@ -11,6 +12,7 @@ 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;
|
||||
@ -23,8 +25,8 @@ public class GameView extends View {
|
||||
private Bitmap cancelBtn;
|
||||
private Bitmap backBtn;
|
||||
private Bitmap validBtn;
|
||||
public GameView(GameActivity context, Saisie saisie, Grille grille) {
|
||||
super(context);
|
||||
public GameView(Context con, SaisieActivity context, Saisie saisie, Grille grille) {
|
||||
super(con);
|
||||
this.saisie=saisie;
|
||||
this.grille=grille;
|
||||
this.setOnTouchListener(new TouchListener(context));
|
||||
|
@ -4,11 +4,11 @@ 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 GameActivity context;
|
||||
private int i = 0;
|
||||
public TouchListener(GameActivity context) {
|
||||
private SaisieActivity context;
|
||||
public TouchListener(SaisieActivity context) {
|
||||
this.context=context;
|
||||
}
|
||||
@Override
|
||||
@ -25,9 +25,6 @@ public class TouchListener implements View.OnTouchListener{
|
||||
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);
|
||||
if(!this.context.getState()) {
|
||||
i++;
|
||||
}
|
||||
} else if(2*v.getWidth()*2/13+v.getWidth()/8-v.getWidth()/15<x && x<2*v.getWidth()*2/13+v.getWidth()/8+v.getWidth()/15) {
|
||||
this.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){
|
||||
@ -41,7 +38,6 @@ public class TouchListener implements View.OnTouchListener{
|
||||
} 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();
|
||||
i = 0;
|
||||
} 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
|
||||
|
Loading…
Reference in New Issue
Block a user