Skip to content
Snippets Groups Projects
Commit 94326f68 authored by iliya's avatar iliya
Browse files

feat: asking user if he wants to restore a game

parent 7f92a908
No related branches found
No related tags found
No related merge requests found
package hepia; package hepia;
import java.io.IOException;
import java.util.Scanner; import java.util.Scanner;
/** /**
* App * App
*/ */
public class App { public class App {
private static final Scanner scanner = new Scanner(System.in);
public static boolean askUserToLoadGame() {
String input;
boolean inputCorrect = false;
do {
System.out.println();
System.out.println("Would you like to load an existing game ? [y/n] ");
input = scanner.next();
switch (input) {
case "y":
return true;
case "n":
return false;
default:
break;
}
} while (!inputCorrect);
public static void main(String[] args) { return false;
Scanner scanner = new java.util.Scanner(System.in); }
public static void main(String[] args) throws IOException{
if (askUserToLoadGame()) {
System.out.print("Please specify the path to the `.ser` file: ");
String filePath = scanner.next();
try {
GameManager.restoreGame(filePath);
} catch (Exception e) {
System.err.println("Game couldn't be restored");
System.exit(1);
}
} else {
System.out.print("How many decks of cards would like to create: "); System.out.print("How many decks of cards would like to create: ");
int nbDecks = scanner.nextInt(); int nbDecks = scanner.nextInt();
System.out.print("Please specify the amount of human players: "); System.out.print("Please specify the amount of human players: ");
...@@ -24,7 +56,6 @@ public class App { ...@@ -24,7 +56,6 @@ public class App {
foo.initBets(nbHumanPlayers, nbBasicAi, nbAdvancedAi); foo.initBets(nbHumanPlayers, nbBasicAi, nbAdvancedAi);
foo.runGame(); foo.runGame();
}
scanner.close();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment