debut choix du code

This commit is contained in:
martins 2023-04-06 22:51:16 +02:00
parent ab5eab9bb0
commit b97998c1f7
14 changed files with 270 additions and 55 deletions

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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;
}
}
}

View File

@ -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();
}
}

View File

@ -1,9 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:background="@color/marron"
android:gravity="center"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
</RelativeLayout>
<com.example.mastermind.vue.mastermind.UnePiece
android:id="@+id/code1"
android:layout_width="@dimen/piece"
android:layout_height="@dimen/piece"
android:layout_margin="@dimen/marge"/>
<com.example.mastermind.vue.mastermind.UnePiece
android:id="@+id/code2"
android:layout_width="@dimen/piece"
android:layout_height="@dimen/piece"
android:layout_margin="@dimen/marge"
android:layout_toRightOf="@id/code1"/>
<com.example.mastermind.vue.mastermind.UnePiece
android:id="@+id/code3"
android:layout_width="@dimen/piece"
android:layout_height="@dimen/piece"
android:layout_margin="@dimen/marge"
android:layout_toRightOf="@id/code2"/>
<com.example.mastermind.vue.mastermind.UnePiece
android:id="@+id/code4"
android:layout_width="@dimen/piece"
android:layout_height="@dimen/piece"
android:layout_margin="@dimen/marge"
android:layout_toRightOf="@id/code3"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/bouton_valider_code"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="@dimen/marge"
android:text="Valider"
android:textColor="@color/white"
android:textAlignment="center"
android:textSize="@dimen/marge"
android:background="@color/black"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</LinearLayout>

View File

@ -30,14 +30,14 @@
<Button
android:id="@+id/unJoueur"
android:layout_width="0dp"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:textSize="30dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginHorizontal="40dp"
android:background="@color/marron"
android:text="Un Joueur"/>
android:background="@color/purple_200"
android:text="Un Joueur"
android:textSize="30dp" />
<Button
android:id="@+id/deuxJoueur"
@ -49,7 +49,7 @@
android:layout_marginTop="50dp"
android:layout_below="@+id/unJoueur"
android:layout_marginHorizontal="40dp"
android:background="@color/marron"
android:background="@color/purple_200"
android:textSize="30dp"
android:text="Deux Joueur"/>

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".vue.mastermind.setting.SettingActivity">
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="piece">50dp</dimen>
<dimen name="marge">20dp</dimen>
</resources>