|
|
|
@ -14,17 +14,19 @@ import androidx.fragment.app.Fragment;
|
|
|
|
|
|
|
|
|
|
import projet.iut.jeu_de_la_vie.R;
|
|
|
|
|
import projet.iut.jeu_de_la_vie.model.Manager;
|
|
|
|
|
import projet.iut.jeu_de_la_vie.model.boucleDeJeu.observer.ObservableBDJ;
|
|
|
|
|
import projet.iut.jeu_de_la_vie.model.boucleDeJeu.observer.ObserverBDJ;
|
|
|
|
|
import projet.iut.jeu_de_la_vie.model.cellule.Cellule;
|
|
|
|
|
import projet.iut.jeu_de_la_vie.model.cellulesVivantes.observer.ObserverCV;
|
|
|
|
|
import projet.iut.jeu_de_la_vie.view.PlateauView;
|
|
|
|
|
|
|
|
|
|
public class FragmentPlateau extends Fragment implements ObserverCV {
|
|
|
|
|
public class FragmentPlateau extends Fragment implements ObserverBDJ {
|
|
|
|
|
|
|
|
|
|
private Manager manager;
|
|
|
|
|
public FragmentPlateau(){
|
|
|
|
|
super(R.layout.fragment_plateau); //<-- lui passer la future vue du jeu
|
|
|
|
|
manager = new Manager();
|
|
|
|
|
manager.getActualiseurCellule().getArbitre().getPlateau().getCellulesVivantes().attacher(this);
|
|
|
|
|
((ObservableBDJ) manager.getBoucleDeJeu()).attacher(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -41,7 +43,7 @@ public class FragmentPlateau extends Fragment implements ObserverCV {
|
|
|
|
|
PlateauView plateauView = view.findViewById(R.id.plateauView);
|
|
|
|
|
plateauView.setLignes(manager.getNumberOfLines());
|
|
|
|
|
plateauView.setColones(manager.getNomberOfColumns());
|
|
|
|
|
plateauView.setOnTouchListener(this::loadRect);
|
|
|
|
|
plateauView.setOnTouchListener(this::tapRect);
|
|
|
|
|
Button button = view.findViewById(R.id.startnstopButton);
|
|
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
@ -58,12 +60,12 @@ public class FragmentPlateau extends Fragment implements ObserverCV {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean loadRect(View view1, MotionEvent motionEvent){
|
|
|
|
|
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);
|
|
|
|
|
return loadRect(view1, x, y);
|
|
|
|
|
return tapRect(view1, x, y);
|
|
|
|
|
}
|
|
|
|
|
private boolean loadRect(View view, int x, int y){
|
|
|
|
|
private boolean tapRect(View view, int x, int y){
|
|
|
|
|
Log.d("D", "x=" + x);
|
|
|
|
|
Log.d("D", "y=" + y);
|
|
|
|
|
try {
|
|
|
|
@ -74,7 +76,6 @@ public class FragmentPlateau extends Fragment implements ObserverCV {
|
|
|
|
|
}else {
|
|
|
|
|
((PlateauView) view).delPosCell(cellule);
|
|
|
|
|
}
|
|
|
|
|
view.postInvalidate();
|
|
|
|
|
}catch (IllegalArgumentException e){
|
|
|
|
|
Log.w("WARNING", e.getMessage());
|
|
|
|
|
}
|
|
|
|
@ -87,15 +88,15 @@ public class FragmentPlateau extends Fragment implements ObserverCV {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void update(Cellule changingCell) {
|
|
|
|
|
View plateauView = getView().findViewById(R.id.plateauView);
|
|
|
|
|
if(plateauView != null) {
|
|
|
|
|
plateauView.post(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
loadRect(plateauView, changingCell.getPosition().getX(), changingCell.getPosition().getY());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
public void update() {
|
|
|
|
|
PlateauView view = (PlateauView) getView().findViewById(R.id.plateauView);
|
|
|
|
|
if(view == null){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
view.resetMap();
|
|
|
|
|
for (Cellule c: manager.getActualiseurCellule().getArbitre().getPlateau().getCellulesVivantes().getCells().values()) {
|
|
|
|
|
view.addPosCell(c);
|
|
|
|
|
}
|
|
|
|
|
view.postInvalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|