save agents works

This commit is contained in:
Guillaume BONABAU 2024-05-31 21:54:39 +02:00
parent e785ba1cf8
commit aff82d0e8a
3 changed files with 9 additions and 3 deletions

View File

@ -0,0 +1,2 @@
52,28;25,33;54,60;70,39;36,41
27,27;62,48;38,63;23,39;74,74
1 52 28;25 33;54 60;70 39;36 41
1 52 28;25 33;54 60;70 39;36 41
2 27 27;62 48;38 63;23 39;74 74

View File

@ -649,13 +649,17 @@ public class Simulator extends Thread {
//iterate through the agents arraylist
for(Agent agent : agents){
if(agent instanceof Sheep) {
listSheep = listSheep + agent.getX() + "," + agent.getY() + ";";
if (listSheep != "") listSheep = listSheep + ";";
listSheep = listSheep + agent.getX() + "," + agent.getY();
}else if (agent instanceof Wolf) {
listWolf = listWolf + agent.getX() + "," + agent.getY() + ";";
if (listWolf != "") listWolf = listWolf + ";";
listWolf = listWolf + agent.getX() + "," + agent.getY();
}
}
agentSave.add(listSheep);
System.out.println("listSheep: " + listSheep);
agentSave.add(listWolf);
System.out.println("listWolf: " + listWolf);
return agentSave;
}

View File

@ -363,7 +363,7 @@ public class MyInterface extends JFrame {
String fileName=SelectFile();
if (fileName.length()>0) {
ArrayList<String> content = mySimu.getAgentsSave();
writeFile(fileName, (String[]) content.toArray());
writeFile(fileName, content.toArray(new String[0]));
}
}