From 70bbd4fdc3b848b9f35511ffb446bb6fe2ab07a1 Mon Sep 17 00:00:00 2001 From: "l.dupuis-burtin" Date: Thu, 30 May 2024 18:21:20 +0200 Subject: [PATCH] clickaction name and clickaction changed to work with agents --- src/backend/Simulator.java | 58 ++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 3d31737..fb2e95e 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -27,7 +27,7 @@ public class Simulator extends Thread { private boolean stopFlag; private boolean pauseFlag; private boolean loopingBorder; - private boolean clickActionFlag; + private int clickActionFlag; private int loopDelay = 150; private ArrayList ruleSurviveCriteria= new ArrayList(); @@ -40,7 +40,7 @@ public class Simulator extends Thread { stopFlag=false; pauseFlag=false; loopingBorder=false; - clickActionFlag=false; + clickActionFlag=0; cells = new ArrayList>(); newCells = new ArrayList>(); @@ -277,16 +277,29 @@ public class Simulator extends Thread { //TODO : complete method //if clickActionFlag = true then create an agent //else if flag = false then change value of cell - if(clickActionFlag) { + switch (clickActionFlag) { + case 0 : System.out.print(x ); System.out.println(y); - }else { - System.out.println(getAliveNeighbors(x, y, LIFE_AREA_RADIUS)); //print nb of neighbours + break; + case 1 : if(getCell(x, y)==0) { setCell(x, y, 1); }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() { //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() { // TODO : initially return "sheep" or "cell" // depending on clickActionFlag - return ""; + switch (clickActionFlag) { + case 0: + return "position"; + case 1: + return "cell"; + case 2: + return "sheep"; + case 3: + return "wolf"; + default: + return ""; + } } }