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