From 007d8ee3937d6268cfb9a706056ce577b6cac252 Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Mon, 7 Mar 2022 17:49:55 +0100 Subject: [PATCH] =?UTF-8?q?-=20Methoden=20=C3=BCberarbeitet=20Teils=20prov?= =?UTF-8?q?isorisch=20da=20genaue=20Umsetzung=20noch=20unklar=20Siehe=20TO?= =?UTF-8?q?DO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ch/zhaw/pm2/racetrack/Track.java | 47 ++++++++++++++----- .../java/ch/zhaw/pm2/racetrack/TrackTest.java | 4 +- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Track.java b/src/main/java/ch/zhaw/pm2/racetrack/Track.java index 8e74c93..688ee61 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Track.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Track.java @@ -94,7 +94,7 @@ public class Track implements TrackSpecification { } } - public void findCar() { + public void addCar() { ConfigSpecification.SpaceType[] spaceTypes = ConfigSpecification.SpaceType.values(); ArrayList allSpaceTypesAsChar = new ArrayList<>(); @@ -113,6 +113,19 @@ public class Track implements TrackSpecification { } + private PositionVector findChar(char symbol) { + PositionVector vector = null; + for (int i = 0; i < track.size(); i++) { + String line = track.get(i); + for (int j = 0; j < line.length(); j++) { + if (line.charAt(j) == symbol) { + vector = new PositionVector(j,i); + } + } + } + return vector; + } + private void findFinish() { //TODO: @@ -155,8 +168,9 @@ public class Track implements TrackSpecification { */ @Override public int getCarCount() { - // TODO: implementation - throw new UnsupportedOperationException(); + // TODO: error??? + return cars.size(); + //throw new UnsupportedOperationException(); } /** @@ -167,8 +181,9 @@ public class Track implements TrackSpecification { */ @Override public Car getCar(int carIndex) { - // TODO: implementation - throw new UnsupportedOperationException(); + // TODO: error??? + return cars.get(carIndex); + //throw new UnsupportedOperationException(); } /** @@ -179,8 +194,9 @@ public class Track implements TrackSpecification { */ @Override public char getCarId(int carIndex) { - // TODO: implementation - throw new UnsupportedOperationException(); + // TODO: error??? + return cars.get(carIndex).getID(); + //throw new UnsupportedOperationException(); } /** @@ -191,8 +207,14 @@ public class Track implements TrackSpecification { */ @Override public PositionVector getCarPos(int carIndex) { - // TODO: implementation - throw new UnsupportedOperationException(); + // TODO: nextPosition or Position of Trackfile? + //Alternative 1 + return cars.get(carIndex).nextPosition(); + + //Alternative 2 //NULL aussschliessen falls umgesetzt. + return findChar(cars.get(carIndex).getID()); + + //throw new UnsupportedOperationException(); } /** @@ -203,8 +225,9 @@ public class Track implements TrackSpecification { */ @Override public PositionVector getCarVelocity(int carIndex) { - // TODO: implementation - throw new UnsupportedOperationException(); + // TODO: error??? + return cars.get(carIndex).getVelocity(); + //throw new UnsupportedOperationException(); } /** @@ -229,7 +252,7 @@ public class Track implements TrackSpecification { */ @Override public String toString() { - // TODO: implementation + // TODO: error??? String str = ""; for (String line : track) { str += line+"\n"; diff --git a/src/test/java/ch/zhaw/pm2/racetrack/TrackTest.java b/src/test/java/ch/zhaw/pm2/racetrack/TrackTest.java index c040580..6821ea9 100644 --- a/src/test/java/ch/zhaw/pm2/racetrack/TrackTest.java +++ b/src/test/java/ch/zhaw/pm2/racetrack/TrackTest.java @@ -44,8 +44,8 @@ public class TrackTest { //TODO: @Test - void findCarAtInit() { - trackObj.findCar(); + void addCarAtInit() { + trackObj.addCar(); } }