48 lines
1.0 KiB
Java
48 lines
1.0 KiB
Java
import java.util.Arrays;
|
|
import java.util.LinkedList;
|
|
import java.util.Queue;
|
|
|
|
public class Player {
|
|
// Attribute für die x- und y-Koordinaten
|
|
private final int ID;
|
|
private int x;
|
|
private int y;
|
|
private final int TRAIL_LENGTH;
|
|
Queue<int[]> trail = new LinkedList<>();
|
|
|
|
// Konstruktor
|
|
public Player(int id, int trailLength) {
|
|
this.ID = id;
|
|
this.TRAIL_LENGTH = trailLength;
|
|
trail.add(new int[]{0,0});
|
|
}
|
|
|
|
public int getX(){
|
|
return x;
|
|
}
|
|
|
|
public int getY(){
|
|
return y;
|
|
}
|
|
|
|
//fügt 2 Koordinaten zum Trail hinzu und verhindert, dass dieser zu lang wird
|
|
public void setKoords(int x, int y){
|
|
addToTrail(x,y);
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
|
|
private void addToTrail(int x, int y) {
|
|
trail.add(new int[]{x, y});
|
|
if (trail.size() > TRAIL_LENGTH) {
|
|
trail.poll(); // Entfernt das älteste Element
|
|
}
|
|
}
|
|
|
|
public Queue<int[]> getTrail(){
|
|
return trail;
|
|
}
|
|
}
|
|
|
|
|