diff --git a/code/jeu de la vie/src/model/CellulesVivantes.java b/code/jeu de la vie/src/model/CellulesVivantes.java index d1d7c90..b7d24f5 100644 --- a/code/jeu de la vie/src/model/CellulesVivantes.java +++ b/code/jeu de la vie/src/model/CellulesVivantes.java @@ -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<>(); } } diff --git a/code/jeu de la vie/src/model/Manager.java b/code/jeu de la vie/src/model/Manager.java index fc58f68..b39d3c6 100644 --- a/code/jeu de la vie/src/model/Manager.java +++ b/code/jeu de la vie/src/model/Manager.java @@ -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 getArbitre().getPlateau().getCell(x, y).setAlive(false); case LIVE, BIRTH -> getArbitre().getPlateau().getCell(x, y).setAlive(true); } diff --git a/code/jeu de la vie/src/model/arbitre/Arbitre.java b/code/jeu de la vie/src/model/arbitre/Arbitre.java index 49719df..d9ef704 100644 --- a/code/jeu de la vie/src/model/arbitre/Arbitre.java +++ b/code/jeu de la vie/src/model/arbitre/Arbitre.java @@ -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); } diff --git a/code/jeu de la vie/src/model/arbitre/ArbitreConwayStyle.java b/code/jeu de la vie/src/model/arbitre/ArbitreConwayStyle.java index f066bc7..f4c3165 100644 --- a/code/jeu de la vie/src/model/arbitre/ArbitreConwayStyle.java +++ b/code/jeu de la vie/src/model/arbitre/ArbitreConwayStyle.java @@ -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) { diff --git a/code/jeu de la vie/src/model/cellule/créateur/CreateurCellule.java b/code/jeu de la vie/src/model/cellule/créateur/CreateurCellule.java index 6b105d2..b796f2b 100644 --- a/code/jeu de la vie/src/model/cellule/créateur/CreateurCellule.java +++ b/code/jeu de la vie/src/model/cellule/créateur/CreateurCellule.java @@ -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> creerCellules(int w, int h, CellulesVivantes observer){ + public ListProperty> creerCellules(int colone, int ligne, CellulesVivantes observer){ ObservableList> cellsInit = FXCollections.observableArrayList(); ListProperty> cells = new SimpleListProperty<>(cellsInit); List 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 creerLigneCellule(int longeure){ + public List creerLigneCellule(int ligne){ List cells = new LinkedList<>(); - for(int i=0; i> grilleObs = FXCollections.observableArrayList(); private ListProperty> 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> cellules) + public Plateau(int colone, int ligne, ListProperty> 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() { diff --git a/code/jeu de la vie/src/views/VueJeu.java b/code/jeu de la vie/src/views/VueJeu.java index 74dc7d2..d1a34d3 100644 --- a/code/jeu de la vie/src/views/VueJeu.java +++ b/code/jeu de la vie/src/views/VueJeu.java @@ -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) {