diff --git a/desktop.ini b/desktop.ini index f173e11..691c67b 100644 --- a/desktop.ini +++ b/desktop.ini @@ -1,2 +1,2 @@ [.ShellClassInfo] -IconResource=C:\Program Files\Google\Drive File Stream\74.0.3.0\GoogleDriveFS.exe,23 +IconResource=C:\Program Files\Google\Drive File Stream\75.0.2.0\GoogleDriveFS.exe,23 diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index ae81cbb..0f27886 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -19,7 +19,8 @@ public class Simulator extends Thread { private boolean pauseFlag; private int loopDelay; //TODO : add declaration of additional attributes here - + private int[][] cells; + public Simulator(MyInterface mjfParam) { mjf = mjfParam; stopFlag=false; @@ -34,8 +35,8 @@ public class Simulator extends Thread { * @return the number of columns in the grid composing the simulated world */ public int getWidth() { - //TODO : correct return - return 0; + //TODO : correct return (DONE MAYBE) + return mjf.getWidth(); } /** @@ -43,8 +44,8 @@ public class Simulator extends Thread { * @return the number of rows in the grid composing the simulated world */ public int getHeight() { - //TODO : correct return - return 0; + //TODO : correct return (DONE MAYBE) + return mjf.getHeight(); } public void run() { @@ -90,14 +91,69 @@ public class Simulator extends Thread { * be it as variables or as attributes you may add to the class Simulator, * by using their (public) methods. */ + int simRow = this.getWidth(); + int simCol = this.getHeight(); + cells = new int[simRow][simCol]; + + for (int row=0;row3) { + cells[row][col]=0; + } + else { + cells[row][col]=1; + } + } + else { //cell is dead + if(liveNeighbors == 3) { + cells[row][col]=1; + } + } + + + } + } + + } + + private int countLiveNeighbors(int row, int col) { + int liveNeighbors =0; + + // Check the eight neighboring cells + for (int i = -1; i <= 1; i++) { + for (int j = -1; j <= 1; j++) { + if (i == 0 && j == 0) { + continue; // Skip the current cell + } + + int neighborRow = row + i; + int neighborCol = col + j; + + // Check if the neighboring cell is within the board bounds + if (neighborRow >= 0 && neighborRow < this.getWidth() && neighborCol >= 0 && neighborCol < this.getHeight()) { + // Check if the neighboring cell is alive + if (cells[neighborRow][neighborCol] == 1) { + liveNeighbors++; + } + } + } + } + + return liveNeighbors; } /** * Stops simulation by raising the stop flag used in the run method */ - public void stopSimu() { - //TODO : set stopFlag to true + public boolean stopSimu() { + //TODO : set stopFlag to true (DONE) + return stopFlag = true; } @@ -105,9 +161,16 @@ public class Simulator extends Thread { * Toggles Pause of simulation * by raising or lowering the pause flag used in the run method */ - public void togglePause() { - //TODO : change value of boolean attribute pauseFlag + public boolean togglePause() { + //TODO : change value of boolean attribute pauseFlag (DONE) // from false to true, or from true to false + if (pauseFlag == true) { + pauseFlag = false; + } + else { + pauseFlag = true; + } + return pauseFlag; } /** @@ -125,6 +188,7 @@ public class Simulator extends Thread { * But the GUI can also print properly more values than that. * You might want to use this for the going further section. */ + } /** * get the value of a cell at coordinates @@ -145,6 +209,7 @@ public class Simulator extends Thread { */ public void setCell(int x, int y, int val) { //TODO implement + } /** @@ -166,6 +231,7 @@ public class Simulator extends Thread { public void populateLine(int coord, String fileLine) { //TODO : implement and correct the comment // As you have to choose row OR column depending on your implementation + } /** diff --git a/src/backend/desktop.ini b/src/backend/desktop.ini index f173e11..691c67b 100644 --- a/src/backend/desktop.ini +++ b/src/backend/desktop.ini @@ -1,2 +1,2 @@ [.ShellClassInfo] -IconResource=C:\Program Files\Google\Drive File Stream\74.0.3.0\GoogleDriveFS.exe,23 +IconResource=C:\Program Files\Google\Drive File Stream\75.0.2.0\GoogleDriveFS.exe,23 diff --git a/src/desktop.ini b/src/desktop.ini index f173e11..691c67b 100644 --- a/src/desktop.ini +++ b/src/desktop.ini @@ -1,2 +1,2 @@ [.ShellClassInfo] -IconResource=C:\Program Files\Google\Drive File Stream\74.0.3.0\GoogleDriveFS.exe,23 +IconResource=C:\Program Files\Google\Drive File Stream\75.0.2.0\GoogleDriveFS.exe,23 diff --git a/src/windowInterface/desktop.ini b/src/windowInterface/desktop.ini index f173e11..691c67b 100644 --- a/src/windowInterface/desktop.ini +++ b/src/windowInterface/desktop.ini @@ -1,2 +1,2 @@ [.ShellClassInfo] -IconResource=C:\Program Files\Google\Drive File Stream\74.0.3.0\GoogleDriveFS.exe,23 +IconResource=C:\Program Files\Google\Drive File Stream\75.0.2.0\GoogleDriveFS.exe,23