日期:2014-05-20  浏览次数:20835 次

关于坦克大战游戏的画面暂停与恢复问题
各位大侠,一下代码要怎样才能使得游戏可以暂停又恢复,我知道暂停只要在线程里的循环里给一个判断,然后continue;但是怎么恢复画面呢
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
PaintThread tt = new PaintThread();

if (e.getActionCommand().equals("NewGame")) {

new TankClient(); //游戏主版面构造


else if (e.getActionCommand().endsWith("Stop")) {

// b=1;
// tt.run();
System.out.println("暂停!");


else if (e.getActionCommand().equals("Continue")) {
System.out.println("继续");
// b = 2;
// tt.run();
} else if (e.getActionCommand().equals("Exit")) {

System.out.println("退出");
System.exit(0);

} else if (e.getActionCommand().equals("help")) {

// MyHelpPanel mhp = new MyHelpPanel();
// this.remove(msp);
// this.add(mhp);
// this.setVisible(true);
}
}


private class PaintThread implements Runnable {
public void run() {
// TODO Auto-generated method stub
while (true) {
// if(变量)continue;
repaint(); //重画画面
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}


------解决方案--------------------
其实你只要给用户一个暂停的感觉就行了。
你的线程可以继续循环做下去,只是总在重绘静止的画面就行了。