build in baseworld
This commit is contained in:
parent
20433d9782
commit
83f59d1e15
|
|
@ -1,4 +1,6 @@
|
|||
package backend;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
|
|
@ -422,6 +424,31 @@ public class Simulator extends Thread {
|
|||
}
|
||||
this.stepCount = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean isWorldEmpty() {
|
||||
for (int x = 0; x < getWidth(); x++) {
|
||||
for (int y = 0; y < getHeight(); y++) {
|
||||
if (getCell(x, y) != 0) { //0 represents a "dead" cell
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void startSimulation() {
|
||||
if (isWorldEmpty()) {
|
||||
mjf.clicLoadFileButtonCSV("World/baseworld.csv");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -226,6 +226,9 @@ public class MyInterface extends JFrame {
|
|||
public void clicButtonGo() {
|
||||
this.instantiateSimu();
|
||||
if(!mySimu.isAlive()) {
|
||||
if(mySimu.isWorldEmpty()) {
|
||||
mySimu.startSimulation();
|
||||
}
|
||||
mySimu.startSimu();
|
||||
mySimu.start();
|
||||
} else {
|
||||
|
|
@ -306,6 +309,40 @@ public class MyInterface extends JFrame {
|
|||
this.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//trying to make the baseworld
|
||||
public void clicLoadFileButtonCSV(String fileName) {
|
||||
Simulator loadedSim = new Simulator(this);
|
||||
//String fileName="baseworld.csv";
|
||||
ArrayList<String> stringArray = new ArrayList<String>();
|
||||
if (fileName.length()>0) {
|
||||
try {
|
||||
BufferedReader fileContent = new BufferedReader(new FileReader(fileName));
|
||||
String line = fileContent.readLine();
|
||||
while (line != null) {
|
||||
stringArray.add(line);
|
||||
line = fileContent.readLine();
|
||||
}
|
||||
fileContent.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(mySimu != null) {
|
||||
mySimu.stopSimu();
|
||||
this.eraseLabels();
|
||||
}
|
||||
loadedSim.loadSaveState(stringArray);
|
||||
mySimu = loadedSim;
|
||||
panelDraw.setSimu(mySimu);
|
||||
this.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void clicLoadRuleFileButton() {
|
||||
String fileName=SelectFile();
|
||||
|
|
@ -418,5 +455,8 @@ public class MyInterface extends JFrame {
|
|||
this.setClickBanner("click : X");
|
||||
speedSlider.setValue(3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue