|
|
|
|
@ -23,10 +23,12 @@ public class Simulator extends Thread {
|
|
|
|
|
private boolean pauseFlag;
|
|
|
|
|
private boolean loopingBorder;
|
|
|
|
|
private boolean clickActionFlag;
|
|
|
|
|
private int loopDelay = 150;
|
|
|
|
|
private boolean clickActionFlagValue = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int loopDelay = 150;
|
|
|
|
|
private int[][] board;
|
|
|
|
|
private int width;
|
|
|
|
|
private int height;
|
|
|
|
|
private int clickActionFlagValue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO : add missing attribute(s)
|
|
|
|
|
|
|
|
|
|
@ -51,15 +53,15 @@ public class Simulator extends Thread {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int getWidth() {
|
|
|
|
|
//TODO : replace with proper return
|
|
|
|
|
return width;
|
|
|
|
|
return COL_NUM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getHeight() {
|
|
|
|
|
//TODO : replace with proper return
|
|
|
|
|
return height;
|
|
|
|
|
return LINE_NUM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Should probably stay as is
|
|
|
|
|
@ -146,20 +148,60 @@ public class Simulator extends Thread {
|
|
|
|
|
/**
|
|
|
|
|
* method called when clicking on a cell in the interface
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Method to handle different behaviors based on the clickActionFlagValue
|
|
|
|
|
public void clickCell(int x, int y) {
|
|
|
|
|
//TODO : complete method
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (clickActionFlagValue) {
|
|
|
|
|
case 1: // Cell case (default): toggles the state of the cell at coordinates x,y
|
|
|
|
|
toggleCellState(x, y);
|
|
|
|
|
break;
|
|
|
|
|
case 2: // Agent case: create an Agent (Sheep provided for example) at provided coordinates
|
|
|
|
|
createAgent(x, y);
|
|
|
|
|
break;
|
|
|
|
|
// Add more cases as needed for different flag values
|
|
|
|
|
default:
|
|
|
|
|
// Default behavior
|
|
|
|
|
System.out.println("Invalid click action flag value.");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Method to toggle the state of the cell at coordinates x, y
|
|
|
|
|
private void toggleCellState(int x, int y) {
|
|
|
|
|
if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
|
|
|
|
|
// Toggle the state of the cell
|
|
|
|
|
board[x][y] = (board[x][y] == 0) ? 1 : 0; // Assuming 0 represents dead cell and 1 represents alive cell
|
|
|
|
|
} else {
|
|
|
|
|
// Handle out of bounds condition or throw an exception
|
|
|
|
|
System.out.println("Invalid coordinates: (" + x + ", " + y + ")");
|
|
|
|
|
// You can choose to throw an exception here instead
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Method to create an agent at the provided coordinates (example: Sheep)
|
|
|
|
|
private void createAgent(int x, int y) {
|
|
|
|
|
|
|
|
|
|
Agent agent = new Sheep(x, y);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* get cell value in simulated world
|
|
|
|
|
* @param x coordinate of cell
|
|
|
|
|
* @param y coordinate of cell
|
|
|
|
|
* @return value of cell
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Method to get the value of cell at coordinates x, y
|
|
|
|
|
public int getCell(int x, int y) {
|
|
|
|
|
//TODO : complete method with proper return
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
|
|
|
|
|
return board[x][y];
|
|
|
|
|
} else {
|
|
|
|
|
// Handle out of bounds condition or return default value
|
|
|
|
|
return -1; // We can choose any default value here
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @return list of Animals in simulated world
|
|
|
|
|
@ -193,6 +235,13 @@ public class Simulator extends Thread {
|
|
|
|
|
*/
|
|
|
|
|
public void setCell(int x, int y, int val) {
|
|
|
|
|
//TODO : complete method
|
|
|
|
|
if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
|
|
|
|
|
board[x][y] = val;
|
|
|
|
|
} else {
|
|
|
|
|
// Handle out of bounds condition or throw an exception
|
|
|
|
|
System.out.println("Invalid coordinates: (" + x + ", " + y + ")");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -274,8 +323,7 @@ public class Simulator extends Thread {
|
|
|
|
|
|
|
|
|
|
public void toggleClickAction() {
|
|
|
|
|
//TODO : complete method
|
|
|
|
|
clickActionFlagValue = !clickActionFlagValue;
|
|
|
|
|
System.out.println("Click action flag toggled. New value: " + clickActionFlagValue);
|
|
|
|
|
clickActionFlagValue = (clickActionFlagValue == 1) ? 2 : 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|