OOP_Letourneux_Lopategui_Pi.../Agent.java

48 lines
1.2 KiB
Java

package backend;
import java.awt.Color;
import java.util.ArrayList;
public abstract class Agent {
protected int x;
protected int y;
protected Color color;
public int triggerRadius; // adds a radius for the animal to detect nearby food/entities
public int intelligence; // adds the capacity for an animal to get straight to its goal
// | 1 ==> will get lost on its way
// | 3 ==> will lose time on its way
// | 5 ==> will get straight to the target
protected Agent(int x, int y, Color color, int triggerRadius, int intelligence) {
this.x = x;
this.y = y;
this.color = color;
this.triggerRadius = triggerRadius;
this.intelligence = intelligence;
}
public Color getDisplayColor() {
return color;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public void changeColor(Color newColor) {
this.color = newColor;
}
public boolean isInArea(int x, int y, int radius) {
int diffX = this.x-x;
int diffY = this.y-y;
int dist = (int) Math.floor(Math.sqrt(diffX*diffX+diffY*diffY));
return dist<radius;
}
public abstract boolean liveTurn(ArrayList<Agent> neighbors, Simulator world);
}