Skip to content

Instantly share code, notes, and snippets.

@andreybleme
Created February 5, 2019 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreybleme/95441ec039fbf9591f57b71054f3eabe to your computer and use it in GitHub Desktop.
Save andreybleme/95441ec039fbf9591f57b71054f3eabe to your computer and use it in GitHub Desktop.
andreybleme.com | Regactoring RPG Game
public void runGame() {
System.out.print(ANSI_CYAN + " WELCOME TO RPG GAME " + ANSI_RESET);
menuLoop: while (true) {
System.out.print("\n\nType the number of an option below to continue: ");
System.out.print(ANSI_BLUE + "\n 1" + ANSI_RESET +" New Game");
System.out.print(ANSI_BLUE + "\n 2" + ANSI_RESET +" Load Game");
System.out.print(ANSI_BLUE + "\n 9" + ANSI_RESET +" Exit");
System.out.print(ANSI_BLUE + "\n\n > " + ANSI_RESET);
Integer option = in.nextInt();
switch (option) {
case NEW_GAME:
System.out.print("\nType here the name of your new Character");
System.out.print(ANSI_BLUE + "\n\n > " + ANSI_RESET);
in.nextLine();
String name = in.nextLine();
command = new NewGameCommand(name);
command.execute();
break;
case LOAD_GAME:
command = new LoadGameCommand(null);
command.execute();
break;
case EXIT_GAME:
break menuLoop;
default:
System.out.print(ANSI_RED + "\nYou typed an invalid option." + ANSI_RESET);
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment