we forget to delete wolf so this is lates lates version
This commit is contained in:
parent
19d55e3803
commit
0e005ee296
|
|
@ -1,61 +0,0 @@
|
||||||
package backend;
|
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class Wolf extends Agent {
|
|
||||||
int hungerLevel;
|
|
||||||
Random rand = new Random();
|
|
||||||
|
|
||||||
public Wolf(int x, int y) {
|
|
||||||
super(x, y, Color.GRAY); // Wolves are gray
|
|
||||||
this.hungerLevel = 10; // Initial hunger level
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void interact(Agent other) {
|
|
||||||
if (other instanceof Sheep) {
|
|
||||||
eat((Sheep) other);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void eat(Sheep sheep) {
|
|
||||||
// Increase hunger level when eating a sheep
|
|
||||||
this.hungerLevel += 5;
|
|
||||||
// Logic to remove the sheep from the simulation might be implemented here
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void move(int newX, int newY) {
|
|
||||||
super.move(newX, newY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean liveTurn(ArrayList<Agent> neighbors, Simulator world) {
|
|
||||||
// Wolves might prioritize eating sheep if they are nearby
|
|
||||||
for (Agent neighbor : neighbors) {
|
|
||||||
if (neighbor instanceof Sheep) {
|
|
||||||
eat((Sheep) neighbor);
|
|
||||||
neighbors.remove(neighbor);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hungerLevel--;
|
|
||||||
this.moveRandom();
|
|
||||||
return hungerLevel > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void moveRandom() {
|
|
||||||
int direction = rand.nextInt(4);
|
|
||||||
if (direction == 0) {
|
|
||||||
x += 1;
|
|
||||||
} else if (direction == 1) {
|
|
||||||
y += 1;
|
|
||||||
} else if (direction == 2) {
|
|
||||||
x -= 1;
|
|
||||||
} else if (direction == 3) {
|
|
||||||
y -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue