当前位置: 代码迷 >> J2ME >> 各位大侠能不能帮帮小弟 检查一下,该怎么处理
  详细解决方案

各位大侠能不能帮帮小弟 检查一下,该怎么处理

热度:6364   发布时间:2013-02-25 21:33:41.0
各位大侠能不能帮帮小弟 检查一下
这段代码写好后始终无法实现计时过程,也没有游戏结束显示,知道的能不能告知一下 万分感激
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;

import java.util.*;
import java.io.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
public class UFOCanvas extends GameCanvas implements Runnable {
  private Display display;
  private boolean sleeping;
  private long frameDelay;
  private long gametime;
  private long gametimeoffset;
  private Random rand;
  private Image background;
  private Sprite ufoSprite;
  private Sprite holeredSprite;
  private Sprite holeblueSprite;
  private int holeoneX;
  private int holetwoX;
  private int holeoneY;
  private int holetwoY;
  private int a;
  private int ufoXSpeed, ufoYSpeed;
  private Sprite[] roidSprite = new Sprite[7];
  private boolean gameOver;
  private int numLives;
  private Player musicPlayer;
  private Player gameoverPlayer;
  public UFOCanvas(Display d) {
  super(true);
  display = d;
  frameDelay = 33;
  refresh();}
 private void refresh(){ 
  rand = new Random();
  holeoneY = rand.nextInt(240);
  holeoneX = rand.nextInt(200);
  holetwoY = rand.nextInt(200);
  holetwoX = rand.nextInt(240);
}
public void start() {
  display.setCurrent(this);
  gametime=0;
  gametimeoffset=System.currentTimeMillis(); 
  gameOver = false;
numLives = 2;
  try {
  background=Image.createImage("/Universe.png");
  holeredSprite = new Sprite(Image.createImage("/holeone.png")); 
  holeredSprite.setPosition(holeoneX,holeoneY);
  holeblueSprite = new Sprite(Image.createImage("/holetwo.png")); 
  holeblueSprite.setPosition(holetwoX,holetwoY);
  ufoSprite = new Sprite(Image.createImage("/Saucer.png"));
  ufoSprite.setPosition((getWidth() - ufoSprite.getWidth()) / 2, (getHeight() - ufoSprite.getHeight()) / 2);
  Image img = Image.createImage("/Roid.png");
  roidSprite[0] = new Sprite(Image.createImage("/Roid.png"));
  roidSprite[0] = new Sprite(img, 42, 35);
  roidSprite[1] = new Sprite(Image.createImage("/Roid.png"));
  roidSprite[1] = new Sprite(img, 42, 35);
  roidSprite[2] = new Sprite(Image.createImage("/Roid.png"));
  roidSprite[2] = new Sprite(img, 42, 35);
  roidSprite[3] = new Sprite(Image.createImage("/Roid.png"));
  roidSprite[3] = new Sprite(img, 42, 35);
  roidSprite[4] = new Sprite(Image.createImage("/Roid.png"));
  roidSprite[4] = new Sprite(img, 42, 35);
  roidSprite[5] = new Sprite(Image.createImage("/Roid.png"));
  roidSprite[5] = new Sprite(img, 42, 35);
  roidSprite[6] = new Sprite(Image.createImage("/Roid.png"));
  roidSprite[6] = new Sprite(img, 42, 35);}
  catch (IOException e) {
  System.err.println("Failed loading images!");
  }
   
  /*try {
  InputStream is = getClass().getResourceAsStream("Music.mid");
  musicPlayer = Manager.createPlayer(is, "audio/midi");
  musicPlayer.prefetch();
  is = getClass().getResourceAsStream("gameover.mid");