j'adore la

This commit is contained in:
sebas 2024-05-23 11:26:14 +02:00
parent 4ea6d4d36e
commit f3c22f0916
3 changed files with 56 additions and 13 deletions

29
src/backend/Grid.java Normal file
View File

@ -0,0 +1,29 @@
package backend;
public class Grid {
private int width;
private int height;
private int[][] grid;
public Grid(int width, int height) {
this.width = width;
this.height = height;
this.grid = new int[height][width];
}
public void setValue(int x, int y, int value) {
if (x >= 0 && x < width && y >= 0 && y < height) {
grid[y][x] = value;
} else {
throw new IndexOutOfBoundsException("Grid position out of range");
}
}
public int getValue(int x, int y) {
if (x >= 0 && x < width && y >= 0 && y < height) {
return grid[y][x];
} else {
throw new IndexOutOfBoundsException("Grid position out of range");
}
}
}

View File

@ -22,8 +22,9 @@ public class Simulator extends Thread {
private boolean stopFlag; private boolean stopFlag;
private boolean pauseFlag; private boolean pauseFlag;
private boolean loopingBorder; private boolean loopingBorder;
private boolean clickActionFlag; private boolean clickActionFlag=false;
private int loopDelay = 150; private int loopDelay = 150;
Grid maingrid = new Grid(COL_NUM, LINE_NUM);
//TODO : add missing attribute(s) //TODO : add missing attribute(s)
@ -57,7 +58,7 @@ public class Simulator extends Thread {
return LINE_NUM; return LINE_NUM;
} }
//Should probably stay as is //Should probably stay as it is
public void run() { public void run() {
int stepCount=0; int stepCount=0;
while(!stopFlag) { while(!stopFlag) {
@ -142,6 +143,13 @@ public class Simulator extends Thread {
*/ */
public void clickCell(int x, int y) { public void clickCell(int x, int y) {
//TODO : complete method //TODO : complete method
if(clickActionFlag) {
if (getCell(x, y)==0) {
setCell(x, y,1);
}else {
setCell(x, y,0);
}
}
} }
/** /**
@ -151,8 +159,8 @@ public class Simulator extends Thread {
* @return value of cell * @return value of cell
*/ */
public int getCell(int x, int y) { public int getCell(int x, int y) {
//TODO : complete method with proper return //TODO : complete method with proper retur
return 0; return maingrid.getValue(x, y);
} }
/** /**
* *
@ -187,7 +195,8 @@ public class Simulator extends Thread {
*/ */
public void setCell(int x, int y, int val) { public void setCell(int x, int y, int val) {
//TODO : complete method //TODO : complete method
} maingrid.setValue(x, y, val);
}
/** /**
* *
@ -265,6 +274,11 @@ public class Simulator extends Thread {
public void toggleClickAction() { public void toggleClickAction() {
//TODO : complete method //TODO : complete method
if(clickActionFlag) {
clickActionFlag=false;
}else {
clickActionFlag=true;
}
} }
/** /**
@ -327,4 +341,4 @@ public class Simulator extends Thread {
return ""; return "";
} }
} }

View File

@ -92,13 +92,13 @@ public class MyInterface extends JFrame {
}); });
panelTop.add(speedSlider); panelTop.add(speedSlider);
// JButton btnSpeed = new JButton("Set Speed"); /*JButton btnSpeed = new JButton("Set Speed");
// btnSpeed.addActionListener(new ActionListener() { btnSpeed.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// clicButtonSpeed(); clicButtonSpeed();
// } }
// }); });
// panelTop.add(btnSpeed); panelTop.add(btnSpeed);*/
JButton btnLoad = new JButton("Load World"); JButton btnLoad = new JButton("Load World");
btnLoad.addActionListener(new ActionListener() { btnLoad.addActionListener(new ActionListener() {