Merge branch 'main' of https://gitarero.ecam.fr/guillaume.bonabau/OOP_F1_Project
This commit is contained in:
commit
d349fb5567
|
|
@ -1,10 +1,10 @@
|
||||||
package backend;
|
package backend;
|
||||||
|
|
||||||
public class Cell {
|
public class Cell {
|
||||||
protected int value;
|
private int value;
|
||||||
protected int density;
|
private int density;
|
||||||
|
|
||||||
protected Cell(int value, int density) {
|
public Cell(int value, int density) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.density = density;
|
this.density = density;
|
||||||
}
|
}
|
||||||
|
|
@ -15,10 +15,10 @@ public class Cell {
|
||||||
public int getDensity() {
|
public int getDensity() {
|
||||||
return density;
|
return density;
|
||||||
}
|
}
|
||||||
public int setValue(int value) {
|
public void setValue(int value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
public int setDensity(int density){
|
public void setDensity(int density){
|
||||||
this.density = density;
|
this.density = density;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,11 @@ public class Simulator extends Thread {
|
||||||
private int loopDelay = 150;
|
private int loopDelay = 150;
|
||||||
|
|
||||||
//TODO : add missing attribute(s)
|
//TODO : add missing attribute(s)
|
||||||
|
private double randomDansitySlider = 0.5;
|
||||||
private int width;
|
private int width;
|
||||||
private int height;
|
private int height;
|
||||||
private boolean enableLogs;
|
private boolean enableLogs;
|
||||||
|
private Table table;
|
||||||
|
|
||||||
public Simulator(MyInterface mjfParam) {
|
public Simulator(MyInterface mjfParam) {
|
||||||
mjf = mjfParam;
|
mjf = mjfParam;
|
||||||
|
|
@ -46,6 +48,7 @@ public class Simulator extends Thread {
|
||||||
this.width=COL_NUM;
|
this.width=COL_NUM;
|
||||||
this.height=LINE_NUM;
|
this.height=LINE_NUM;
|
||||||
enableLogs = true; // for debugging purposes
|
enableLogs = true; // for debugging purposes
|
||||||
|
table = new Table(height, width);
|
||||||
|
|
||||||
|
|
||||||
//Default rule : Survive always, birth never
|
//Default rule : Survive always, birth never
|
||||||
|
|
@ -110,8 +113,28 @@ public class Simulator extends Thread {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//then evolution of the field
|
//then evolution of the field
|
||||||
// TODO : apply game rule to all cells of the field
|
// TODO-INPROGRESS : apply game rule to all cells of the field
|
||||||
|
Table tempTable = new Table(this.height, this.width);
|
||||||
|
for(int x=0; x<width; x++) {
|
||||||
|
for(int y=0; y<height; y++) {
|
||||||
|
if (this.table.getCell(x, y).getValue()=1) {
|
||||||
|
if (table.countNear(x,y)<2) {
|
||||||
|
tempTable.getCell(x,y).setValue(0);
|
||||||
|
} else if(table.countNear(x,y)>3) {
|
||||||
|
tempTable.getCell(x,y).setValue(0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(table.countNear(x,y)==3) {
|
||||||
|
tempTable.getCell(x,y).setValue(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.table = tempTable;
|
||||||
|
}
|
||||||
|
|
||||||
/* you should distribute this action in methods/classes
|
/* you should distribute this action in methods/classes
|
||||||
* don't write everything here !
|
* don't write everything here !
|
||||||
*
|
*
|
||||||
|
|
@ -128,8 +151,6 @@ public class Simulator extends Thread {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* leave this as is
|
* leave this as is
|
||||||
|
|
@ -185,7 +206,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-ERROR : WHY THE FUCK DOES IT WORK AT 0 BUT NOT WITH table.getcell.getvalue ????
|
||||||
|
//complete method with proper return
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
@ -237,7 +259,7 @@ public class Simulator extends Thread {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -300,12 +322,20 @@ public class Simulator extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLoopingBorder() {
|
public boolean isLoopingBorder() {
|
||||||
//TODO : complete method with proper return
|
//ODO-COMPLETE : complete method with proper return
|
||||||
return false;
|
return loopingBorder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleLoopingBorder() {
|
public void toggleLoopingBorder() {
|
||||||
//TODO : complete method
|
//ODO-COMPLETE : complete method
|
||||||
|
loopingBorder = !loopingBorder;
|
||||||
|
if (enableLogs) {
|
||||||
|
if (loopingBorder) {
|
||||||
|
System.out.println("toggleLoopingBorder called, set loopingBorder to true");
|
||||||
|
} else {
|
||||||
|
System.out.println("toggleLoopingBorder called, set loopingBorder to false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -316,6 +346,13 @@ public class Simulator extends Thread {
|
||||||
System.out.println("Loop delay set to " + delay);
|
System.out.println("Loop delay set to " + delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDansity(double density) {
|
||||||
|
randomDansitySlider = density;
|
||||||
|
if (enableLogs) {
|
||||||
|
System.out.println("Density set to " + density);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void toggleClickAction() {
|
public void toggleClickAction() {
|
||||||
//TODO-COMPLETE : complete method
|
//TODO-COMPLETE : complete method
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,11 @@ public class MyInterface extends JFrame {
|
||||||
randSlider.setMinimum(0);
|
randSlider.setMinimum(0);
|
||||||
randSlider.setMaximum(100);
|
randSlider.setMaximum(100);
|
||||||
randSlider.setPreferredSize(new Dimension(30,200));
|
randSlider.setPreferredSize(new Dimension(30,200));
|
||||||
|
randSlider.addChangeListener(new ChangeListener() {
|
||||||
|
public void stateChanged(ChangeEvent arg0) {
|
||||||
|
changeDansity();
|
||||||
|
}
|
||||||
|
});
|
||||||
panelRight.add(randSlider);
|
panelRight.add(randSlider);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -254,6 +259,15 @@ public class MyInterface extends JFrame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void changeDansity() {
|
||||||
|
if(mySimu != null) {
|
||||||
|
double density = ((double)randSlider.getValue())/((double)randSlider.getMaximum());
|
||||||
|
mySimu.setDansity(density);
|
||||||
|
} else {
|
||||||
|
randSlider.setValue(50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void clicLoadFileButton() {
|
public void clicLoadFileButton() {
|
||||||
Simulator loadedSim = new Simulator(this);
|
Simulator loadedSim = new Simulator(this);
|
||||||
String fileName=SelectFile();
|
String fileName=SelectFile();
|
||||||
|
|
@ -379,6 +393,7 @@ public class MyInterface extends JFrame {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update (int stepCount) {
|
public void update (int stepCount) {
|
||||||
|
System.out.println("update called");
|
||||||
this.setStepBanner("Step : "+ stepCount);
|
this.setStepBanner("Step : "+ stepCount);
|
||||||
this.repaint();
|
this.repaint();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue