Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/TimNekk/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public void run() {

if (menuItem == MenuItem.PRINT_HIGHEST_PLAYER_SCORE) {
messageView.printHighestPlayerScore();
} else if (menuItem == MenuItem.EXIT) {
throw new IllegalStateException("Exit");
} else {
startGame();
endGame();
Expand Down
6 changes: 5 additions & 1 deletion src/TimNekk/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ public static void main(String[] args) {
Application application = new Application();

while (true) {
application.run();
try {
application.run();
} catch (IllegalStateException e) {
break;
}
}
}
}
3 changes: 2 additions & 1 deletion src/TimNekk/controller/MenuController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public MenuController(Scanner scanner, GameFlow gameFlow) {
public MenuItem handlerMenuInput() {
MenuItem menuItem = getMenuItem();

if (menuItem != MenuItem.PRINT_HIGHEST_PLAYER_SCORE) {
try {
gameFlow.setGameMode(GameMode.fromMenuItem(menuItem));
} catch (IllegalArgumentException ignored) {
}

return menuItem;
Expand Down
3 changes: 2 additions & 1 deletion src/TimNekk/model/MenuItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ public enum MenuItem {
PLAYER_VS_SIMPLE_BOT(1, "Player VS Bot"),
PLAYER_VS_ADVANCED_BOT(2, "Player VS Advanced Bot"),
PLAYER_VS_PLAYER(3, "Player VS Player"),
PRINT_HIGHEST_PLAYER_SCORE(4, "Print Highest Player Score");
PRINT_HIGHEST_PLAYER_SCORE(4, "Print Highest Player Score"),
EXIT(5, "Exit");

private final int number;
private final String name;
Expand Down