個人認為游戲最難控制的就是這些線程了。如果游戲復雜的話。為了避免資源沖突,死鎖等。這方面對程序要求是很高的。還好。我那個游戲很簡單,所以就不用考慮到這些。
只要一個最重要的東西就行了。
java 代碼
- //無非是要程序不停的運行,直到游戲結束為之
- while (true) {
- game.run();
- try {
- Thread.sleep(80);
- } catch (InterruptedException ie) {
- }
- }
java 代碼
-
-
-
-
-
- package org.wuhua.battleplan;
-
- import javax.microedition.lcdui.Display;
-
-
-
-
-
-
-
-
-
-
-
- public class GameThread implements Runnable {
-
- private Game game;
- GameThread(){
- game = new Game();
- }
- public void run() {
- gameRun();
-
- }
-
- public void init(){
- game.init();
- }
- public void open(Display d){
- d.setCurrent(game);
- }
-
- private void gameRun() {
- while (true) {
- game.run();
- try {
- Thread.sleep(80);
- } catch (InterruptedException ie) {
- }
- }
-
- }
-
- }
|