📄 gamethread.java
字号:
package net.frog_parrot.jump;/** * This class contains the loop that keeps the game running. * * @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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -