diff --git a/README.md b/README.md index 7754444..cc38efd 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# team02-AngryNerds-projekt1-racetrack -PM2 Team 02 Projekt 1 Racetrack + +#PM2 Team 02 Projekt 1 Racetrack Racetrack is a pen and paper game that dates back to the early 1960s in this version of the game, the game is digitalized and the math behind it is done automatically rather than calculated by hand and the winner gets informed automatically as well. The aim of the game is to finish the race faster than your opponent or win by being the only survivor in case the other cars crash. -In order to not crash you have to keep in mind the acceleration and other players car to get to the finish line safely. +In order to not crash you have to keep in mind the acceleration and other player's car to get to the finish line safely. # Initialization: #### The game can be initialized by the terminal command: diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Game.java b/src/main/java/ch/zhaw/pm2/racetrack/Game.java index 4203a3e..d9d2206 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Game.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Game.java @@ -2,7 +2,6 @@ package ch.zhaw.pm2.racetrack; import ch.zhaw.pm2.racetrack.given.GameSpecification; import ch.zhaw.pm2.racetrack.strategy.*; -import org.hamcrest.core.IsInstanceOf; import java.io.File; import java.io.FileNotFoundException; @@ -29,7 +28,8 @@ public class Game implements GameSpecification { } /** - * This method will initialize the game. Therefore it interacts with the user via UserInterface + * This method will initialize the game. Therefore, it interacts with the user via UserInterface + * * @return true if the initialization is completed. Returns false if there is an error. */ public boolean initPhase() { @@ -70,35 +70,35 @@ public class Game implements GameSpecification { moveStrategy = new UserMoveStrategy(userInterface, i, track.getCarId(i)); break; case 2: - for(File file : config.getMoveDirectory().listFiles()){ - if(file.toString().equals(config.getMoveDirectory().toString() + "\\" + selectedTrack.getName().split("\\.")[0] + "-car-" + track.getCar(i).getID() + ".txt")){ + for (File file : config.getMoveDirectory().listFiles()) { + if (file.toString().equals(config.getMoveDirectory().toString() + "\\" + selectedTrack.getName().split("\\.")[0] + "-car-" + track.getCar(i).getID() + ".txt")) { selectedFile = file; } } - if(selectedFile != null){ + if (selectedFile != null) { try { moveStrategy = new MoveListStrategy(selectedFile); } catch (FileNotFoundException e) { userInterface.printInformation("There is no Move-List implemented. Choose another Strategy!"); } - } else{ + } else { userInterface.printInformation("There is no Move-List implemented. Choose another Strategy!"); } break; case 3: - for(File file : config.getFollowerDirectory().listFiles()){ - if(file.toString().equals(config.getFollowerDirectory().toString() + "\\" + selectedTrack.getName().split("\\.")[0] + "_points.txt")){ + for (File file : config.getFollowerDirectory().listFiles()) { + if (file.toString().equals(config.getFollowerDirectory().toString() + "\\" + selectedTrack.getName().split("\\.")[0] + "_points.txt")) { selectedFile = file; } } - if(selectedFile != null){ + if (selectedFile != null) { try { moveStrategy = new PathFollowerMoveStrategy(selectedFile, track.getCarPos(currentCarIndex)); } catch (FileNotFoundException e) { userInterface.printInformation("There is no Point-List implemented. Choose another Strategy!"); } - } else{ + } else { userInterface.printInformation("There is no Point-List implemented. Choose another Strategy!"); } @@ -112,21 +112,24 @@ public class Game implements GameSpecification { } return true; } else { - userInterface.printInformation("No Trackfile found!"); + userInterface.printInformation("No track file found!"); return false; } } /** - * The functionality was taken out of init to automate testing + * Selects the desired track and returns it. + * The functionality was taken out of init to automate testing. + * * @param selectedTrack the Track which was selected by user */ - Track selectTrack(File selectedTrack) throws InvalidTrackFormatException,FileNotFoundException { + Track selectTrack(File selectedTrack) throws InvalidTrackFormatException, FileNotFoundException { track = new Track(selectedTrack); return track; } /** + * Sets a desired move strategy for a desired car. * The functionality was taken out of init to automate testing * * @param car to set the MoveStrategy @@ -148,7 +151,7 @@ public class Game implements GameSpecification { } /** - * Get the id of the specified car. + * Gets the id of the specified car. * * @param carIndex The zero-based carIndex number * @return A char containing the id of the car @@ -221,7 +224,7 @@ public class Game implements GameSpecification { *
The calling method must check the winner state and decide how to go on. If the winner is different * than {@link Game#NO_WINNER}, or the current car is already marked as crashed the method returns immediately.
* - * @param acceleration A Direction containing the current cars acceleration vector (-1,0,1) in x and y direction + * @param acceleration A Direction containing the current car's acceleration vector (-1,0,1) in x and y direction * for this turn */ @Override @@ -240,9 +243,9 @@ public class Game implements GameSpecification { } } int newWinPoints = track.calculateNewWinPoints(track.getCarPos(currentCarIndex), track.getCar(currentCarIndex).nextPosition()); - if(newWinPoints == 1){ + if (newWinPoints == 1) { track.getCar(currentCarIndex).increaseWinPoints(); - }else if(newWinPoints == -1){ + } else if (newWinPoints == -1) { track.getCar(currentCarIndex).deductWinPoints(); } if (crashPosition != null) { @@ -253,7 +256,8 @@ public class Game implements GameSpecification { } /** - * This method implements the gameflow in a while loop. If there is a winner. The method will return its carid. + * This method is in charge of changing the players and checking if a winner is found if there is no winner null will be returned. + * If a winner is found the game will return the char of the winning player. * * @return the ID of the winning car return null if there is no winner. */ @@ -265,7 +269,7 @@ public class Game implements GameSpecification { Direction direction; direction = track.getCar(currentCarIndex).getMoveStrategy().nextMove(); if (direction == null) { - if(track.getCar(currentCarIndex).getMoveStrategy() instanceof UserMoveStrategy){ + if (track.getCar(currentCarIndex).getMoveStrategy() instanceof UserMoveStrategy) { quit = true; direction = Direction.NONE; } else { @@ -317,51 +321,6 @@ public class Game implements GameSpecification { return track.calculatePointsOnPath(startPosition, endPosition); } - - /** - * This method will check if a car is passing the finishline. - * If the car is passing the finishline in the wrong direction, the car will lose a winpoint. - * If the car is passing the finishline in the correct direction, the car will gain a winpoint. - * @param start the startposition of the car - * @param finish the expected finishpositon of the car after the move - */ - private void calculateWinner(PositionVector start, PositionVector finish, int carIndex) { - List