⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gamethread.java

📁 Source code for j2me game WordSearch
💻 JAVA
字号:
package wordSearch20;/** * This class contains the loop that keeps the game running. * * @author Jeremiah McLeod xdebugx http://www.xdebugx.net */public class GameThread extends Thread {  //---------------------------------------------------------  //   fields  /**   * Whether or not this thread has been started.   */  boolean myAlreadyStarted;  private long runTime,lastCPSTTime;  int cps,cyclesThisSecond;  final int MS_PER_FRAME=41;  /**   * A handle back to the graphical components.   */  mainCanvas myMainCanvas;  //----------------------------------------------------------  //   initialization  /**   * standard constructor.   */  GameThread(mainCanvas canvas) {    myMainCanvas = canvas;  }  //----------------------------------------------------------  //   actions  /**   * start or pause or unpause the game.   */  void go() {    if(!myAlreadyStarted) {      myAlreadyStarted = true;      start();    } else {    }  }  /**   * pause the game.   */  void pause() {  }  /**   * stops the game.   */  static void requestStop() {  }  /**   * start the game..   */  public void run() {   runTime=0;	  runTime=System.currentTimeMillis();	  lastCPSTTime=0;   while(true) {   runTime=System.currentTimeMillis();   myMainCanvas.advance();      if (System.currentTimeMillis()-lastCPSTTime>1000)      {		  lastCPSTTime=System.currentTimeMillis();		  cps=cyclesThisSecond;		 // System.out.println ("cps "+cps);		  cyclesThisSecond=0;	  } else	  cyclesThisSecond++;	  long timeSinceStart=(runTime-System.currentTimeMillis());	  if (timeSinceStart<MS_PER_FRAME) {	  try	  {		  if ((MS_PER_FRAME - timeSinceStart)-((System.currentTimeMillis()-lastCPSTTime)-(cyclesThisSecond*MS_PER_FRAME))>0) Thread.sleep((MS_PER_FRAME - timeSinceStart)-((System.currentTimeMillis()-lastCPSTTime)-(cyclesThisSecond*MS_PER_FRAME)));	  }	  catch (java.lang.InterruptedException e)	  {}  } //if}// while}}

⌨️ 快捷键说明

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