63 lines
1.3 KiB
Java
63 lines
1.3 KiB
Java
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;
|
|
Queue<int[]> trail = new LinkedList<>();
|
|
|
|
ArduinoCommunication arduinoCommunicator;
|
|
|
|
|
|
|
|
private final int TRAIL_LENGTH = 30;
|
|
|
|
// Konstruktor
|
|
public Player(int id, String finalIpAddress, int finalPortNr) {
|
|
this.ID = id;
|
|
arduinoCommunicator = new ArduinoCommunication(finalIpAddress, finalPortNr);
|
|
}
|
|
|
|
public int getX(){
|
|
return x;
|
|
}
|
|
|
|
public int getY(){
|
|
return y;
|
|
}
|
|
|
|
|
|
//fügt 2 Koordinaten zum Trail hinzu nd verhindert, dass dieser zulang wird
|
|
public void setKoords(int x, int y){
|
|
addToTrail(x,y);
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
|
|
private void addToTrail(int x, int y) {
|
|
this.trail.add(new int[]{x, y});
|
|
|
|
if(trail.size() > TRAIL_LENGTH){
|
|
trail.poll();
|
|
}
|
|
}
|
|
|
|
public Queue<int[]> getTrail(){
|
|
return trail;
|
|
}
|
|
|
|
public void sendToCar(int light, double steer, double speed){
|
|
arduinoCommunicator.sendMessage(light, steer, speed);
|
|
}
|
|
|
|
|
|
//gibt aktuelle Position aus
|
|
public void printPosition() {
|
|
System.out.println(trail);
|
|
}
|
|
}
|
|
|
|
|