📄 thread.java
字号:
package net.frog_parrot.jump:
/* this class contains the loop that keeps the game running.*/
public class GameThread extends Thread
{
static boolean myShouldStop; //whether or not the main thread would like this thread to stop
boolean myAreadyStarted;//whether or not this thread has been started
JumpCanvas myJumpCanvas;//a handle back to the graphical components.
//standard constructor.
GameThread(JumpCanvas canvas)
{
myJumpCanvas = canvas;
}
//start or pause or unpause the game
void go()
{
if(!myAlreadyStarted)
{
myAlreadyStarted = true;
start();
}
else
{
myShouldPause = !myShouldPause;
}
}
void pause()
{
myShouldPause = true;
}
/**
* stops the game
*/
static void requestStop()
{
myShouldStop = true;
}
/**
* start the game
*/
public void run()
{
//flush any keystrokes that occured 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 + -