From 837297cd3102a9691d3e148e3ee96f6fbad524dd Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Fri, 18 Mar 2022 19:44:47 +0100 Subject: [PATCH] MoveListStrategy implemented --- src/main/java/ch/zhaw/pm2/racetrack/Game.java | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Game.java b/src/main/java/ch/zhaw/pm2/racetrack/Game.java index 7098a95..fa7df66 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Game.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Game.java @@ -47,28 +47,31 @@ public class Game implements GameSpecification { moveStrategies.add("Move List Strategy"); moveStrategies.add("Path Follow Move Strategy"); for (int i = 0; i < track.getCarCount(); i++) { - int moveStrategie = userInterface.selectOption( - "Select Strategy for Car " + i + " (" + track.getCarId(i) + ")", moveStrategies); - switch (moveStrategie + 1) { - case 1: - track.getCar(i).setMoveStrategy(new DoNotMoveStrategy()); - break; - case 2: - track.getCar(i).setMoveStrategy(new UserMoveStrategy(userInterface, i, track.getCarId(i))); - break; - case 3: - String path = ".\\moves\\ " + selectedTrack.getName().split("\\.")[0] + "-car-" + track.getCar(i).getID() + ".txt"; - try { - MoveStrategy moveStrategy = new MoveListStrategy(path); - track.getCar(i).setMoveStrategy(moveStrategy); - } catch (FileNotFoundException e) { - //TODO: what if not valid - } - //TODO: Backslash kompatibel für Linux - break; - case 4: - track.getCar(i).setMoveStrategy(new PathFollowerMoveStrategy()); //TODO: add Arguments - break; + while(track.getCar(i).getMoveStrategy() == null) { + int moveStrategie = userInterface.selectOption( + "Select Strategy for Car " + i + " (" + track.getCarId(i) + ")", moveStrategies); + switch (moveStrategie + 1) { + case 1: + track.getCar(i).setMoveStrategy(new DoNotMoveStrategy()); + break; + case 2: + track.getCar(i).setMoveStrategy(new UserMoveStrategy(userInterface, i, track.getCarId(i))); + break; + case 3: + String path = ".\\moves\\" + selectedTrack.getName().split("\\.")[0] + "-car-" + track.getCar(i).getID() + ".txt"; + System.out.println(path); + try { + MoveStrategy moveStrategy = new MoveListStrategy(path); + track.getCar(i).setMoveStrategy(moveStrategy); + } catch (FileNotFoundException e) { + userInterface.printInformation("There is no MoveList implemented. Choose another Strategy!"); + } + //TODO: Backslash kompatibel für Linux + break; + case 4: + track.getCar(i).setMoveStrategy(new PathFollowerMoveStrategy()); //TODO: add Arguments + break; + } } } return true;