Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Game;
- import utils.ConsoleUtils;
- public class GameController {
- private static GameLogic gameLogic;
- private GameController() {
- gameLogic = new GameLogic();
- Menu.welcomeMessage();
- Menu.showCommands();
- }
- public static void main(String[] args) {
- boolean hasGameStarted = false;
- // Lazy hack, clean this up
- while( !hasGameStarted || gameLogic.isGameOver() ) {
- for ( String arg : args ) {
- hasGameStarted = arg.matches( Menu.startGamePattern );
- }
- String input = ConsoleUtils.getInput("Enter a command");
- hasGameStarted = input.matches( Menu.startGamePattern );
- if ( input.matches( Menu.quitGamePattern ) ) {
- gameLogic.endGame();
- } else if ( input.matches( Menu.reportGamePattern ) ) {
- System.out.println("Game hasn't started yet");
- } else {
- System.out.println("Invalid command!\n");
- }
- }
- gameLogic.start(); //Player sets the hidden number
- while( !gameLogic.isGameOver() ) {
- String input = ConsoleUtils.getInput("Enter a command");
- if ( input.matches( Menu.quitGamePattern ) ) {
- gameLogic.endGame();
- } else if ( input.matches( Menu.reportGamePattern ) ) {
- System.out.println( String.format("You made %d guesses so far.", gameLogic.getAttempts()));
- } else if( input.matches( Menu.makeGuessPattern )) {
- gameLogic.makeGuess();
- } else {
- System.out.println("Invalid command!\n");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement