Ça marche pour de vrai cette foi ^^'

master
Allan POINT 4 years ago
parent d0b01a9de0
commit 72cea8d78f

@ -38,6 +38,10 @@ public class CellulesVivantes implements ObserverCellule {
}
public CellulesVivantes clone(){
return new CellulesVivantes(cellVivantes);
return new CellulesVivantes(new HashMap<>(cellVivantes));
}
public void reset(){
cellVivantes = new HashMap<>();
}
}

@ -3,7 +3,6 @@ package model;
import model.actualiseur.ActualiseurCellule;
import model.actualiseur.ActualiseurTour;
import model.actualiseur.ActualiseurTourUnParUn;
import model.boucleDeJeu.BoucleDeJeu30FPS;
import model.boucleDeJeu.BoucleDeJeu5FPS;
import model.boucleDeJeu.IBoucleDeJeu;
import model.boucleDeJeu.observer.ObservableBDJ;
@ -42,11 +41,13 @@ public class Manager implements ObserverBDJ {
}
private void deleguerChangementCellule() {
for (int y=0; y<actualiseurCellule.getArbitre().getPlateau().getLargeur(); ++y){
for(int x=0; x<actualiseurCellule.getArbitre().getPlateau().getLongueur(); ++x){
actualiseurCellule.changerCellule(x, y);
CellulesVivantes reference = getActualiseurCellule().getArbitre().getPlateau().getCellulesVivantes().clone();
for (int y = 0; y<actualiseurCellule.getArbitre().getPlateau().getLigne(); ++y){
for(int x = 0; x<actualiseurCellule.getArbitre().getPlateau().getColone(); ++x){
actualiseurCellule.changerCellule(x, y, reference);
}
}
}
public void inverserEtatCellule(Cellule c){
getActualiseurCellule().getArbitre().getPlateau().getCell(c.getPosition().getX(), c.getPosition().getY()).inverseAlive();
@ -63,6 +64,7 @@ public class Manager implements ObserverBDJ {
public void stoperJeu(){
actualiseurTour.resetTour();
actualiseurCellule.getArbitre().getPlateau().getCellulesVivantes().reset();
jeuLance = false;
}

@ -1,11 +1,12 @@
package model.actualiseur;
import model.CellulesVivantes;
import model.arbitre.Arbitre;
import model.plateau.Plateau;
public abstract class ActualiseurCellule {
private Arbitre arbitre;
public abstract void changerCellule(int x, int y);
public abstract void changerCellule(int x, int y, CellulesVivantes reference);
ActualiseurCellule(Arbitre arbitre) throws IllegalArgumentException{
if(arbitre == null) {

@ -1,5 +1,6 @@
package model.actualiseur;
import model.CellulesVivantes;
import model.arbitre.Arbitre;
public class ActualiseurEtatCellule extends ActualiseurCellule{
@ -7,8 +8,8 @@ public class ActualiseurEtatCellule extends ActualiseurCellule{
super(a);
}
@Override
public void changerCellule(int x, int y) {
switch(getArbitre().verifierChangementCellules(x, y)) {
public void changerCellule(int x, int y, CellulesVivantes reference) {
switch(getArbitre().verifierChangementCellules(x, y, reference)) {
case DIE -> getArbitre().getPlateau().getCell(x, y).setAlive(false);
case LIVE, BIRTH -> getArbitre().getPlateau().getCell(x, y).setAlive(true);
}

@ -21,5 +21,5 @@ public abstract class Arbitre {
protected CompteurDeCellule getCompteurCell(){
return compteurCell;
}
public abstract CellState verifierChangementCellules(int x, int y);
public abstract CellState verifierChangementCellules(int x, int y, CellulesVivantes reference);
}

@ -12,14 +12,14 @@ public class ArbitreConwayStyle extends Arbitre{
}
@Override
public CellState verifierChangementCellules(int x, int y) {
if(verifierNaissance(x, y, getPlateau().getCellulesVivantes().clone())) {
public CellState verifierChangementCellules(int x, int y, CellulesVivantes reference) {
if(verifierNaissance(x, y, reference)) {
return CellState.BIRTH;
}
if(verifierMort(x, y, getPlateau().getCellulesVivantes())) {
if(verifierMort(x, y, reference)) {
return CellState.DIE;
}
return getPlateau().getCell(x, y).isAlive() ? CellState.LIVE : CellState.DIE;
return reference.getAt(x, y) != null ? CellState.LIVE : CellState.DIE;
}
private boolean verifierNaissance(int x, int y, CellulesVivantes reference) {

@ -15,7 +15,7 @@ public class CreateurCellule implements ICreateurCellule {
private int h;
public CreateurCellule(int w, int h) throws IllegalArgumentException{
if(w < 0 || h<0){
if(w<0 || h<0){
throw new IllegalArgumentException("La longueur et la largeur doivent être supperieur à 0");
}
this.w = w;
@ -25,14 +25,14 @@ public class CreateurCellule implements ICreateurCellule {
return creerCellules(w, h, observer);
}
public ListProperty<List<Cellule>> creerCellules(int w, int h, CellulesVivantes observer){
public ListProperty<List<Cellule>> creerCellules(int colone, int ligne, CellulesVivantes observer){
ObservableList<List<Cellule>> cellsInit = FXCollections.observableArrayList();
ListProperty<List<Cellule>> cells = new SimpleListProperty<>(cellsInit);
List<Cellule> tmp;
Cellule c;
for (int i = 0; i < h; i++) {
for (int i = 0; i < ligne; i++) {
tmp = new LinkedList<>();
for (int j = 0; j < w; j++) {
for (int j = 0; j < colone; j++) {
c = new Cellule(j, i);
c.attacher(observer);
tmp.add(c);
@ -41,10 +41,10 @@ public class CreateurCellule implements ICreateurCellule {
}
return cells;
}
public List<Cellule> creerLigneCellule(int longeure){
public List<Cellule> creerLigneCellule(int ligne){
List<Cellule> cells = new LinkedList<>();
for(int i=0; i<longeure; ++i){
cells.add(new Cellule(i, longeure));
for(int i=0; i<ligne; ++i){
cells.add(new Cellule(i, ligne));
}
++h;
return cells;

@ -9,15 +9,15 @@ import java.util.List;
public class Plateau implements PrototypePlateau{
private CreateurCellule createurCellule;
private IntegerProperty longueur = new SimpleIntegerProperty();
public int getLongueur() { return longueur.get();}
public void setLongueur(int valeur) { longueur.set(valeur); resetGrille(getLargeur(), valeur);}
public IntegerProperty longueurProperty() { return longueur; }
private IntegerProperty colone = new SimpleIntegerProperty();
public int getColone() { return colone.get();}
public void setColone(int valeur) { colone.set(valeur); resetGrille(valeur, getLigne());}
public IntegerProperty coloneProperty() { return colone; }
private IntegerProperty largeur = new SimpleIntegerProperty();
public int getLargeur() { return largeur.get(); }
public void setLargeur( int valeur ) { largeur.set(valeur); resetGrille(valeur, getLongueur());}
public IntegerProperty largeurProperty() { return largeur; }
private IntegerProperty ligne = new SimpleIntegerProperty();
public int getLigne() { return ligne.get(); }
public void setLigne(int valeur ) { ligne.set(valeur); resetGrille(getColone(), valeur);}
public IntegerProperty ligneProperty() { return ligne; }
//private ObservableList<List<Cellule>> grilleObs = FXCollections.observableArrayList();
private ListProperty<List<Cellule>> grille = new SimpleListProperty<>();
@ -40,10 +40,10 @@ public class Plateau implements PrototypePlateau{
}
public void resetGrille(){
resetGrille(getLargeur(), getLongueur());
resetGrille(getColone(), getLigne());
}
public void resetGrille(int w, int h){
setGrille(createurCellule.creerCellules(w, h, cellulesVivantes));
public void resetGrille(int colone, int ligne){
setGrille(createurCellule.creerCellules(colone, ligne, cellulesVivantes));
}
public Plateau(){
@ -51,26 +51,26 @@ public class Plateau implements PrototypePlateau{
cellulesVivantes = new CellulesVivantes();
setGrille(new SimpleListProperty<>());
}
public Plateau(int longueur, int largeur) {
this(longueur, largeur, new CellulesVivantes());
public Plateau(int colone, int ligne) {
this(colone, ligne, new CellulesVivantes());
}
public Plateau(int longueur, int largeur, CellulesVivantes observer) {
createurCellule = new CreateurCellule(longueur, largeur);
setLargeur(largeur);
setLongueur(longueur);
public Plateau(int colone, int ligne, CellulesVivantes observer) {
createurCellule = new CreateurCellule(colone, ligne);
setLigne(ligne);
setColone(colone);
cellulesVivantes = observer;
setGrille(createurCellule.creerCellules(cellulesVivantes));
}
public Plateau(int longueur, int largeur, ListProperty<List<Cellule>> cellules)
public Plateau(int colone, int ligne, ListProperty<List<Cellule>> cellules)
{
this(longueur, largeur);
this(colone, ligne);
setGrille(cellules);
}
@Override
public Plateau cloner() {
return new Plateau(getLongueur(), getLargeur(), getGrille());
return new Plateau(getColone(), getLigne(), getGrille());
}
public CellulesVivantes getCellulesVivantes() {

@ -2,14 +2,11 @@ package views;
import javafx.beans.property.Property;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.Label;
import javafx.scene.control.Spinner;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
@ -51,34 +48,34 @@ public class VueJeu {
public void createGrid() {
map.getChildren().clear();
for(int i=0; i < colGame.getValue().intValue(); ++i) {
for(int j=0; j < rowGame.getValue().intValue(); ++j) {
for(int i=0; i < rowGame.getValue().intValue(); ++i) {
for(int j=0; j < colGame.getValue().intValue(); ++j) {
Rectangle rect = new Rectangle(15, 15, color.getValue());
Cellule c = manager.getActualiseurCellule().getArbitre().getPlateau().getCell(j, i);
rect.fillProperty().bindBidirectional(c.activeColorProperty());
rect.setOnMouseClicked((src)->manager.inverserEtatCellule(c));
map.add(rect, i, j);
map.add(rect, j, i);
}
}
}
public void generateraRandom() {
resetGrid();
int largeur = manager.getActualiseurCellule().getArbitre().getPlateau().getLargeur();
int longueur = manager.getActualiseurCellule().getArbitre().getPlateau().getLongueur();
for(int i=0; i<(longueur+largeur)/2; ++i) {
int ligne = manager.getActualiseurCellule().getArbitre().getPlateau().getLigne();
int colone = manager.getActualiseurCellule().getArbitre().getPlateau().getColone();
for(int i=0; i<(colone+ligne)/2; ++i) {
Random random = new Random();
manager.getActualiseurCellule().getArbitre().getPlateau().getCell(random.nextInt(longueur), random.nextInt(largeur)).setAlive(true);
manager.getActualiseurCellule().getArbitre().getPlateau().getCell(random.nextInt(colone), random.nextInt(ligne)).setAlive(true);
}
}
public void initialize() {
manager = new Manager();
deathColor = Color.BLACK;
rowGame.getValueFactory().valueProperty().bindBidirectional((Property) manager.getActualiseurCellule().getArbitre().getPlateau().largeurProperty());
colGame.getValueFactory().valueProperty().bindBidirectional((Property) manager.getActualiseurCellule().getArbitre().getPlateau().longueurProperty());
manager.getActualiseurCellule().getArbitre().getPlateau().longueurProperty().addListener((src)->resetGrid());
manager.getActualiseurCellule().getArbitre().getPlateau().largeurProperty().addListener((src)->resetGrid());
rowGame.getValueFactory().valueProperty().bindBidirectional((Property) manager.getActualiseurCellule().getArbitre().getPlateau().ligneProperty());
colGame.getValueFactory().valueProperty().bindBidirectional((Property) manager.getActualiseurCellule().getArbitre().getPlateau().coloneProperty());
manager.getActualiseurCellule().getArbitre().getPlateau().coloneProperty().addListener((src)->resetGrid());
manager.getActualiseurCellule().getArbitre().getPlateau().ligneProperty().addListener((src)->resetGrid());
colGame.getValueFactory().setValue(10);
rowGame.getValueFactory().setValue(10);
@ -87,8 +84,8 @@ public class VueJeu {
nbColGame.setText(colGame.getValue().toString());
nbRowGame.setText(rowGame.getValue().toString());
numTour.textProperty().bind(((ActualiseurTourUnParUn)manager.getActualiseurTour()).cptTourProperty().asString());
nbColGame.textProperty().bind(manager.getActualiseurCellule().getArbitre().getPlateau().longueurProperty().asString());
nbRowGame.textProperty().bind(manager.getActualiseurCellule().getArbitre().getPlateau().largeurProperty().asString());
nbColGame.textProperty().bind(manager.getActualiseurCellule().getArbitre().getPlateau().coloneProperty().asString());
nbRowGame.textProperty().bind(manager.getActualiseurCellule().getArbitre().getPlateau().ligneProperty().asString());
}
public void startGame(ActionEvent actionEvent) {

Loading…
Cancel
Save