clickaction name and clickaction changed to work with agents

This commit is contained in:
l.dupuis-burtin 2024-05-30 18:21:20 +02:00
parent d3efcf8140
commit 70bbd4fdc3
1 changed files with 49 additions and 9 deletions

View File

@ -27,7 +27,7 @@ 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 int clickActionFlag;
private int loopDelay = 150; private int loopDelay = 150;
private ArrayList<Integer> ruleSurviveCriteria= new ArrayList<Integer>(); private ArrayList<Integer> ruleSurviveCriteria= new ArrayList<Integer>();
@ -40,7 +40,7 @@ public class Simulator extends Thread {
stopFlag=false; stopFlag=false;
pauseFlag=false; pauseFlag=false;
loopingBorder=false; loopingBorder=false;
clickActionFlag=false; clickActionFlag=0;
cells = new ArrayList<ArrayList<Cell>>(); cells = new ArrayList<ArrayList<Cell>>();
newCells = new ArrayList<ArrayList<Cell>>(); newCells = new ArrayList<ArrayList<Cell>>();
@ -277,16 +277,29 @@ public class Simulator extends Thread {
//TODO : complete method //TODO : complete method
//if clickActionFlag = true then create an agent //if clickActionFlag = true then create an agent
//else if flag = false then change value of cell //else if flag = false then change value of cell
if(clickActionFlag) { switch (clickActionFlag) {
case 0 :
System.out.print(x ); System.out.print(x );
System.out.println(y); System.out.println(y);
}else { break;
System.out.println(getAliveNeighbors(x, y, LIFE_AREA_RADIUS)); //print nb of neighbours case 1 :
if(getCell(x, y)==0) { if(getCell(x, y)==0) {
setCell(x, y, 1); setCell(x, y, 1);
}else {setCell(x, y, 0);} }else {setCell(x, y, 0);}
break;
case 2 :
if(getCell(x, y)==0) {
setCell(x, y, 1);
}else {setCell(x, y, 0);}
break;
case 3 :
if(getCell(x, y)==0) {
setCell(x, y, 1);
}else {setCell(x, y, 0);}
break;
default:
break;
} }
} }
/** /**
@ -463,7 +476,23 @@ public class Simulator extends Thread {
public void toggleClickAction() { public void toggleClickAction() {
//TODO : complete method //TODO : complete method
clickActionFlag = !clickActionFlag; switch (clickActionFlag) {
case 0:
clickActionFlag++;
break;
case 1:
clickActionFlag++;
break;
case 2:
clickActionFlag++;
break;
case 3:
clickActionFlag=0;
break;
default:
break;
}
} }
/** /**
@ -539,7 +568,18 @@ public class Simulator extends Thread {
public String clickActionName() { public String clickActionName() {
// TODO : initially return "sheep" or "cell" // TODO : initially return "sheep" or "cell"
// depending on clickActionFlag // depending on clickActionFlag
switch (clickActionFlag) {
case 0:
return "position";
case 1:
return "cell";
case 2:
return "sheep";
case 3:
return "wolf";
default:
return ""; return "";
} }
}
} }