Merge branch 'main' of https://gitarero.ecam.fr/guillaume.bonabau/OOP_F1_Project
This commit is contained in:
commit
dee5805c28
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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<String> getSaveState() {
|
||||
//TODO : complete method with proper return
|
||||
return null;
|
||||
ArrayList<String> 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
|
||||
|
|
|
|||
|
|
@ -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<String> content = mySimu.getSaveState();
|
||||
writeFile(fileName, (String[]) content.toArray());
|
||||
writeFile(fileName, content.toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void clicSaveAgentsToFileButton() {
|
||||
String fileName=SelectFile();
|
||||
|
|
|
|||
Loading…
Reference in New Issue