From e6fc0fde396ea5dfe433d08d00445859162f99ce Mon Sep 17 00:00:00 2001 From: romanschenk37 <84532681+romanschenk37@users.noreply.github.com> Date: Fri, 18 Mar 2022 17:23:50 +0100 Subject: [PATCH 1/2] fix in makeCarMoveInTrack in Track.java (redraw finish line if car was on finish line) --- .../java/ch/zhaw/pm2/racetrack/Track.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Track.java b/src/main/java/ch/zhaw/pm2/racetrack/Track.java index 0593222..a1ace12 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Track.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Track.java @@ -60,6 +60,7 @@ public class Track implements TrackSpecification { private List track; private List cars; private final List finishLine; + private ConfigSpecification.SpaceType finishTyp; /** * Initialize a Track from the given track file. @@ -132,7 +133,7 @@ public class Track implements TrackSpecification { if (finishLine.size() == 0) { throw new InvalidTrackFormatException(); } - ConfigSpecification.SpaceType finishTyp = getSpaceType(finishLine.get(0)); + finishTyp = getSpaceType(finishLine.get(0)); for (PositionVector positionVector : finishLine) { if (getSpaceType(positionVector) != finishTyp) { throw new InvalidTrackFormatException(); @@ -207,12 +208,20 @@ public class Track implements TrackSpecification { * @param carIndex of the current car */ private void makeCarMoveInTrack(int carIndex) { - PositionVector positionVector = findChar(getCarId(carIndex)); + PositionVector carPositionVector = findChar(getCarId(carIndex)); //Removes the Car at Current Pos - drawCharOnTrackIndicator(positionVector, ConfigSpecification.SpaceType.TRACK.getValue()); + drawCharOnTrackIndicator(carPositionVector, ConfigSpecification.SpaceType.TRACK.getValue()); + + //Redraw finishline if Car was on finish-line Position + for(PositionVector finishLinePositionVector : finishLine){ + if(finishLinePositionVector.equals(carPositionVector)){ + drawCharOnTrackIndicator(carPositionVector, finishTyp.getValue()); + } + } + //Adds Car at new Position - positionVector = cars.get(carIndex).nextPosition(); - drawCharOnTrackIndicator(positionVector, cars.get(carIndex).getID()); + carPositionVector = cars.get(carIndex).nextPosition(); + drawCharOnTrackIndicator(carPositionVector, cars.get(carIndex).getID()); } /** From dad57ea8ac44ca42ad4978eed23403d3e159a42e Mon Sep 17 00:00:00 2001 From: romanschenk37 <84532681+romanschenk37@users.noreply.github.com> Date: Fri, 18 Mar 2022 17:32:16 +0100 Subject: [PATCH 2/2] fix in CardoesCrash in Track.java (remove Car when crash) --- src/main/java/ch/zhaw/pm2/racetrack/Track.java | 14 ++++++++------ 1 file changed, 8 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 a1ace12..c83839e 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Track.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Track.java @@ -231,7 +231,7 @@ public class Track implements TrackSpecification { * @return true if car would crash. Else false. */ public boolean willCrashAtPosition(int carIndex, PositionVector positionVector) throws PositionVectorNotValid { - isPositionVectorOnTrack(positionVector); + isPositionVectorOnTrack(positionVector); //TODO: remove this line? Or Method? char charAtPosition = track.get(positionVector.getY()).charAt(positionVector.getX()); if (getCarId(carIndex) == charAtPosition) return false; return !(charAtPosition == ConfigSpecification.SpaceType.TRACK.value || @@ -245,14 +245,16 @@ public class Track implements TrackSpecification { * This Method will make the Car Crash. In Track and in the Car Object * * @param carIndex representing current Car - * @param positionVector where the Crash did happen + * @param crashPositionVector where the Crash did happen */ - public void carDoesCrash(int carIndex, PositionVector positionVector) throws PositionVectorNotValid{ - isPositionVectorOnTrack(positionVector); + public void carDoesCrash(int carIndex, PositionVector crashPositionVector) throws PositionVectorNotValid{ + isPositionVectorOnTrack(crashPositionVector); //TODO: remove this line? and Method? + PositionVector currentCarPosition = getCarPos(carIndex); + drawCharOnTrackIndicator(new PositionVector(currentCarPosition.getX(), currentCarPosition.getY()), ConfigSpecification.SpaceType.TRACK.getValue()); Car car = cars.get(carIndex); car.crash(); - car.setPosition(positionVector); - drawCharOnTrackIndicator(new PositionVector(positionVector.getX(), positionVector.getY()), CRASH_INDICATOR); + car.setPosition(crashPositionVector); + drawCharOnTrackIndicator(new PositionVector(crashPositionVector.getX(), crashPositionVector.getY()), CRASH_INDICATOR); } /**