Start binding plateauView

main
Allan POINT 3 years ago
parent 32da6e2ac7
commit dd279c0724

@ -36,6 +36,10 @@ public class Manager implements ObserverBDJ {
jeuLance = false;
}
public void updateOnCellBeforeStart(int x, int y){
getActualiseurCellule().inverserCellule(x, y);
}
/**
* Change l'actualiseur de cellule en fonction des règles
*/

@ -18,6 +18,7 @@ public abstract class ActualiseurCellule {
* @param reference CellulesVivantes au début du tour qui sert de référence
*/
public abstract void changerCellule(int x, int y, CellulesVivantes reference);
public abstract void inverserCellule(int x, int y);
ActualiseurCellule(Arbitre arbitre) throws IllegalArgumentException{
if(arbitre == null) {

@ -31,4 +31,9 @@ public class ActualiseurEtatCellule extends ActualiseurCellule{
break;
}
}
@Override
public void inverserCellule(int x, int y) {
getArbitre().getPlateau().inverserCellule(x, y);
}
}

@ -136,4 +136,8 @@ public class Plateau implements PrototypePlateau{
public CellulesVivantes getCellulesVivantes() {
return cellulesVivantes;
}
public void inverserCellule(int x, int y){
getCell(x, y).inverseAlive();
}
}

@ -10,12 +10,14 @@ import android.os.Build;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.view.WindowManager;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.view.MotionEventCompat;
import java.util.HashMap;
import java.util.LinkedList;
@ -35,32 +37,35 @@ public class PlateauView extends View implements ObserverCV {
public PlateauView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
Log.d("fragment","constructeur");
init();
}
public PlateauView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public PlateauView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private Paint paint = new Paint();
private int colones;
private int lignes;
private int dethColor = Color.BLACK;
private int width;
private int height;
public PlateauView(Context context, int colones, int lignes){
super(context);
colors = new HashMap<>();
paint = new Paint();
this.colones = colones;
this.lignes = lignes;
init();
}
private void init(){
colors = new HashMap<>();
paint = new Paint();
this.dethColor = Color.BLACK;
}
@ -72,13 +77,14 @@ public class PlateauView extends View implements ObserverCV {
Rect rect;
for(int i=0; i<lignes; ++i){
for(int j=0; j<colones; ++j){
//tmp = colors.get(p);
Position p = new Position(j, i);
tmp = colors.get(p);
paint.setColor(dethColor);
/*
if(tmp instanceof Integer){
paint.setColor(tmp);
}
*/
int width = LauncherActivity.width;
Log.d("affichage",""+LauncherActivity.isPortrait);
if (LauncherActivity.isPortrait) {
@ -104,6 +110,10 @@ public class PlateauView extends View implements ObserverCV {
}
}
public void addPosCell(int x, int y){
//TODO: Récup la céllue et ajouter dans colors
}
public void setColones(int value) throws IllegalArgumentException{
if(value < 0){
throw new IllegalArgumentException("La valeur des colones doit être supperieur à 0");
@ -117,12 +127,4 @@ public class PlateauView extends View implements ObserverCV {
}
lignes = value;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
}

@ -4,6 +4,7 @@ import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import androidx.annotation.NonNull;
@ -46,11 +47,24 @@ public class FragmentPlateau extends Fragment {
PlateauView plateauView = view.findViewById(R.id.plateauView);
plateauView.setLignes(manager.getNumberOfLines());
plateauView.setColones(manager.getNomberOfColumns());
plateauView.setOnTouchListener((view1, 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);
Log.d("D", "x=" + x);
Log.d("D", "y=" + y);
try {
manager.updateOnCellBeforeStart(x, y);
view1.postInvalidate();
}catch (IllegalArgumentException e){
Log.w("WARNING", e.getMessage());
}
return false;
});
}
@Override
public void onInflate(@NonNull Context context, @NonNull AttributeSet attrs, @Nullable Bundle savedInstanceState) {
super.onInflate(context, attrs, savedInstanceState);
}
}

Loading…
Cancel
Save