Пример #1
0
 public void run() {
   while (true) {
     try {
       boardViewer.tick();
     } catch (UserInteruptException e) {
       GenericMainMenu mainMenu =
           MainMenuFactory.createMainMenu(
               mainMenuType, gameProd.getPlatform(), gameProd.getServices());
       gameProd.getPlatform().getDisplay().setCurrent(mainMenu);
     } catch (GameOverException e) {
       GenericMainMenu mainMenu =
           MainMenuFactory.createMainMenu(
               mainMenuType, gameProd.getPlatform(), gameProd.getServices());
       mainMenu.setMessage(e.getMessage());
       gameProd.getPlatform().getDisplay().setCurrent(mainMenu);
     }
     try {
       Thread.sleep(20);
     } catch (Exception ex) {
     }
   }
 }
  /** This code runs the game in a different thread. */
  @Override
  public void run() {
    while (this.isRunning) {
      try {
        // Tell model to update, send next key press.
        // or 0 if no new keypress since last update.
        this.gameModel.gameUpdate(nextKeyPress());

        this.view.repaint();

        Thread.sleep(this.updateInterval);
      } catch (GameOverException e) {
        // we got a game over signal, time to exit...
        // The current implementation ignores the game score
        this.isRunning = false;
        System.out.println("Game over: " + e.getScore());
      } catch (InterruptedException e) {
        // if we get this exception, we're asked to terminate ourselves
        this.isRunning = false;
      }
    }
  }