Game #23

Merged
schrom01 merged 43 commits from Game into main 2022-03-20 16:56:34 +01:00
3 changed files with 37 additions and 13 deletions
Showing only changes of commit fc78b10365 - Show all commits

View File

@ -190,7 +190,7 @@ public class Game implements GameSpecification {
}
}
public int gamePhase() throws PositionVectorNotValid {
public String gamePhase() throws PositionVectorNotValid {
while (CarsMoving() && getWinner() == NO_WINNER) {
userInterface.printTrack(track);
Direction direction = null;
@ -203,7 +203,11 @@ public class Game implements GameSpecification {
switchToNextActiveCar();
}
userInterface.printTrack(track);
return getWinner();
int indexWinner = getWinner();
if(indexWinner == NO_WINNER){
return null;
}
return String.valueOf(track.getCar(indexWinner).getID());
}
/**

View File

@ -7,23 +7,34 @@ import java.util.List;
public class Main {
public static void main(String[] args) throws InvalidTrackFormatException, FileNotFoundException, PositionVectorNotValid {
boolean exit = false;
UserInterface userInterface = new UserInterface("Hello and Welcome");
while (!exit) {
UserInterface userInterface = new UserInterface("Hello and Welcome to Racetrack by Team02-\"AngryNerds\"");
while (true) {
Game game = new Game(userInterface);
int winner = 0;
String winner;
if (game.initPhase()) {
winner = game.gamePhase();
}
List<String> optionsNewGame = new ArrayList<>();
optionsNewGame.add("exit");
optionsNewGame.add("new game");
int selectedOption = userInterface.selectOption("The Winner was Car : " + winner + "\nStart new Game?", optionsNewGame);
String winnerText;
if(winner == null){
winnerText = "There was no winner.";
}
else {
winnerText = "The Winner was Car " + winner;
}
int selectedOption = userInterface.selectOption(winnerText + "\nStart new Game?", optionsNewGame);
if(selectedOption == 0) {
exit = true;
userInterface.quit("Thank you and goodbye\npress enter to close the application.");
break;
}
}
userInterface.printInformation("Thank you and goodbye");
else {
userInterface.quit("The initialisation of the game failed. Press enter to close the application.");
break;
}
}
}
}

View File

@ -97,6 +97,15 @@ public class UserInterface {
textTerminal.println(track.toString());
}
/**
* Method to dispose the Textterminal
* @param text OUtput Text
*/
public void quit(String text){
textIO.newStringInputReader().withMinLength(0).read(text);
textTerminal.dispose();
}
}