Пример #1
0
  @Override
  protected void newGame() {
    try {
      File templateFile =
          new File(this.getTemplateFolder() + this.getFileSeparator() + "2x12_8x8.xml");

      if (!templateFile.exists()) {
        GameLoader gameLoader = new GameLoader(GamePlayer.getInputStream("templates/2x12_8x8.xml"));

        new GameSaver(gameLoader.getEngine().getBoard(), templateFile);
      }

      GameLoader gameLoader = new GameLoader(templateFile);

      NewGameConfigurator configurator = new NewGameConfigurator(gameLoader, this);

      if (configurator.isResult()) {
        this.engine = configurator.getEngine();
        this.engine.addTurnListener(this.turnListener);
        this.setBoardWidget(new BoardWidget(this.engine.getBoard()));
        this.displayMessage(
            getEngine().getBoard().getCurrentPlayer().getName() + ", it's your turn.");
      }
    } catch (Exception e) {
      this.displayMessage(e.getMessage());
    }
  }
Пример #2
0
 // method to load and start a saved game, called by the "Ladda spel" button"
 private void runSavedGame() {
   if (!mGameInAction) // can only be done if no game is active
   {
     abortGame();
     Game game = mLoader.loadGame("savedgames"); // set the folder where the game is to be stored
     if (game != null) {
       mGUI.getBoard().setButtons(game.getButtons());
       mGUI.getTimePanel()
           .getDisplay()
           .setTime(game.getHours(), game.getMinutes(), game.getSeconds());
       mSolved = false;
       mGUI.getBoard().boardUpdate();
       extractLockedValues(); // important only to read buttons from original game
       try {
         mSolver.run(mCurrentValues);
       } catch (Exception ex) {
         // No need to do anything, game is already checked
       }
       getSolution();
       extractValuesFromBoard(); // now get all values to get current board
       mGUI.getTimePanel().start();
       mGameInAction = true;
       mLoader.nullGame();
     }
   }
 }
Пример #3
0
  public static void main(String[] args) {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
    }

    if (args.length == 0) {
      new GamePlayer();
    } else if (args.length == 1) {
      GameLoader gameLoader = new GameLoader(GamePlayer.getInputStream("templates/2x12_8x8.xml"));

      new GamePlayer(gameLoader.getEngine().getBoard());
    }
  }
Пример #4
0
 // start a new game, called by "Nytt spel"" button
 private void runNewGame() {
   if (!mGameInAction) // can only be done if no game is active
   {
     mGUI.getTimePanel().stop();
     mGUI.getTimePanel().reset();
     clearBoard(); // just to be sure nothing remains
     Game game = mLoader.loadGame("newgames"); // set the folder from where new game is retrieved
     if (game != null) {
       mGUI.getBoard().setButtons(game.getButtons()); // set the buttons
       startGame();
       mLoader.nullGame();
     }
   }
 }
Пример #5
0
  public void run() {
    Game gameObject = null;
    Dimension dimension = new Dimension(640, 480);
    boolean fullscreen = false;

    if (action.equals("Tutorial5_1")) {
      gameObject =
          new Tutorial5_1() {
            protected void notifyExit() {}
          };

    } else if (action.equals("Tutorial5_2")) {
      gameObject = new Tutorial5_2();
      fullscreen = true;

    } else if (action.equals("Tutorial6")) {
      gameObject =
          new Tutorial6() {
            protected void notifyExit() {}
          };

    } else if (action.equals("Tutorial7_1")) {
      gameObject =
          new Tutorial7_1() {
            protected void notifyExit() {}
          };

    } else if (action.equals("Tutorial7_2")) {
      gameObject =
          new Tutorial7_2() {
            protected void notifyExit() {}
          };

    } else if (action.equals("Tutorial7_3")) {
      gameObject =
          new Tutorial7_3() {
            protected void notifyExit() {}
          };

    } else if (action.equals("Tutorial8_1")) {
      gameObject =
          new Tutorial8_1() {
            protected void notifyExit() {}
          };

    } else if (action.equals("Tutorial8_2")) {
      gameObject =
          new Tutorial8_2() {
            protected void notifyExit() {}
          };

    } else if (action.equals("Tutorial8_3")) {
      gameObject =
          new Tutorial8_3() {
            protected void notifyExit() {}
          };

    } else if (action.equals("Tutorial9_1")) {
      gameObject =
          new Tutorial9_1() {
            protected void notifyExit() {}
          };

    } else if (action.equals("Tutorial9_2")) {
      gameObject =
          new Tutorial9_2() {
            protected void notifyExit() {}
          };

    } else if (action.equals("Tutorial10")) {
      gameObject =
          new Tutorial10() {
            protected void notifyExit() {}
          };

    } else if (action.equals("Tutorial11")) {
      gameObject =
          new Tutorial11() {
            protected void notifyExit() {}
          };
    }

    // create the game!
    GameLoader game = new GameLoader();
    game.setup(gameObject, dimension, fullscreen);
    game.start();
  }