From 9869e8e74d1241fb263346244a62c812c311c80e Mon Sep 17 00:00:00 2001 From: romanschenk37 <84532681+romanschenk37@users.noreply.github.com> Date: Fri, 18 Mar 2022 16:48:37 +0100 Subject: [PATCH] fix in getWinner in Game.java --- src/main/java/ch/zhaw/pm2/racetrack/Game.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Game.java b/src/main/java/ch/zhaw/pm2/racetrack/Game.java index cdac7ab..94af85b 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Game.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Game.java @@ -128,10 +128,9 @@ public class Game implements GameSpecification { if (onlyOneCarLeft()) { return currentCarIndex; } - List cars = track.getCars(); - for (Car car : cars) { - if (car.getWinPoints() == 1) { - return car.getID(); // TODO: Index not ID + for (int i = 0; i < track.getCarCount(); i++) { + if (track.getCar(i).getWinPoints() == 1) { + return i; } } return NO_WINNER; @@ -294,8 +293,8 @@ public class Game implements GameSpecification { List path = calculatePath(start, finish); for (PositionVector point : path) { if (track.getSpaceType(point) != null) - { - switch (track.getSpaceType(point)) { //TODO: Case null + { + switch (track.getSpaceType(point)) { case FINISH_UP: if (start.getY() < finish.getY()) { track.getCar(carIndex).increaseWinPoints(); @@ -324,9 +323,9 @@ public class Game implements GameSpecification { track.getCar(carIndex).increaseWinPoints(); } break; - } + } - } + } } }