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 String name = "Thunfisch";
    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);
        trail.add(new int[]{0,0});
    }

    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) {
        trail.add(new int[]{x, y});
        if (trail.size() > TRAIL_LENGTH) {
            trail.poll();  // Entfernt das älteste Element
        }
    }


    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);
    }
}


