Part 2: the Mandatory methods
This commit is contained in:
parent
d1a06c5d46
commit
e6d5262178
|
|
@ -50,13 +50,11 @@ public class Simulator extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
//TODO : replace with proper return
|
return COL_NUM;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
//TODO : replace with proper return
|
return LINE_NUM;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Should probably stay as is
|
//Should probably stay as is
|
||||||
|
|
@ -136,14 +134,20 @@ public class Simulator extends Thread {
|
||||||
* method called when clicking pause button
|
* method called when clicking pause button
|
||||||
*/
|
*/
|
||||||
public void togglePause() {
|
public void togglePause() {
|
||||||
// TODO : actually toggle the corresponding flag
|
pauseFlag = !pauseFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* method called when clicking on a cell in the interface
|
* method called when clicking on a cell in the interface
|
||||||
*/
|
*/
|
||||||
public void clickCell(int x, int y) {
|
public void clickCell(int x, int y) {
|
||||||
//TODO : complete method
|
if (clickActionFlag) {
|
||||||
|
agents.add(new Sheep(x, y));
|
||||||
|
} else {
|
||||||
|
|
||||||
|
int currentValue = getCell(x, y);
|
||||||
|
int newValue = (currentValue == 0) ? 1 : 0;
|
||||||
|
setCell(x, y, newValue);}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -153,8 +157,7 @@ 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
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -188,7 +191,7 @@ public class Simulator extends Thread {
|
||||||
* @param val to set in cell
|
* @param val to set in cell
|
||||||
*/
|
*/
|
||||||
public void setCell(int x, int y, int val) {
|
public void setCell(int x, int y, int val) {
|
||||||
//TODO : complete method
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -197,7 +200,6 @@ public class Simulator extends Thread {
|
||||||
* the simulated world in its present state
|
* the simulated world in its present state
|
||||||
*/
|
*/
|
||||||
public ArrayList<String> getSaveState() {
|
public ArrayList<String> getSaveState() {
|
||||||
//TODO : complete method with proper return
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
@ -241,14 +243,7 @@ public class Simulator extends Thread {
|
||||||
* to be alive in new state
|
* to be alive in new state
|
||||||
*/
|
*/
|
||||||
public void generateRandom(float chanceOfLife) {
|
public void generateRandom(float chanceOfLife) {
|
||||||
//TODO : complete method
|
|
||||||
/*
|
|
||||||
* Advice :
|
|
||||||
* as you should probably have a separate class
|
|
||||||
* representing the field of cells...
|
|
||||||
* maybe just make a constructor in there
|
|
||||||
* and use it here
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLoopingBorder() {
|
public boolean isLoopingBorder() {
|
||||||
|
|
@ -259,11 +254,11 @@ public class Simulator extends Thread {
|
||||||
loopingBorder = !loopingBorder;
|
loopingBorder = !loopingBorder;
|
||||||
}
|
}
|
||||||
public void setLoopDelay(int delay) {
|
public void setLoopDelay(int delay) {
|
||||||
//TODO : complete method
|
loopDelay = delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleClickAction() {
|
public void toggleClickAction() {
|
||||||
//TODO : complete method
|
clickActionFlag = !clickActionFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -321,9 +316,7 @@ public class Simulator extends Thread {
|
||||||
* @return String representation of click action
|
* @return String representation of click action
|
||||||
*/
|
*/
|
||||||
public String clickActionName() {
|
public String clickActionName() {
|
||||||
// TODO : initially return "sheep" or "cell"
|
return clickActionFlag ? "Sheep" : "Cell";
|
||||||
// depending on clickActionFlag
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue