diff --git a/app/src/main/java/com/example/mastermind/ChoixDuMotDePasse.java b/app/src/main/java/com/example/mastermind/ChoixDuMotDePasse.java index ad4886d..ff86cdb 100644 --- a/app/src/main/java/com/example/mastermind/ChoixDuMotDePasse.java +++ b/app/src/main/java/com/example/mastermind/ChoixDuMotDePasse.java @@ -26,10 +26,11 @@ public class ChoixDuMotDePasse extends AppCompatActivity { 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)); + boolean t=this.getIntent().getBooleanExtra("vide", false); + this.un.setOnTouchListener(new MonOnTouchListener(this.un, t)); + this.deux.setOnTouchListener(new MonOnTouchListener(this.deux, t)); + this.trois.setOnTouchListener(new MonOnTouchListener(this.trois, t)); + this.quatre.setOnTouchListener(new MonOnTouchListener(this.quatre, t)); this.findViewById(R.id.bouton_valider_code).setOnTouchListener(new OnTouchBoutonValider(this)); diff --git a/app/src/main/java/com/example/mastermind/MasterMindActivity.java b/app/src/main/java/com/example/mastermind/MasterMindActivity.java index 98dca96..8e3d591 100644 --- a/app/src/main/java/com/example/mastermind/MasterMindActivity.java +++ b/app/src/main/java/com/example/mastermind/MasterMindActivity.java @@ -2,21 +2,31 @@ package com.example.mastermind; import android.content.Intent; import android.os.Bundle; +import android.view.View; +import android.widget.LinearLayout; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import com.example.mastermind.controller.mastermind.MonOnTouchListener; +import com.example.mastermind.vue.mastermind.UnePiece; + public class MasterMindActivity extends AppCompatActivity { + private int[] code; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_master_mind); Intent data=this.getIntent(); - System.out.println(data.getBooleanExtra("vide", false)); - int tab[]=data.getIntArrayExtra("code"); - for(int i : tab){ - System.out.println(i); + this.code=data.getIntArrayExtra("code"); + LinearLayout l=this.findViewById(R.id.jeu); + + for(int i=0; i0 && v1>0){ - if(v>v1){ - //slide a droit plus fort + if (Math.abs(v) > Math.abs(v1)) { + if (v > 0) { + // slide à droite 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 + } else { + // slide à gauche this.vue.setColor(0); - }else{ - //slide en bas plus fort + } + } else { + if (v1 > 0) { + // slide en bas + this.vue.setColor(1); + } else { + // slide en haut 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/MonOnDoubleTapListener.java b/app/src/main/java/com/example/mastermind/controller/mastermind/MonOnDoubleTapListener.java new file mode 100644 index 0000000..a4ef895 --- /dev/null +++ b/app/src/main/java/com/example/mastermind/controller/mastermind/MonOnDoubleTapListener.java @@ -0,0 +1,32 @@ +package com.example.mastermind.controller.mastermind; + +import android.view.GestureDetector; +import android.view.MotionEvent; + +import androidx.annotation.NonNull; + +import com.example.mastermind.vue.mastermind.UnePiece; + +public class MonOnDoubleTapListener implements GestureDetector.OnDoubleTapListener { + private UnePiece v; + + public MonOnDoubleTapListener(UnePiece p){ + this.v=p; + } + @Override + public boolean onSingleTapConfirmed(@NonNull MotionEvent motionEvent) { + this.v.setColor(5); + return true; + } + + @Override + public boolean onDoubleTap(@NonNull MotionEvent motionEvent) { + this.v.setColor(4); + return true; + } + + @Override + public boolean onDoubleTapEvent(@NonNull MotionEvent motionEvent) { + return false; + } +} 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 index c85e00a..2347695 100644 --- a/app/src/main/java/com/example/mastermind/controller/mastermind/MonOnTouchListener.java +++ b/app/src/main/java/com/example/mastermind/controller/mastermind/MonOnTouchListener.java @@ -1,19 +1,22 @@ package com.example.mastermind.controller.mastermind; +import android.content.Context; import android.view.GestureDetector; import android.view.MotionEvent; +import android.view.ScaleGestureDetector; 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); + public MonOnTouchListener(UnePiece p, boolean t){ + this.detector=new GestureDetector(new MonGestureListener(p)); + this.detector.setOnDoubleTapListener(new MonOnDoubleTapListener(p)); + if(t==false){ + this.detector.setIsLongpressEnabled(t); + } } @Override 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 d3844ef..b03c6aa 100644 --- a/app/src/main/java/com/example/mastermind/util/MonPaint.java +++ b/app/src/main/java/com/example/mastermind/util/MonPaint.java @@ -10,6 +10,8 @@ public abstract class MonPaint { private static Paint blanche; private static Paint noir; + private static Paint vide; + private static void istanciate(){ MonPaint.rouge=new Paint(); MonPaint.rouge.setColor(0xffff0000); @@ -28,6 +30,11 @@ public abstract class MonPaint { MonPaint.noir=new Paint(); MonPaint.noir.setColor(0xff000000); + + MonPaint.vide=new Paint(); + MonPaint.vide.setColor(0xFF000000); + MonPaint.vide.setStyle(Paint.Style.STROKE); + MonPaint.vide.setStrokeWidth(5.0f); } public static Paint getVerte(){ @@ -72,6 +79,13 @@ public abstract class MonPaint { return MonPaint.noir; } + public static Paint getVide(){ + if(MonPaint.vide== null){ + MonPaint.istanciate(); + } + return MonPaint.vide; + } + public static Paint getColor(int n){ switch (n){ case 0: @@ -89,7 +103,8 @@ public abstract class MonPaint { case 5: return MonPaint.getBlanche(); - + case 6: + return MonPaint.getVide(); default: return null; } diff --git a/app/src/main/java/com/example/mastermind/vue/mastermind/PieceCorrection.java b/app/src/main/java/com/example/mastermind/vue/mastermind/PieceCorrection.java new file mode 100644 index 0000000..63d071b --- /dev/null +++ b/app/src/main/java/com/example/mastermind/vue/mastermind/PieceCorrection.java @@ -0,0 +1,18 @@ +package com.example.mastermind.vue.mastermind; + +import android.content.Context; +import android.util.AttributeSet; + +import androidx.annotation.Nullable; + +public class PieceCorrection extends UnePiece{ + + public PieceCorrection(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected int getRaduis() { + return 20; + } +} diff --git a/app/src/main/java/com/example/mastermind/vue/mastermind/UnePiece.java b/app/src/main/java/com/example/mastermind/vue/mastermind/UnePiece.java index 380e77f..af0ec36 100644 --- a/app/src/main/java/com/example/mastermind/vue/mastermind/UnePiece.java +++ b/app/src/main/java/com/example/mastermind/vue/mastermind/UnePiece.java @@ -24,18 +24,22 @@ public class UnePiece extends View { super.onDraw(canvas); int centerX = getWidth() / 2; int centerY = getHeight() / 2; - int radius = 50; + int radius = this.getRaduis(); canvas.drawCircle(centerX, centerY, radius, MonPaint.getColor(this.color)); } + protected int getRaduis() { + return 40; + } + public int getColor() { return color; } public void setColor(int colorr) { - this.color = colorr%6; + this.color = colorr%7; 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 c98d967..8595f8c 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 @@ -18,29 +18,29 @@ + android:layout_width="@dimen/pieceM" + android:layout_height="@dimen/pieceM" + android:layout_margin="@dimen/margeM"/> @@ -54,11 +54,11 @@ android:id="@+id/bouton_valider_code" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_margin="@dimen/marge" + android:layout_margin="@dimen/margeM" android:text="Valider" android:textColor="@color/white" android:textAlignment="center" - android:textSize="@dimen/marge" + android:textSize="@dimen/margeM" android:background="@color/black" android:layout_alignParentLeft="true" android:layout_alignParentRight="true"/> diff --git a/app/src/main/res/layout/activity_master_mind.xml b/app/src/main/res/layout/activity_master_mind.xml index ce385f9..1d7bd55 100644 --- a/app/src/main/res/layout/activity_master_mind.xml +++ b/app/src/main/res/layout/activity_master_mind.xml @@ -1,9 +1,180 @@ - + android:background="@color/marron" + android:gravity="center_vertical" + > + - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 9e0283e..0e8dc37 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,5 +1,8 @@ - 50dp - 20dp + 40dp + 10dp + 20dp + 5dp + 30dp \ No newline at end of file