|
|
@ -24,27 +24,25 @@ public class App { |
|
|
|
private void init() { |
|
|
|
menuManager = initMenuManager(); |
|
|
|
|
|
|
|
cli.clearConsole(); |
|
|
|
cli.getPrintStream().println("Welcome to the Cli Arcade Service!"); |
|
|
|
cli.getPrintStream().println("Press 'q' at any time to stop the application"); |
|
|
|
cli.getPrintStream().println("Select a item by typing the number next to it"); |
|
|
|
|
|
|
|
cli.getPrintStream().print(menuManager.getFormattedMenuList()); |
|
|
|
goToMenu(); |
|
|
|
} |
|
|
|
|
|
|
|
public void start() { |
|
|
|
isRunning = true; |
|
|
|
while (isRunning) { |
|
|
|
String input = cli.getScanner().nextLine(); |
|
|
|
if (input.equals("q")) { |
|
|
|
if (input.equals("exit")) { |
|
|
|
stop(); |
|
|
|
return; |
|
|
|
} else { |
|
|
|
if (inMenu) { |
|
|
|
cli.clearConsole(); |
|
|
|
cli.getPrintStream().println("Select a item by typing the number next to it"); |
|
|
|
selectMenuItem(input); |
|
|
|
} else { |
|
|
|
if (input.equals("q")) { |
|
|
|
goToMenu(); |
|
|
|
continue; |
|
|
|
} |
|
|
|
cli.clearConsole(); |
|
|
|
currentGame.update(input); |
|
|
|
currentGame.print(cli); |
|
|
@ -71,7 +69,6 @@ public class App { |
|
|
|
ArrayList<Menu> gameList = new ArrayList<>(); |
|
|
|
|
|
|
|
gameList.add(new Menu("Tic Tac Toe")); |
|
|
|
gameList.add(new Menu("Tic Toe")); |
|
|
|
|
|
|
|
Menu gameMenu = new Menu("Games"); |
|
|
|
|
|
|
@ -87,6 +84,11 @@ public class App { |
|
|
|
|
|
|
|
protected void selectMenuItem(String input) { |
|
|
|
Scanner scanner = new Scanner(input); |
|
|
|
|
|
|
|
if (input.equals("q") && !menuManager.inRootMenu()) { |
|
|
|
goToMenu(); |
|
|
|
} |
|
|
|
|
|
|
|
if (scanner.hasNextInt()) { |
|
|
|
int index = scanner.nextInt() - 1; |
|
|
|
menuManager.select(index); |
|
|
@ -108,7 +110,7 @@ public class App { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
cli.getPrintStream().print(menuManager.getFormattedMenuList()); |
|
|
|
printMenu(); |
|
|
|
} |
|
|
|
|
|
|
|
private void setCurrentGame(Game game) { |
|
|
@ -117,4 +119,26 @@ public class App { |
|
|
|
cli.clearConsole(); |
|
|
|
currentGame.print(cli); |
|
|
|
} |
|
|
|
|
|
|
|
private void goToMenu() { |
|
|
|
inMenu = true; |
|
|
|
currentGame = null; |
|
|
|
while (!menuManager.inRootMenu()) { |
|
|
|
try { |
|
|
|
menuManager.back(); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
printMenu(); |
|
|
|
} |
|
|
|
|
|
|
|
private void printMenu() { |
|
|
|
cli.clearConsole(); |
|
|
|
cli.getPrintStream().println("Welcome to the Cli Arcade Service!"); |
|
|
|
cli.getPrintStream().println("Type 'exit' at any time to stop the application"); |
|
|
|
cli.getPrintStream().println("Select a item by typing the number next to it"); |
|
|
|
|
|
|
|
cli.getPrintStream().print(menuManager.getFormattedMenuList()); |
|
|
|
} |
|
|
|
} |