diff --git a/src/backend/Sheep.java b/src/backend/Sheep.java index c6f9aaa..59bcbe8 100644 --- a/src/backend/Sheep.java +++ b/src/backend/Sheep.java @@ -37,7 +37,7 @@ public class Sheep extends Agent { } else { hunger++; } - this.moveRandom(world); + this.moveRandom(); return hunger<10; //condition to be alive //if the sheep can reproduce it creates a new sheep in agents //if(canReproduce(neighbors, world)) { diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 5cbdbf5..a0e4877 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -70,7 +70,8 @@ public class Simulator extends Thread { //Default rule : Survive always, birth never - loadRule("ressources/Rule/conwayRule.json"); + //loadRule("ressources/Rule/conwayRule.json"); + loadRule("OOP_F1_Project/ressources/Rule/conwayRule.json"); } @@ -393,9 +394,28 @@ public class Simulator extends Thread { * the simulated world in its present state */ public ArrayList getSaveState() { - //TODO : complete method with proper return - return null; + ArrayList saveState = new ArrayList<>(); + + // Ensure height and width are properly initialized + int height = getHeight(); // Replace getHeight() with your method to get the height + int width = getWidth(); // Replace getWidth() with your method to get the width + + for (int y = 0; y < height; y++) { + StringBuilder lineBuilder = new StringBuilder(); + for (int x = 0; x < width; x++) { + lineBuilder.append(getCell(x, y)); + if (x < width - 1) { + lineBuilder.append(";"); + } + } + saveState.add(lineBuilder.toString()); + } + return saveState; } + + + + /** * * @param lines of file representing saved world state diff --git a/src/windowInterface/MyInterface.java b/src/windowInterface/MyInterface.java index d33f149..59a8c24 100644 --- a/src/windowInterface/MyInterface.java +++ b/src/windowInterface/MyInterface.java @@ -351,12 +351,13 @@ public class MyInterface extends JFrame { public void clicSaveToFileButton() { - String fileName=SelectFile(); - if (fileName.length()>0) { + String fileName = SelectFile(); + if (fileName.length() > 0) { ArrayList content = mySimu.getSaveState(); - writeFile(fileName, (String[]) content.toArray()); + writeFile(fileName, content.toArray(new String[0])); } } + public void clicSaveAgentsToFileButton() { String fileName=SelectFile();