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