Grille fonctionel

master
Allan POINT 4 years ago
parent b079cc5435
commit 7ecfcfbffc

@ -50,12 +50,11 @@
</ChoiceBox>
</HBox>
<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>
<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>
<Button fx:id="create" onAction="#createGrid">Create grid</Button>
<Button fx:id="play" onAction="#startGame">Play</Button>
<Button>Pause</Button>
<Button fx:id="random" onAction="#generateraRandom">Random</Button>

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

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

@ -21,6 +21,10 @@ public class CreateurCellule implements ICreateurCellule {
this.h = h;
}
public ListProperty<List<Cellule>> creerCellules(){
return creerCellules(w, h);
}
public ListProperty<List<Cellule>> creerCellules(int w, int h){
ObservableList<List<Cellule>> cellsInit = FXCollections.observableArrayList();
ListProperty<List<Cellule>> cells = new SimpleListProperty<>(cellsInit);
List<Cellule> tmp;
@ -33,4 +37,12 @@ public class CreateurCellule implements ICreateurCellule {
}
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,21 +7,22 @@ import model.cellule.créateur.CreateurCellule;
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); }
public int getLongueur() { return longueur.get();}
public void setLongueur(int valeur) { longueur.set(valeur); resetGrille(getLargeur(), valeur);}
public IntegerProperty longueurProperty() { return longueur; }
private IntegerProperty largeur = new SimpleIntegerProperty();
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; }
//private ObservableList<List<Cellule>> grilleObs = FXCollections.observableArrayList();
private ListProperty<List<Cellule>> grille = new SimpleListProperty<>();
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 ReadOnlyListProperty grilleProperty() { return grille; }
public void setGrille(ListProperty<List<Cellule>> cells) {grille.set(cells);}
public ReadOnlyListProperty grilleProperty() { return grille;}
public Cellule getCell(int x, int y) throws IllegalArgumentException{
if(x < 0 || y < 0) {
@ -36,12 +37,22 @@ public class Plateau implements PrototypePlateau{
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) {
createurCellule = new CreateurCellule(longueur, largeur);
setLargeur(largeur);
setLongueur(longueur);
CreateurCellule c = new CreateurCellule(longueur, largeur);
setGrille(c.creerCellules());
setGrille(createurCellule.creerCellules());
}
public Plateau(int longueur, int largeur, ListProperty<List<Cellule>> cellules)

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

Loading…
Cancel
Save