Started The Lab and stopped at clickCell Step

This commit is contained in:
Isaac Enzo MOUANG TACHI 2024-04-10 17:23:12 +02:00
parent 8b6f8403e6
commit 95f33b5f12
2 changed files with 25 additions and 8 deletions

View File

@ -1,4 +1,5 @@
package backend;
import java.util.ArrayList;
import windowInterface.MyInterface;
@ -11,8 +12,10 @@ public class Simulator extends Thread {
private final int LINE_NUM = 100;
private final int LIFE_TYPE_NUM = 4;
//Conway Radius : 1
private final int CONWAY_RADIUS = 1;
private final int LIFE_AREA_RADIUS = 1;
//Animal Neighborhood Radius : 5
private final int ANIMAL_NEIGHBORHOOD_RADIUS = 5 ;
private final int ANIMAL_AREA_RADIUS = 2;
private ArrayList<Integer> fieldSurviveValues;
private ArrayList<Integer> fieldBirthValues;
@ -24,7 +27,7 @@ public class Simulator extends Thread {
private boolean loopingBorder;
private boolean clickActionFlag;
private int loopDelay = 150;
private Grid grid;
//TODO : add missing attribute(s)
public Simulator(MyInterface mjfParam) {
@ -37,6 +40,7 @@ public class Simulator extends Thread {
agents = new ArrayList<Agent>();
fieldBirthValues = new ArrayList<Integer>();
fieldSurviveValues = new ArrayList<Integer>();
grid = new Grid(COL_NUM,LINE_NUM);
//TODO : add missing attribute initialization
@ -51,12 +55,12 @@ public class Simulator extends Thread {
public int getWidth() {
//TODO : replace with proper return
return 0;
return COL_NUM;
}
public int getHeight() {
//TODO : replace with proper return
return 0;
return LINE_NUM;
}
//Should probably stay as is
@ -137,6 +141,7 @@ public class Simulator extends Thread {
*/
public void togglePause() {
// TODO : actually toggle the corresponding flag
pauseFlag = !pauseFlag;
}
/**
@ -144,6 +149,9 @@ public class Simulator extends Thread {
*/
public void clickCell(int x, int y) {
//TODO : complete method
getCell(x,y);
}
/**
@ -154,7 +162,8 @@ public class Simulator extends Thread {
*/
public int getCell(int x, int y) {
//TODO : complete method with proper return
return 0;
return grid.getValueCell(x,y);
}
/**
*
@ -189,6 +198,7 @@ public class Simulator extends Thread {
*/
public void setCell(int x, int y, int val) {
//TODO : complete method
grid.setValueCell(x,y,val);
}
/**
@ -253,15 +263,18 @@ public class Simulator extends Thread {
public boolean isLoopingBorder() {
//TODO : complete method with proper return
return false;
return loopingBorder;
}
public void toggleLoopingBorder() {
loopingBorder = !loopingBorder ;
//TODO : complete method
}
public void setLoopDelay(int delay) {
loopDelay = delay;
//TODO : complete method
}

View File

@ -23,6 +23,7 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.awt.event.ActionEvent;
public class MyInterface extends JFrame {
@ -326,7 +327,8 @@ public class MyInterface extends JFrame {
String fileName=SelectFile();
if (fileName.length()>0) {
ArrayList<String> content = mySimu.getSaveState();
writeFile(fileName, (String[]) content.toArray());
String[] strArr = Arrays.copyOf(content.toArray(), content.toArray().length, String[].class);
writeFile(fileName, strArr);
}
}
@ -334,7 +336,8 @@ public class MyInterface extends JFrame {
String fileName=SelectFile();
if (fileName.length()>0) {
ArrayList<String> content = mySimu.getRule();
writeFile(fileName, (String[]) content.toArray());
String[] strArr = Arrays.copyOf(content.toArray(), content.toArray().length, String[].class);
writeFile(fileName, strArr);
}
}
@ -342,7 +345,8 @@ public class MyInterface extends JFrame {
String fileName=SelectFile();
if (fileName.length()>0) {
ArrayList<String> content = mySimu.getAgentsSave();
writeFile(fileName, (String[]) content.toArray());
String[] strArr = Arrays.copyOf(content.toArray(), content.toArray().length, String[].class);
writeFile(fileName, strArr);
}
}