Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI #9

Closed
wants to merge 13 commits into from
Closed

GUI #9

wants to merge 13 commits into from

Conversation

Gabriela-Dumanska
Copy link
Collaborator

No description provided.

Gabriela-Dumanska and others added 3 commits January 6, 2024 00:58
While resolving merge conflict forgot to check if genotypeLength exists. Made Genotype abstract and divided mutation method into 2 seperate classes.
Comment on lines +1 to +9
package agh.ics.oop;

import javafx.application.Application;

public class World {
public static void main(String[] args) {
Application.launch(SimulationApp.class, args);
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the App should be launched from here by running World class

Comment on lines 4 to 10
<?import javafx.scene.layout.BorderPane?>
<BorderPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
minHeight="550.0" minWidth="850.0"
fx:controller="agh.ics.oop.presenter.SimulationPresenter">
minHeight="550.0" minWidth="850.0">
<center>
<Label fx:id="infoLabel" text="All animals will be living here!" textAlignment="CENTER"/>
</center>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file will be showing the simulation in some time

Copy link
Owner

@karmatys8 karmatys8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variables restriction differ from previous ones. While they make code more readable they require you to check the rest of the code and tests to make sure there are no violations.

public void initialize() {
mapWidth.setTextFormatter(positiveInteger());
mapHeight.setTextFormatter(positiveInteger());
mapWidth.textProperty().addListener((observable, oldValue, newValue) -> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should values be validated on every change or only after startTheSimulation Button changed?
Right now if you try to change values you have to do it in the correct order and it probably isn't a good UX.

int height = getValueFromTextField(mapHeight);

checkAndClearIfGreaterThan(initialNumberOfPlants, width * height);
checkAndClearIfGreaterThan(initialNumberOfAnimals, width * height);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many animals can be on one tile. So unless it is a restriction to prevent lagging and user overuse we can delete this line.

If you decide to do so don't forget to delete line 235 as well.

initialEnergyOfAnimals.setTextFormatter(positiveInteger());
energyToBeWellFed.setTextFormatter(positiveInteger());
energyToBeWellFed.textProperty().addListener((observable, oldValue, newValue) -> {
setTextFormatterLessThan(energyToBeWellFed, energyToReproduce);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name of this method and setTextFormatterLessThanWholeMap is a bit misleading because if the values are equal it still works. You can change ...Less... to ...NotGreater... or something else to make the names shorter if possible.

alert.showAndWait();
}

private void setTextFormatterLessThan(TextField maxValue, TextField lowerValue) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exacly is maxValue and lowerValue?

If I understand it correctly lowerValue is value to check and max is the mac limit set?
If so the variables names are chosen poorly.

});
}

private TextFormatter<Integer> positiveInteger() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we allowed some values to be equal to 0. For instance:

  1. initialNumberOfPlants
  2. energyFromOnePlant;
  3. plantsEachDay;
  4. minNumberOfMutations;
  5. maxNumberOfMutations;

I only mentioned those that would have sense if we decide to let them be 0 again.

Current state is not bad, but I want to make sure that in previous code there are usages that will need to be changed. Fe. in GenotypeTests.


ObservableList<String> optionsOfMap = FXCollections.observableArrayList(
"Underground tunnels",
"Rectangular map"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still to the "Globe" name.

Comment on lines +111 to +121
&& !mapHeight.getText().isEmpty()
&& !initialNumberOfPlants.getText().isEmpty()
&& !energyFromOnePlant.getText().isEmpty()
&& !initialNumberOfAnimals.getText().isEmpty()
&& !plantsEachDay.getText().isEmpty()
&& !initialEnergyOfAnimals.getText().isEmpty()
&& !energyToBeWellFed.getText().isEmpty()
&& !energyToReproduce.getText().isEmpty()
&& !lengthOfGenotypes.getText().isEmpty()
&& !maxNumberOfMutations.getText().isEmpty()
&& !minNumberOfMutations.getText().isEmpty()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All those TextFields can be stored in a List. Then instead of writing everything by hand you can iterate through this list. You could also iterate through this list while setting positiveInteger TextFormatter in initialize().

It would look something like that:

private boolean areAllValuesFilled() {
    List<TextField> fields = Arrays.asList(
            mapWidth, mapHeight, initialNumberOfPlants, energyFromOnePlant,
            initialNumberOfAnimals, plantsEachDay, initialEnergyOfAnimals,
            energyToBeWellFed, energyToReproduce, lengthOfGenotypes,
            maxNumberOfMutations, minNumberOfMutations
    );

    return fields.stream().allMatch(field -> !field.getText().isEmpty())
            && mutationOption.getValue() != null
            && mapOption.getValue() != null;
}

try {
int newValue = Integer.parseInt(newText);

if (newValue < max) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to allow some values to be the same? For instance minNumberOfmutations and maxNumberOfMutations. If not you have to make sure that nowhere else is the code we are allowing that to happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants