From e15927408594ddc426740bb89337edb8a2f02896 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 11 Mar 2022 10:37:54 +0100 Subject: [PATCH] finished method currentCarIndex, switchToNextActiveCar, willCarCrash --- src/main/java/ch/zhaw/pm2/racetrack/Game.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Game.java b/src/main/java/ch/zhaw/pm2/racetrack/Game.java index db3fe53..85363e8 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Game.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Game.java @@ -82,8 +82,7 @@ public class Game implements GameSpecification { */ @Override public int getCurrentCarIndex() { - // TODO: implementation - throw new UnsupportedOperationException(); + return currentCarIndex; } /** @@ -163,8 +162,12 @@ public class Game implements GameSpecification { */ @Override public void switchToNextActiveCar() { - // TODO: implementation - throw new UnsupportedOperationException(); + do { + if (currentCarIndex++ > track.getCarCount()) { + currentCarIndex = 0; + } + } while (track.getCar(currentCarIndex).isCrashed()); + // TODO: evtl andere Kapselung } /** @@ -181,7 +184,7 @@ public class Game implements GameSpecification { */ @Override public List calculatePath(PositionVector startPosition, PositionVector endPosition) { - ArrayList pathList = new ArrayList(); + ArrayList pathList = new ArrayList<>(); // Use Bresenham's algorithm to determine positions. int x = startPosition.getX(); int y = startPosition.getY(); @@ -246,7 +249,13 @@ public class Game implements GameSpecification { @Override public boolean willCarCrash(int carIndex, PositionVector position) { + List positionList = calculatePath(track.getCarPos(carIndex),position); + for(PositionVector location : positionList) { + if(track.willCrashAtPosition(location)) { + return true; + } + } + return false; - return true; } }