gamethread.java

来自「Java版PRG游戏——跳动的牛仔」· Java 代码 · 共 95 行

JAVA
95
字号
package net.frog_parrot.jump;/** * This class contains the loop that keeps the game running. * Download by http://www.codefans.net * @author Carol Hamer */public class GameThread extends Thread {  //---------------------------------------------------------  //   fields  /**   * Whether or not the main thread would like this thread    * to pause.   */  boolean myShouldPause;  /**   * Whether or not the main thread would like this thread    * to stop.   */  static boolean myShouldStop;  /**   * Whether or not this thread has been started.   */  boolean myAlreadyStarted;  /**   * A handle back to the graphical components.   */  JumpCanvas myJumpCanvas;  //----------------------------------------------------------  //   initialization  /**   * standard constructor.   */  GameThread(JumpCanvas canvas) {    myJumpCanvas = canvas;  }  //----------------------------------------------------------  //   actions  /**   * start or pause or unpause the game.   */  void go() {    if(!myAlreadyStarted) {      myAlreadyStarted = true;      start();    } else {      myShouldPause = !myShouldPause;    }  }  /**   * pause the game.   */  void pause() {    myShouldPause = true;  }  /**   * stops the game.   */  static void requestStop() {    myShouldStop = true;  }  /**   * start the game..   */  public void run() {    // flush any keystrokes that occurred before the     // game started:    myJumpCanvas.flushKeys();    myShouldStop = false;    myShouldPause = false;    while(true) {      if(myShouldStop) {	break;      }      if(!myShouldPause) {	myJumpCanvas.checkKeys();	myJumpCanvas.advance();      }    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?