From 1b432953a195c607a735416ffbe16fba9c705440 Mon Sep 17 00:00:00 2001 From: Balthazar Squinabol Date: Wed, 29 May 2024 17:07:30 +0200 Subject: [PATCH] Fix --- src/backend/Sheep.java | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/backend/Sheep.java b/src/backend/Sheep.java index f6fb5bb..3ff1d63 100644 --- a/src/backend/Sheep.java +++ b/src/backend/Sheep.java @@ -12,7 +12,6 @@ public class Sheep extends Agent { int hunger; Random rand; - Simulator simulator; Sheep(int x,int y){ //first we call the constructor of the superClass(Animal) @@ -25,37 +24,24 @@ public class Sheep extends Agent { rand = new Random(); } - boolean loopingBorder = simulator.isLoopingBorder(); - int width = simulator.getWidth(); - int height = simulator.getHeight(); + /** * action of the animal * it can interact with the cells or with other animals * as you wish */ - public boolean liveTurn(ArrayList neighbors, Simulator word) { - - //we check if the sheep is on the border of the world - //If loopingBorder == true, the world is a torus - //If loopingBorder == false, the world is a square and the sheep can't go out of the world - - if(simulator.getCell(x, y)==1) { - simulator.setCell(x, y, 0); - hunger = hunger--; + public boolean liveTurn(ArrayList neighbors, Simulator world) { + if(world.getCell(x, y)==1) { + world.setCell(x, y, 0); } else { hunger++; } - this.moveRandom(world); + this.moveRandom(); return hunger<10; //condition to be alive } private void moveRandom() { - //check if the sheep is on the border of the world - //If loopingBorder == true, the world is a torus - - - int direction = rand.nextInt(4); if(direction == 0) { x+=1; @@ -70,4 +56,6 @@ public class Sheep extends Agent { y-=1; } } -} + + +} \ No newline at end of file