Skip to content

Commit

Permalink
initial params window template created
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrMakarewicz committed Dec 20, 2020
1 parent dac82b4 commit 2bcba04
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 23 deletions.
4 changes: 0 additions & 4 deletions src/sample/Controller.java

This file was deleted.

55 changes: 55 additions & 0 deletions src/sample/InitialParamsWindowController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package sample;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;

public class InitialParamsWindowController {

@FXML
private ResourceBundle resources;

@FXML
private URL location;

@FXML
private Spinner<Integer> initialAnimalsSpinner;

@FXML
private Spinner<Integer> plantEnergySpinner;

@FXML
private Spinner<Integer> moveEnergySpinner;

@FXML
private Spinner<Double> jungleRatioSpinner;

@FXML
private Spinner<Integer> boardHeightSpinner;

@FXML
private Spinner<Integer> boardWidthSpinner;

@FXML
private Button startSimulationButton;

@FXML
void initialize() {
assert initialAnimalsSpinner != null : "fx:id=\"initialAnimalsSpinner\" was not injected: check your FXML file 'initialParamsWindow.fxml'.";
assert plantEnergySpinner != null : "fx:id=\"plantEnergySpinner\" was not injected: check your FXML file 'initialParamsWindow.fxml'.";
assert moveEnergySpinner != null : "fx:id=\"moveEnergySpinner\" was not injected: check your FXML file 'initialParamsWindow.fxml'.";
assert jungleRatioSpinner != null : "fx:id=\"jungleRatioSpinner\" was not injected: check your FXML file 'initialParamsWindow.fxml'.";
assert boardHeightSpinner != null : "fx:id=\"boardHeightSpinner\" was not injected: check your FXML file 'initialParamsWindow.fxml'.";
assert boardWidthSpinner != null : "fx:id=\"boardWidthSpinner\" was not injected: check your FXML file 'initialParamsWindow.fxml'.";
assert startSimulationButton != null : "fx:id=\"startSimulationButton\" was not injected: check your FXML file 'initialParamsWindow.fxml'.";
initialAnimalsSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 25,10));
plantEnergySpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 100,50));
moveEnergySpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 100,10));
jungleRatioSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0.1, 0.9,0.5,0.01));
boardHeightSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(10, 100));
boardWidthSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(10, 100));
}
}

16 changes: 9 additions & 7 deletions src/sample/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@
public class Main extends Application {

@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
public void start(Stage stage) throws Exception{
Parent loader = FXMLLoader.load(getClass().getResource("initialParamsWindow.fxml"));
stage.setTitle("Evolution Simulator");
stage.setScene(new Scene(loader));
stage.setResizable(false);
stage.show();
}


public static void main(String[] args) {
Simulation simulation = new Simulation("Sysad",3,3,0.3,5,100,8, 100);
simulation.start();
launch(args);
// Simulation simulation = new Simulation("Sysad",3,3,0.3,5,100,8, 100);
// simulation.start();
//launch(args);
}
}
24 changes: 24 additions & 0 deletions src/sample/initialParamsWindow.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.layout.Pane?>

<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="245.0" prefWidth="261.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.InitialParamsWindowController">
<children>
<Spinner fx:id="initialAnimalsSpinner" layoutX="162.0" layoutY="80.0" maxWidth="75.0" />
<Label layoutX="20.0" layoutY="83.0" text="Initial number of animals" />
<Spinner fx:id="plantEnergySpinner" layoutX="162.0" layoutY="110.0" maxWidth="75.0" />
<Label layoutX="20.0" layoutY="113.0" text="Plant energy" />
<Spinner fx:id="moveEnergySpinner" layoutX="162.0" layoutY="140.0" maxWidth="75.0" />
<Label layoutX="20.0" layoutY="143.0" text="Move energy" />
<Spinner fx:id="jungleRatioSpinner" layoutX="162.0" layoutY="170.0" maxWidth="75.0" />
<Label layoutX="20.0" layoutY="173.0" text="Jungle ratio" />
<Spinner fx:id="boardHeightSpinner" layoutX="162.0" layoutY="50.0" maxWidth="75.0" />
<Label layoutX="20.0" layoutY="53.0" text="Board height" />
<Spinner fx:id="boardWidthSpinner" layoutX="162.0" layoutY="20.0" maxWidth="75.0" />
<Label layoutX="20.0" layoutY="23.0" text="Board width" />
<Button fx:id="startSimulationButton" layoutX="162.0" layoutY="200.0" maxWidth="75.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="75.0" text="Start!" />
</children>
</Pane>
8 changes: 0 additions & 8 deletions src/sample/sample.fxml

This file was deleted.

7 changes: 3 additions & 4 deletions src/simulation/Simulation.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Simulation(String name, int width, int height, double jungleRatio, double
this.jungle = new Jungle(width,height,jungleRatio);
this.moveEnergy = moveEnergy;
this.plantEnergy = plantEnergy;
this.minimalReproduceEnergy = 2*moveEnergy;
this.minimalReproduceEnergy = initialEnergy/2;
this.initialAnimalsNum = initialAnimalsNum;
}

Expand Down Expand Up @@ -66,7 +66,7 @@ private void moveAnimals() throws AnimalStateException {
}

public Location toBoardLimits(Location location){
return new Location(location.getX()%width, location.getY()%height);
return new Location((location.getX()+width)%width, (location.getY()+height)%height);
}
public void eatPlants() throws UnplantingUnplantedLocationException{
for (Location location : plantBoard.getPlantedLocations()) {
Expand Down Expand Up @@ -146,9 +146,8 @@ public void start(){

public void simulateOneDay() throws SimulationErrorException{
currentDay++;
System.out.println("\nSTARTING DAY"+ currentDay + "\n=======================================");
System.out.println("\nSTARTING DAY "+ currentDay + "\n=======================================");
try {

System.out.println("\nMoving animals\n=======================================");
moveAnimals();
System.out.println("\nEating plants\n=======================================");
Expand Down

0 comments on commit 2bcba04

Please sign in to comment.