From 46e6b838c216f110e04fbbf0a96a70d9aa913fda Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Thu, 10 Mar 2022 14:43:34 +0100 Subject: [PATCH] =?UTF-8?q?-=20Methoden=20=C3=BCberarbeitet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ch/zhaw/pm2/racetrack/Track.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Track.java b/src/main/java/ch/zhaw/pm2/racetrack/Track.java index 5cc9993..2596103 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Track.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Track.java @@ -193,15 +193,21 @@ public class Track implements TrackSpecification { //Adds Car at new Position positionVector = cars.get(carIndex).nextPosition(); line = track.get(positionVector.getY()); - line = line.substring(0,positionVector.getX()) + cars.get(carIndex).getId() + line.substring(positionVector.getX()+1); + line = line.substring(0,positionVector.getX()) + cars.get(carIndex).getID() + line.substring(positionVector.getX()+1); track.add(positionVector.getY(),line); //Change position of car getCar(carIndex).move(); } - public char getRealCharAtPosition(PositionVector positionVector) { - return track.get(positionVector.getY()).charAt(positionVector.getX()); + /** + * This Method will check if the Car could crash at the specific position + * @param positionVector the position to check if the car could crash + * @return true if car would crash. Else false. + */ + public boolean willCrashAtPosition(PositionVector positionVector) { + char charAtPosition = track.get(positionVector.getY()).charAt(positionVector.getX()); + return charAtPosition != ConfigSpecification.SpaceType.TRACK.value; } /** @@ -255,7 +261,7 @@ public class Track implements TrackSpecification { */ @Override public char getCarId(int carIndex) { - return cars.get(carIndex).getId(); + return cars.get(carIndex).getID(); } /** @@ -267,7 +273,7 @@ public class Track implements TrackSpecification { */ @Override public PositionVector getCarPos(int carIndex) { - return findChar(cars.get(carIndex).getId()); + return findChar(cars.get(carIndex).getID()); } /** @@ -294,7 +300,7 @@ public class Track implements TrackSpecification { public char getCharAtPosition(int y, int x, Config.SpaceType currentSpace) { char charAtPos = track.get(y).charAt(x); for (Car car : cars) { - if(charAtPos == car.getId()) { + if(charAtPos == car.getID()) { if(car.isCrashed()) { return CRASH_INDICATOR; }