Grille fonctionel

master
Allan POINT 4 years ago
parent b079cc5435
commit 7ecfcfbffc

@ -50,12 +50,11 @@
</ChoiceBox> </ChoiceBox>
</HBox> </HBox>
<Label>Row</Label> <Label>Row</Label>
<Spinner editable="true" fx:id="rowGame" initialValue="15" amountToStepBy="5" min="0" max="100"/> <Spinner editable="true" fx:id="rowGame" amountToStepBy="5" min="0" max="100" />
<Label>Column</Label> <Label>Column</Label>
<Spinner editable="true" fx:id="colGame" initialValue="15" amountToStepBy="5" min="0" max="100"/> <Spinner editable="true" fx:id="colGame" amountToStepBy="5" min="0" max="100" />
<HBox> <HBox>
<Button fx:id="create" onAction="#createGrid">Create grid</Button>
<Button fx:id="play" onAction="#startGame">Play</Button> <Button fx:id="play" onAction="#startGame">Play</Button>
<Button>Pause</Button> <Button>Pause</Button>
<Button fx:id="random" onAction="#generateraRandom">Random</Button> <Button fx:id="random" onAction="#generateraRandom">Random</Button>

@ -9,7 +9,6 @@ import model.boucleDeJeu.observer.ObserverBDJ;
import model.plateau.Plateau; import model.plateau.Plateau;
public class Manager implements ObserverBDJ { public class Manager implements ObserverBDJ {
private Plateau plateau;
private ActualiseurTour actualiseurTour; private ActualiseurTour actualiseurTour;
private ActualiseurCellule actualiseurCellule; private ActualiseurCellule actualiseurCellule;
private IBoucleDeJeu boucleDeJeu; private IBoucleDeJeu boucleDeJeu;
@ -55,7 +54,7 @@ public class Manager implements ObserverBDJ {
jeuLance = false; jeuLance = false;
} }
public void setPlateau(Plateau plateau) { //public void setPlateau(Plateau plateau) {
this.plateau = plateau; //this.plateau = plateau;
} //}
} }

@ -32,6 +32,7 @@ public class Cellule extends ObservableCellule {
*/ */
public Cellule(int x, int y) throws IllegalArgumentException { public Cellule(int x, int y) throws IllegalArgumentException {
deathColor = Color.BLACK; deathColor = Color.BLACK;
activeColorProperty().setValue(deathColor);
position = new Position(x,y); position = new Position(x,y);
} }

@ -21,6 +21,10 @@ public class CreateurCellule implements ICreateurCellule {
this.h = h; this.h = h;
} }
public ListProperty<List<Cellule>> creerCellules(){ public ListProperty<List<Cellule>> creerCellules(){
return creerCellules(w, h);
}
public ListProperty<List<Cellule>> creerCellules(int w, int h){
ObservableList<List<Cellule>> cellsInit = FXCollections.observableArrayList(); ObservableList<List<Cellule>> cellsInit = FXCollections.observableArrayList();
ListProperty<List<Cellule>> cells = new SimpleListProperty<>(cellsInit); ListProperty<List<Cellule>> cells = new SimpleListProperty<>(cellsInit);
List<Cellule> tmp; List<Cellule> tmp;
@ -33,4 +37,12 @@ public class CreateurCellule implements ICreateurCellule {
} }
return cells; return cells;
} }
public List<Cellule> creerLigneCellule(int longeure){
List<Cellule> cells = new LinkedList<>();
for(int i=0; i<longeure; ++i){
cells.add(new Cellule(i, longeure));
}
++h;
return cells;
}
} }

@ -7,20 +7,21 @@ import model.cellule.créateur.CreateurCellule;
import java.util.List; import java.util.List;
public class Plateau implements PrototypePlateau{ public class Plateau implements PrototypePlateau{
private CreateurCellule createurCellule;
private IntegerProperty longueur = new SimpleIntegerProperty(); private IntegerProperty longueur = new SimpleIntegerProperty();
public int getLongueur() { return longueur.get();} public int getLongueur() { return longueur.get();}
public void setLongueur(int valeur) { longueur.set(valeur); } public void setLongueur(int valeur) { longueur.set(valeur); resetGrille(getLargeur(), valeur);}
public IntegerProperty longueurProperty() { return longueur; } public IntegerProperty longueurProperty() { return longueur; }
private IntegerProperty largeur = new SimpleIntegerProperty(); private IntegerProperty largeur = new SimpleIntegerProperty();
public int getLargeur() { return largeur.get(); } public int getLargeur() { return largeur.get(); }
public void setLargeur( int valeur ) { largeur.set(valeur); } public void setLargeur( int valeur ) { largeur.set(valeur); resetGrille(valeur, getLongueur());}
public IntegerProperty largeurProperty() { return largeur; } public IntegerProperty largeurProperty() { return largeur; }
//private ObservableList<List<Cellule>> grilleObs = FXCollections.observableArrayList(); //private ObservableList<List<Cellule>> grilleObs = FXCollections.observableArrayList();
private ListProperty<List<Cellule>> grille = new SimpleListProperty<>(); private ListProperty<List<Cellule>> grille = new SimpleListProperty<>();
public ListProperty<List<Cellule>> getGrille() { return (ListProperty<List<Cellule>>) grille.get(); } public ListProperty<List<Cellule>> getGrille() { return (ListProperty<List<Cellule>>) grille.get(); }
public void setGrille(ListProperty<List<Cellule>> cells) {grille.set(cells);setLongueur(cells.size()); setLargeur(cells.size());} public void setGrille(ListProperty<List<Cellule>> cells) {grille.set(cells);}
public ReadOnlyListProperty grilleProperty() { return grille;} public ReadOnlyListProperty grilleProperty() { return grille;}
public Cellule getCell(int x, int y) throws IllegalArgumentException{ public Cellule getCell(int x, int y) throws IllegalArgumentException{
@ -36,12 +37,22 @@ public class Plateau implements PrototypePlateau{
return grille.get().get(y).get(x); return grille.get().get(y).get(x);
} }
public Plateau(){setGrille(new SimpleListProperty<>());} public void resetGrille(){
resetGrille(getLargeur(), getLongueur());
}
public void resetGrille(int w, int h){
setGrille(createurCellule.creerCellules(w, h));
}
public Plateau(){
createurCellule = new CreateurCellule(0, 0);
setGrille(new SimpleListProperty<>());
}
public Plateau(int longueur, int largeur) { public Plateau(int longueur, int largeur) {
createurCellule = new CreateurCellule(longueur, largeur);
setLargeur(largeur); setLargeur(largeur);
setLongueur(longueur); setLongueur(longueur);
CreateurCellule c = new CreateurCellule(longueur, largeur); setGrille(createurCellule.creerCellules());
setGrille(c.creerCellules());
} }
public Plateau(int longueur, int largeur, ListProperty<List<Cellule>> cellules) public Plateau(int longueur, int largeur, ListProperty<List<Cellule>> cellules)

@ -59,13 +59,12 @@ public class VueJeu {
}*/ }*/
map.getChildren().clear(); map.getChildren().clear();
for(int i=0; i < rowGame.getValue().intValue(); ++i) { for(int i=0; i < colGame.getValue().intValue(); ++i) {
for(int j=0; j < colGame.getValue().intValue(); ++j) { for(int j=0; j < rowGame.getValue().intValue(); ++j) {
Rectangle rect = new Rectangle(15, 15, color.getValue()); Rectangle rect = new Rectangle(15, 15, color.getValue());
plateau = new Plateau(i,j); //manager.getActualiseurCellule().getArbitre().getPlateau().getCell(j, i).activeColorProperty().bindBidirectional(rect.fillProperty());
manager.setPlateau(plateau); rect.fillProperty().bindBidirectional(manager.getActualiseurCellule().getArbitre().getPlateau().getCell(j, i).activeColorProperty());
//rect.fillProperty().bindBidirectional(manager.getActualiseurCellule().getArbitre().getPlateau().getCell(j, i).activeColorProperty()); //rect.setOnMouseClicked(event -> changeColor(event));
rect.setOnMouseClicked(event -> changeColor(event));
map.add(rect, i, j); map.add(rect, i, j);
} }
} }
@ -95,12 +94,13 @@ public class VueJeu {
public void initialize() { public void initialize() {
manager = new Manager(); manager = new Manager();
deathColor = Color.BLACK; deathColor = Color.BLACK;
rowGame.getValueFactory().valueProperty().bindBidirectional((Property) manager.getActualiseurCellule().getArbitre().getPlateau().longueurProperty()); rowGame.getValueFactory().valueProperty().bindBidirectional((Property) manager.getActualiseurCellule().getArbitre().getPlateau().largeurProperty());
colGame.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());
color.valueProperty().bindBidirectional(Cellule.livingColorProperty()); color.valueProperty().bindBidirectional(Cellule.livingColorProperty());
plateau = new Plateau(rowGame.getValue().intValue(), colGame.getValue().intValue());
createGrid(); // createGrid();
nbColGame.setText(colGame.getValue().toString()); nbColGame.setText(colGame.getValue().toString());
nbRowGame.setText(rowGame.getValue().toString()); nbRowGame.setText(rowGame.getValue().toString());
@ -109,4 +109,9 @@ public class VueJeu {
public void startGame(ActionEvent actionEvent) { public void startGame(ActionEvent actionEvent) {
manager.lancerJeu(); manager.lancerJeu();
} }
public void resetGrid(){
manager.getActualiseurCellule().getArbitre().getPlateau().resetGrille();
createGrid();
}
} }

Loading…
Cancel
Save