diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 74217e8..23426a4 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,14 +4,7 @@
-
-
-
-
-
-
-
-
+
@@ -38,10 +31,6 @@
@@ -73,7 +62,7 @@
1732108904989
-
+
@@ -83,23 +72,7 @@
1732109548353
-
-
- 1732109721570
-
-
-
- 1732109721570
-
-
-
- 1732109899753
-
-
-
- 1732109899753
-
-
+
@@ -118,8 +91,6 @@
-
-
-
+
\ No newline at end of file
diff --git a/src/main/java/ArduinoCommunicator.java b/src/main/java/ArduinoCommunicator.java
index 4a2bab4..96dbefe 100644
--- a/src/main/java/ArduinoCommunicator.java
+++ b/src/main/java/ArduinoCommunicator.java
@@ -1,2 +1,35 @@
+import com.illposed.osc.OSCMessage;
+import com.illposed.osc.transport.OSCPortOut;
+
+import java.net.InetAddress;
+import java.util.Arrays;
+
public class ArduinoCommunicator {
+ private InetAddress address;
+ private int port;
+ private OSCPortOut oscPortOut;
+
+ public ArduinoCommunicator(String ipAdress, int portNr) {
+ try{
+ address = InetAddress.getByName(ipAdress);
+ port = portNr;
+ oscPortOut = new OSCPortOut(address, port);
+ }
+ catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ public void sendMessage(double speed, double steer, boolean light){
+ String oscAddress = "/arduino/command"; // OSC-Adresse für die Nachricht
+ OSCMessage message = new OSCMessage(oscAddress, Arrays.asList(speed, steer, light));
+
+ try {
+ oscPortOut.send(message);
+ }
+ catch (Exception e){
+ e.printStackTrace();
+ }
+ System.out.println("OSC Nachricht gesendet: " + message);
+ }
}
diff --git a/src/main/java/GameLogic.java b/src/main/java/GameLogic.java
deleted file mode 100644
index f52c9f4..0000000
--- a/src/main/java/GameLogic.java
+++ /dev/null
@@ -1,40 +0,0 @@
-pu
- Player
- objekte
- private Player player1 = new Player(0, 0);
- private Player player2 = new Player(0, 0);
-
- setUp()
-
- // Playerobjekte
- private Player player1 = new Player(0, 0);
- private Player player2 = new Player(0, 0);
-
-
- d set
- {}()pU
- iov etavirpleLogic gl = newmaG tatic void main(String[
- {}sgra ])ic class GameLogic g
- publ.run;
- {
-
-
- private void run(){
-
- }
-
- private void trackPlayer1(){
-
- }
- private void drawGrafics(){
-
- }
-
- private void trackPlayer2(){
-
- }
- private void checkPlayerCollission(){
-
- }
-
- }
diff --git a/src/main/java/Player.java b/src/main/java/Player.java
index 74df381..94d4df1 100644
--- a/src/main/java/Player.java
+++ b/src/main/java/Player.java
@@ -3,34 +3,53 @@ import java.util.Queue;
public class Player {
// Attribute für die x- und y-Koordinaten
- private int id;
- private int trailLength = 30;
+ private final int ID;
+ private int x;
+ private int y;
Queue trail = new LinkedList<>();
- // Konstruktor zur Initialisierung der Koordinaten
- public Player(int id) {
- this.id = id;
+ ArduinoCommunicator arduinoCommunicator;
+
+
+
+ private final int TRAIL_LENGTH = 30;
+
+ // Konstruktor
+ public Player(int id, String finalIpAddress, int finalPortNr) {
+ this.ID = id;
+ arduinoCommunicator = new ArduinoCommunicator(finalIpAddress, finalPortNr);
}
- //fügt 2 Koordinaten zum Trail hinzu und verhindert, dass dieser zulang wird
- public void addToTrail(int x, int 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() > trailLength){
+ if(trail.size() > TRAIL_LENGTH){
trail.poll();
}
-
}
-
+
public Queue getTrail(){
return trail;
}
+ public void sendToCar(double speed, double steer, boolean light){
+ arduinoCommunicator.sendMessage(speed, steer, light);
+ }
+
//gibt aktuelle Position aus
public void printPosition() {
- System.out.println("Player Position: (" + x + ", " + y + ")");
+ System.out.println(trail);
}
}