Exemple #1
0
  /**
   * This method sets up everything, including the GUI and the game data, and starts the timer,
   * which will force state updates and rendering. Note that rendering will not be seen until the
   * game's window is set visible.
   *
   * @param appTitle the name of the game application, it will be put in the window's title bar.
   * @param initFramesPerSecond the frame rate to be used for running the game application. This
   *     refers to how many times each second the game state is updated and rendered.
   */
  public void initMiniGame(String appTitle, int initFramesPerSecond) {
    // KEEP THE TITLE AND FRAME RATE
    name = appTitle;
    framesPerSecond = initFramesPerSecond;

    // CALCULATE THE TIME EACH FRAME SHOULD TAKE
    frameDuration = 1000 / framesPerSecond;

    // CONSTRUCT OUR LOCK, WHICH WILL MAKE SURE
    // WE ARE NOT UPDATING THE GAME DATA SIMULATEOUSLY
    // IN TWO DIFFERENT THREADS
    dataLock = new ReentrantLock();

    // AND NOW SETUP THE FULL APP. NOTE THAT SOME
    // OF THESE METHODS MUST BE CUSTOMLY PROVIDED FOR
    // EACH GAME IMPLEMENTATION
    initAudio();
    initWindow();
    initData();
    initGUI();
    initHandlers();
    initTimer();

    // LET THE USER START THE GAME ON DEMAND
    data.setGameState(MiniGameState.NOT_STARTED);
  }