From 211dd04e8a8945237793e198a1a9b8c101da65e2 Mon Sep 17 00:00:00 2001 From: alpoint Date: Mon, 21 Mar 2022 13:47:17 +0100 Subject: [PATCH] Fix bug RecTap --- .../jeu_de_la_vie/view/LauncherActivity.java | 42 +------------------ .../iut/jeu_de_la_vie/view/PlateauView.java | 15 ++++++- .../view/fragment/FragmentPlateau.java | 14 ++++--- 3 files changed, 23 insertions(+), 48 deletions(-) diff --git a/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/LauncherActivity.java b/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/LauncherActivity.java index 8f143c5..e981440 100644 --- a/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/LauncherActivity.java +++ b/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/LauncherActivity.java @@ -7,6 +7,7 @@ import android.os.Bundle; import android.text.Editable; import android.util.DisplayMetrics; import android.util.Log; +import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; @@ -40,49 +41,10 @@ public class LauncherActivity extends AppCompatActivity { super.onCreate(savedInstanceState); manager = new Manager(); setContentView(R.layout.jeu_de_la_vie); - /* - //très moche à enlever plus tard - start = findViewById(R.id.startButton); - start.setOnClickListener(this::startGame); - /* - //manager.lancerJeu(); - start.setOnClickListener(l -> { - EditText colones = findViewById(R.id.nbColone); - //manager.getActualiseurCellule().getArbitre().getPlateau().setColone(Integer.parseInt(colones.getText().toString())); - EditText lignes = findViewById(R.id.nbLignes); - //manager.getActualiseurCellule().getArbitre().getPlateau().setLigne(Integer.parseInt(lignes.getText().toString())); - for (List list : manager.getActualiseurCellule().getArbitre().getPlateau().getGrille()) { - for (Cellule cell : list) { - Log.d("instances",cell.isAlive().toString()); - } - } - manager.lancerJeu(); - manager.update(); - }); - findViewById(R.id.test).setOnClickListener(y -> { - manager.getActualiseurCellule().getArbitre().getPlateau().setColone(2); - manager.getActualiseurCellule().getArbitre().getPlateau().setLigne(2); - manager.getActualiseurCellule().getArbitre().getPlateau().getCell(1, 1).setAlive(true); - //manager.getActualiseurCellule().getArbitre().getPlateau().getCell(0, 0).setAlive(true); - manager.getActualiseurCellule().getArbitre().getPlateau().getCell(1, 0).setAlive(true); - manager.getActualiseurCellule().getArbitre().getPlateau().getCell(0, 1).setAlive(true); - }); - */ DisplayMetrics disp = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(disp); width = disp.widthPixels; height = disp.heightPixels; - - - if(manager.isJeuLance()) { - - }else { - //getSupportFragmentManager().beginTransaction().add(R.id.menuView,MenuFragment.class,null).commit(); <-- cassait tout - } - } - - public void updateGame (){ - } @Override @@ -94,8 +56,6 @@ public class LauncherActivity extends AppCompatActivity { else if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){ isPortrait = false; } - //FragmentPlateau fragment = new FragmentPlateau(); - //fragment.setPlateau(manager.getActualiseurCellule().getArbitre().getPlateau()); } @Override diff --git a/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/PlateauView.java b/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/PlateauView.java index 35589ba..6c4df5f 100644 --- a/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/PlateauView.java +++ b/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/PlateauView.java @@ -58,13 +58,20 @@ public class PlateauView extends View implements ObserverCV { private int lignes; private int dethColor = Color.BLACK; private int modif = 80; + private boolean formule; public PlateauView(Context context, int colones, int lignes){ super(context); this.colones = colones; this.lignes = lignes; + int width = LauncherActivity.width; + int height = LauncherActivity.height; + formule = LauncherActivity.isPortrait ? width/colones < height/lignes : height/lignes >= width/colones; init(); } + public boolean isFormule(){ + return formule; + } private void init(){ colors = new HashMap<>(); @@ -93,14 +100,16 @@ public class PlateauView extends View implements ObserverCV { if (LauncherActivity.isPortrait) { if (width/colones < height/lignes) { - rect = new Rect(width / colones * j + (width / colones) * 5 / 100, width / colones * i + (width / colones) * 5 / 100, (width / colones * (j + 1)) - (width / colones) * 5 / 100, (width / colones * (i + 1)) - (width / colones) * 5 / 100); + rect = new Rect((width / colones) * j + (width / colones) * 5 / 100, width / colones * i + (width / colones) * 5 / 100, (width / colones * (j + 1)) - (width / colones) * 5 / 100, (width / colones * (i + 1)) - (width / colones) * 5 / 100); canvas.drawRect(rect, paint); Log.d("orientation", "portrait"); + formule = true; } else { - rect = new Rect((height-modif) / lignes * j + ((height-modif) / lignes) * 5 / 100, (height-modif) / lignes * i + ((height-modif) / lignes) * 5 / 100, ((height-modif) / lignes * (j + 1)) - ((height-modif) / lignes) * 5 / 100, ((height-modif) / lignes * (i + 1)) - ((height-modif) / lignes) * 5 / 100); + rect = new Rect(((height-modif) / lignes) * j + ((height-modif) / lignes) * 5 / 100, (height-modif) / lignes * i + ((height-modif) / lignes) * 5 / 100, ((height-modif) / lignes * (j + 1)) - ((height-modif) / lignes) * 5 / 100, ((height-modif) / lignes * (i + 1)) - ((height-modif) / lignes) * 5 / 100); canvas.drawRect(rect, paint); Log.d("orientation", "portrait"); + formule = false; } } else { @@ -108,11 +117,13 @@ public class PlateauView extends View implements ObserverCV { rect = new Rect((height - modif) / lignes * j + ((height - modif) / lignes) * 5 / 100, (height - modif) / lignes * i + ((height - modif) / lignes) * 5 / 100, ((height - modif) / lignes * (j + 1)) - ((height - modif) / lignes) * 5 / 100, ((height - modif) / lignes * (i + 1)) - ((height - modif) / lignes) * 5 / 100); canvas.drawRect(rect, paint); Log.d("orientation", "landscpape"); + formule = false; } else{ rect = new Rect(width / colones * j + (width / colones) * 5 / 100, width / colones * i + (width / colones) * 5 / 100, (width / colones * (j + 1)) - (width / colones) * 5 / 100, (width / colones * (i + 1)) - (width / colones) * 5 / 100); canvas.drawRect(rect, paint); Log.d("orientation", "landscpape"); + formule = true; } } } diff --git a/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/fragment/FragmentPlateau.java b/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/fragment/FragmentPlateau.java index b963363..de73236 100644 --- a/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/fragment/FragmentPlateau.java +++ b/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/fragment/FragmentPlateau.java @@ -65,14 +65,18 @@ public class FragmentPlateau extends Fragment implements ObserverBDJ { } private boolean tapRect(View view1, MotionEvent motionEvent){ - int x = (int) (( (float) manager.getNomberOfColumns() / view1.getWidth()) * motionEvent.getX()-5/100); - int y = (int) (( (float) manager.getNomberOfColumns() / view1.getWidth()) * motionEvent.getY()-5/100); - if (LauncherActivity.isPortrait) { - return tapRect(view1, x, y); + int x = -1; + int y = -1; + PlateauView plateauView = (PlateauView) view1; + if (plateauView.isFormule()) { + x = (int) (( (float) manager.getNomberOfColumns() / view1.getWidth()) * motionEvent.getX()-5/100); + y = (int) (( (float) manager.getNomberOfColumns() / view1.getWidth()) * motionEvent.getY()-5/100); } else { - return tapRect(view1, x, y); + x = (int) (( (float) manager.getNumberOfLines() / view1.getHeight()) * motionEvent.getX()-5/100); + y = (int) (( (float) manager.getNumberOfLines() / view1.getHeight() ) * motionEvent.getY()-5/100); } + return tapRect(view1, x, y); } private boolean tapRect(View view, int x, int y){ Log.d("D", "x=" + x);