看到网上1个别人没做完的小游戏,小弟我重新写过了1下,原码发出来给大家看看(有点混乱),麻烦给点意见,大家交流1下
//=====================主类midlet==============================
/*
* MobileGame.java
*
* Created on 2007年2月19日, 上午8:45
*/
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
/**
*
* @author Victor
* @version
*/
public class MobileGame extends MIDlet {
private Display display=null;
private GameWorld gameworld=null;
public MobileGame(){
gameworld=new GameWorld();
display=Display.getDisplay(this);
}
public void startApp() {
gameworld.start();
display.setCurrent(gameworld);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
//=====================背景类==============================
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.TiledLayer;
import
java.io.IOException;
/**
*
* @author Victor
*/
public class BackGround extends TiledLayer {
static public Image imgbg=null;
static int map[][]=new int[][]{{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
/** Creates a new instance of BackGround */
protected BackGround(int cols,int rows,Image img,int width,int height) {
super(cols,rows,img,width,height);
}
public static BackGround loadImage(){
try{
imgbg=Image.createImage( "/CityBackGround.png ");
System.out.println( "Heightbg "+imgbg.getHeight()+ " Widthbg "+imgbg.getWidth());
}catch(
IOException imgError){System.out.println( "imgErroe "+imgError);}
BackGround background=new BackGround(4,4,imgbg,60,80);
for(int i=0;i <4;i++){
for(int j=0;j <4;j++)
background.setCell(j,i,map[i][j]);
}
return background;
}
}
//======================敌人类==========================
/*
* Enemy.java
*
* Created on 2007年2月20日, 下午3:09
*
* To change this template, choose Tools | Template Manager