📄 gamethread.java
字号:
package cutOff;/** * This class contains the loop that keeps the game running. * * @author Jeremiah McLeod xdebugx */public class GameThread extends Thread { //--------------------------------------------------------- // fields /** * Whether or not this thread has been started. */ boolean myAlreadyStarted; /** * A handle back to the graphical components. */ cutOffCanvas myCutOffCanvas;private long runTime;final int MS_PER_FRAME=25; //---------------------------------------------------------- // initialization /** * standard constructor. */ GameThread(cutOffCanvas canvas) { myCutOffCanvas = 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=System.currentTimeMillis(); while(true) { myCutOffCanvas.advance(); long timeSinceStart=(System.currentTimeMillis()-runTime); if (timeSinceStart<MS_PER_FRAME) { try { Thread.sleep(MS_PER_FRAME - timeSinceStart); } catch (java.lang.InterruptedException e) {}}runTime=System.currentTimeMillis();}}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -