diff --git a/app/src/main/java/com/example/mastermind/ChoixDuMotDePasse.java b/app/src/main/java/com/example/mastermind/ChoixDuMotDePasse.java
index 6bf2afc..ad4886d 100644
--- a/app/src/main/java/com/example/mastermind/ChoixDuMotDePasse.java
+++ b/app/src/main/java/com/example/mastermind/ChoixDuMotDePasse.java
@@ -2,13 +2,52 @@ package com.example.mastermind;
import androidx.appcompat.app.AppCompatActivity;
+import android.content.Intent;
import android.os.Bundle;
+import android.view.View;
+
+import com.example.mastermind.controller.ChoixDuMotDePasse.OnTouchBoutonValider;
+import com.example.mastermind.controller.mastermind.MonOnTouchListener;
+import com.example.mastermind.vue.mastermind.UnePiece;
+
+import java.util.Random;
public class ChoixDuMotDePasse extends AppCompatActivity {
+ private UnePiece un, deux, trois, quatre;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_choix_du_mot_de_passe);
+
+ this.un=(UnePiece) this.findViewById(R.id.code1);
+ this.deux=(UnePiece) this.findViewById(R.id.code2);
+ this.trois=(UnePiece) this.findViewById(R.id.code3);
+ this.quatre=(UnePiece) this.findViewById(R.id.code4);
+
+ this.un.setOnTouchListener(new MonOnTouchListener(this.un));
+ this.deux.setOnTouchListener(new MonOnTouchListener(this.deux));
+ this.trois.setOnTouchListener(new MonOnTouchListener(this.trois));
+ this.quatre.setOnTouchListener(new MonOnTouchListener(this.quatre));
+
+ this.findViewById(R.id.bouton_valider_code).setOnTouchListener(new OnTouchBoutonValider(this));
+
+ }
+
+ public void start(){
+ Intent mastermind=new Intent(this, MasterMindActivity.class);
+ Intent data=this.getIntent();
+ mastermind.putExtra("vide", data.getBooleanExtra("vide", false));
+
+ int tab[]=new int[4];
+ tab[0]=this.un.getColor();
+ tab[1]=this.deux.getColor();
+ tab[2]=this.trois.getColor();
+ tab[3]=this.quatre.getColor();
+ mastermind.putExtra("code", tab);
+
+ this.startActivity(mastermind);
+ this.finish();
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/mastermind/MasterMindActivity.java b/app/src/main/java/com/example/mastermind/MasterMindActivity.java
index 78fe96c..98dca96 100644
--- a/app/src/main/java/com/example/mastermind/MasterMindActivity.java
+++ b/app/src/main/java/com/example/mastermind/MasterMindActivity.java
@@ -13,7 +13,17 @@ public class MasterMindActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_master_mind);
Intent data=this.getIntent();
- System.out.println(data.getIntExtra("nbJoeur", 1));
- System.out.println(data.getIntArrayExtra("code"));
+ System.out.println(data.getBooleanExtra("vide", false));
+ int tab[]=data.getIntArrayExtra("code");
+ for(int i : tab){
+ System.out.println(i);
+ }
+ }
+
+ @Override
+ public void onBackPressed() {
+ Intent menu=new Intent(this, MenuActivity.class);
+ this.startActivity(menu);
+ this.finish();
}
}
diff --git a/app/src/main/java/com/example/mastermind/controller/ChoixDuMotDePasse/OnTouchBoutonValider.java b/app/src/main/java/com/example/mastermind/controller/ChoixDuMotDePasse/OnTouchBoutonValider.java
new file mode 100644
index 0000000..93beab7
--- /dev/null
+++ b/app/src/main/java/com/example/mastermind/controller/ChoixDuMotDePasse/OnTouchBoutonValider.java
@@ -0,0 +1,21 @@
+package com.example.mastermind.controller.ChoixDuMotDePasse;
+
+import android.view.MotionEvent;
+import android.view.View;
+
+import com.example.mastermind.ChoixDuMotDePasse;
+
+public class OnTouchBoutonValider implements View.OnTouchListener {
+
+ private ChoixDuMotDePasse mdp;
+
+ public OnTouchBoutonValider(ChoixDuMotDePasse mdp0){
+ this.mdp=mdp0;
+ }
+
+ @Override
+ public boolean onTouch(View view, MotionEvent motionEvent) {
+ this.mdp.start();
+ return false;
+ }
+}
diff --git a/app/src/main/java/com/example/mastermind/controller/mastermind/MonGestureDetector.java b/app/src/main/java/com/example/mastermind/controller/mastermind/MonGestureDetector.java
deleted file mode 100644
index 1918d90..0000000
--- a/app/src/main/java/com/example/mastermind/controller/mastermind/MonGestureDetector.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.example.mastermind.controller.mastermind;
-
-import android.os.Handler;
-import android.view.GestureDetector;
-import android.view.MotionEvent;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
-public class MonGestureDetector extends GestureDetector {
-
- public MonGestureDetector(@NonNull OnGestureListener listener, @Nullable Handler handler) {
- super(listener, handler);
- }
-}
diff --git a/app/src/main/java/com/example/mastermind/controller/mastermind/MonGestureListener.java b/app/src/main/java/com/example/mastermind/controller/mastermind/MonGestureListener.java
index 81b36d8..6c15930 100644
--- a/app/src/main/java/com/example/mastermind/controller/mastermind/MonGestureListener.java
+++ b/app/src/main/java/com/example/mastermind/controller/mastermind/MonGestureListener.java
@@ -5,7 +5,17 @@ import android.view.MotionEvent;
import androidx.annotation.NonNull;
+import com.example.mastermind.vue.mastermind.UnePiece;
+
public class MonGestureListener implements GestureDetector.OnGestureListener {
+
+ private UnePiece vue;
+
+ public MonGestureListener(UnePiece p) {
+ this.vue=p;
+ }
+
+
@Override
public boolean onDown(@NonNull MotionEvent motionEvent) {
return false;
@@ -18,7 +28,8 @@ public class MonGestureListener implements GestureDetector.OnGestureListener {
@Override
public boolean onSingleTapUp(@NonNull MotionEvent motionEvent) {
- return false;
+ this.vue.setColor(5);
+ return true;
}
@Override
@@ -28,11 +39,47 @@ public class MonGestureListener implements GestureDetector.OnGestureListener {
@Override
public void onLongPress(@NonNull MotionEvent motionEvent) {
-
+ this.vue.setColor(4);
}
@Override
public boolean onFling(@NonNull MotionEvent motionEvent, @NonNull MotionEvent motionEvent1, float v, float v1) {
- return false;
+ if(v>0 && v1>0){
+ if(v>v1){
+ //slide a droit plus fort
+ this.vue.setColor(2);
+ }else{
+ //slide en bas plus fort
+ this.vue.setColor(1);
+ }
+ }
+ if(v>0 && v1<0){
+ if(v+v1 >0){
+ //slide a droit plus fort
+ this.vue.setColor(2);
+ }else{
+ //slide en haut plus fort
+ this.vue.setColor(1);
+ }
+ }
+ if(v<0 && v1>0){
+ if((v+v1) < 0){
+ //slide a gauche plus fort
+ this.vue.setColor(0);
+ }else{
+ //slide en bas plus fort
+ this.vue.setColor(3);
+ }
+ }
+ if(v<0 && v1<0){
+ if(v < v1){
+ //slide gauche plus fort
+ this.vue.setColor(0);
+ }else{
+ //slide en haut plus fort
+ this.vue.setColor(1);
+ }
+ }
+ return true;
}
}
diff --git a/app/src/main/java/com/example/mastermind/controller/mastermind/MonOnTouchListener.java b/app/src/main/java/com/example/mastermind/controller/mastermind/MonOnTouchListener.java
new file mode 100644
index 0000000..c85e00a
--- /dev/null
+++ b/app/src/main/java/com/example/mastermind/controller/mastermind/MonOnTouchListener.java
@@ -0,0 +1,24 @@
+package com.example.mastermind.controller.mastermind;
+
+import android.view.GestureDetector;
+import android.view.MotionEvent;
+import android.view.View;
+
+import com.example.mastermind.R;
+import com.example.mastermind.vue.mastermind.UnePiece;
+
+public class MonOnTouchListener implements View.OnTouchListener {
+
+ private GestureDetector detector;
+ private MonGestureListener listener;
+ public MonOnTouchListener(UnePiece p){
+ this.listener=new MonGestureListener(p);
+ this.detector=new GestureDetector(this.listener);
+ }
+
+ @Override
+ public boolean onTouch(View view, MotionEvent motionEvent) {
+ this.detector.onTouchEvent(motionEvent);
+ return true;
+ }
+}
diff --git a/app/src/main/java/com/example/mastermind/controller/mastermind/ObservateurTouchListener.java b/app/src/main/java/com/example/mastermind/controller/mastermind/ObservateurTouchListener.java
deleted file mode 100644
index 48895bd..0000000
--- a/app/src/main/java/com/example/mastermind/controller/mastermind/ObservateurTouchListener.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.example.mastermind.controller.mastermind;
-
-import android.view.MotionEvent;
-import android.view.View;
-
-public class ObservateurTouchListener implements View.OnTouchListener {
-
-
- @Override
- public boolean onTouch(View view, MotionEvent motionEvent) {
-
- return true;
- }
-}
diff --git a/app/src/main/java/com/example/mastermind/controller/menu/ObservateurMenuDebutPartie.java b/app/src/main/java/com/example/mastermind/controller/menu/ObservateurMenuDebutPartie.java
index 6f3dc05..19b76ae 100644
--- a/app/src/main/java/com/example/mastermind/controller/menu/ObservateurMenuDebutPartie.java
+++ b/app/src/main/java/com/example/mastermind/controller/menu/ObservateurMenuDebutPartie.java
@@ -39,7 +39,7 @@ public class ObservateurMenuDebutPartie implements View.OnClickListener {
tab[1]=r.nextInt(6);
tab[2]=r.nextInt(6);
tab[3]=r.nextInt(6);
- mastermind.putIntegerArrayListExtra("code", )
+ mastermind.putExtra("code", tab);
menu.startActivity(mastermind);
}
diff --git a/app/src/main/java/com/example/mastermind/util/MonPaint.java b/app/src/main/java/com/example/mastermind/util/MonPaint.java
index 255c6fc..d3844ef 100644
--- a/app/src/main/java/com/example/mastermind/util/MonPaint.java
+++ b/app/src/main/java/com/example/mastermind/util/MonPaint.java
@@ -37,6 +37,13 @@ public abstract class MonPaint {
return MonPaint.verte;
}
+ public static Paint getRouge() {
+ if(MonPaint.rouge== null){
+ MonPaint.istanciate();
+ }
+ return MonPaint.rouge;
+ }
+
public static Paint getJaune(){
if(MonPaint.jaune== null){
MonPaint.istanciate();
@@ -64,4 +71,27 @@ public abstract class MonPaint {
}
return MonPaint.noir;
}
+
+ public static Paint getColor(int n){
+ switch (n){
+ case 0:
+ return MonPaint.getRouge();
+ case 1:
+ return MonPaint.getBleue();
+
+ case 2:
+ return MonPaint.getVerte();
+
+ case 3:
+ return MonPaint.getJaune();
+ case 4:
+ return MonPaint.getNoir();
+
+ case 5:
+ return MonPaint.getBlanche();
+
+ default:
+ return null;
+ }
+ }
}
diff --git a/app/src/main/java/com/example/mastermind/vue/UnePiece.java b/app/src/main/java/com/example/mastermind/vue/mastermind/UnePiece.java
similarity index 52%
rename from app/src/main/java/com/example/mastermind/vue/UnePiece.java
rename to app/src/main/java/com/example/mastermind/vue/mastermind/UnePiece.java
index ab4f841..380e77f 100644
--- a/app/src/main/java/com/example/mastermind/vue/UnePiece.java
+++ b/app/src/main/java/com/example/mastermind/vue/mastermind/UnePiece.java
@@ -1,4 +1,4 @@
-package com.example.mastermind.vue;
+package com.example.mastermind.vue.mastermind;
import android.content.Context;
import android.graphics.Canvas;
@@ -12,14 +12,30 @@ import com.example.mastermind.util.MonPaint;
public class UnePiece extends View {
+ private int color;
public UnePiece(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
+ this.color=4;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
- canvas.drawArc(0, 0, 50, 50, 0, (float) (Math.PI*2), false, MonPaint.getNoir());
+ int centerX = getWidth() / 2;
+ int centerY = getHeight() / 2;
+ int radius = 50;
+
+
+ canvas.drawCircle(centerX, centerY, radius, MonPaint.getColor(this.color));
+ }
+
+ public int getColor() {
+ return color;
+ }
+
+ public void setColor(int colorr) {
+ this.color = colorr%6;
+ this.invalidate();
}
}
diff --git a/app/src/main/res/layout/activity_choix_du_mot_de_passe.xml b/app/src/main/res/layout/activity_choix_du_mot_de_passe.xml
index 466e6ed..c98d967 100644
--- a/app/src/main/res/layout/activity_choix_du_mot_de_passe.xml
+++ b/app/src/main/res/layout/activity_choix_du_mot_de_passe.xml
@@ -1,9 +1,70 @@
-
+ android:layout_height="match_parent"
+ android:background="@color/marron"
+ android:gravity="center"
+ android:orientation="vertical"
+
+ >
+
+
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_menu.xml b/app/src/main/res/layout/activity_menu.xml
index 9366a35..8c4f543 100644
--- a/app/src/main/res/layout/activity_menu.xml
+++ b/app/src/main/res/layout/activity_menu.xml
@@ -30,14 +30,14 @@
+ android:background="@color/purple_200"
+ android:text="Un Joueur"
+ android:textSize="30dp" />
diff --git a/app/src/main/res/layout/activity_setting.xml b/app/src/main/res/layout/activity_setting.xml
deleted file mode 100644
index aa4d77b..0000000
--- a/app/src/main/res/layout/activity_setting.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
new file mode 100644
index 0000000..9e0283e
--- /dev/null
+++ b/app/src/main/res/values/dimens.xml
@@ -0,0 +1,5 @@
+
+
+ 50dp
+ 20dp
+
\ No newline at end of file