import java.io.IOException;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.LayerManager;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.lcdui.game.TiledLayer;
//////////////////////////////////////////////
//游戏类
// 游戏场景,游戏过程;
///////////////////////////////////////////////
public class MyGame extends GameCanvas
implements Runnable
{
static boolean musicON = true;
public static int stage,score,GetXue,GetShengming;
public static LayerManager lm;
public static GameSpringe
sprock,spDownRock, //石头
spjiguan,spjiguan1,spjiguan2, //机关
spzhangai, //障碍
splouti,splouti1,splouti2, //楼梯
spmen, //门
spjian,spjian1,spjian2,spjian3,//箭
spgunR1,spgunR2,spgunD1, //棍
spxin, //心
spbaozhang,spbaozhang1; //宝藏
public static GameOgre
spguai,spguai1,spguai2,spguai3,spguai4; //怪
public static GamePlayer player;
public static PlayMusic pp;
public static TiledLayer tlqiang;
private TiledLayer tlbeijing;
private Image map,caidan,beijing;
private Image tou,xue,shengming;
public static Sprite spxue,sptou,spshengming;
public static boolean isL,isR,isD,isU,isOK,isDown,isJump,isUandD;
//游戏画面
public static Displayable instance;
private boolean isKey,isEndGame,islose,flag,isMOV;
public static boolean ispause,isTime;
private int i;
private int mapqiang1[][]= {
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1,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, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 3 },
{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3 }
};
private int mapbeijing1 [][] = {
{ 5, 2, 1, 5, 6, 6 },
{ 8, 6, 1, 8, 1, 2 },
{ 1, 6, 2, 3, 1, 7 },
{ 2, 2, 1, 1, 2, 5 },
{ 2, 6, 3, 1, 2, 8 },
{ 5, 4, 5, 2, 1, 2 },
{ 8, 1, 8, 2, 6, 4 }
};
private int mapbeijing2[][] = {
{ 1, 1, 1, 1, 1, 1 },
{ 3, 3, 3, 3, 3, 3 },
{ 3, 4, 3, 3, 3, 3 },
{ 3, 3, 3, 3, 3, 3 },
{ 3, 3, 3, 3, 3, 3 },
{ 3, 3, 3, 3, 4, 3 },
{ 3, 3, 3, 3, 3, 3 }
};
private int mapbeijing3 [][] = {
{ 1, 1, 1, 1, 1, 1 },
{ 3, 2, 3, 3, 3, 3 },
{ 3, 3, 3, 3, 3, 3 },
{ 4, 4, 4, 4, 4, 4 },
{ 3, 3, 3, 3, 3, 3 },
{ 3, 3, 3, 3, 3, 3 },
{ 3, 3, 3, 3, 3, 3 }
};
long StartGameTime = 0;
long EedGameTime = 0;
long em = 0,mm = 0;
//创建并得到一个游戏画面的对象
synchronized public static Displayable getInstance()
{
instance = null;
if(instance == null)
instance = new MyGame();
return instance;
}
protected MyGame()
{
super(false);
setFullScreenMode(true);
stage = 1;
score = 0;
GetXue = 2;
i = 1;
GetShengming = 3;
isUandD = false;
isL = true;
isR = true;
isU = false;
isD = false;
isDown = true;
isJump = false;
isOK = false;
isKey = false;
islose = false;
isEndGame = false;
flag = true;
ispause = false;
isTime = true;
isMOV = true;
try
{
caidan = Image.createImage("/res/caidan.png");
}
catch(Exception e)
{}
Thread t = new Thread(this);
t.start();
}
protected void initGame()
{
switch (stage)
{
case 1:
isOK = false;
lm = null;
player = null;
tlqiang = null;
beijing = null;
tlbeijing = null;
pp = null;
sprock = null;
spjiguan = null;
splouti = null;
spjian = null;
spguai = null;
spmen = null;
spxue = null;
spshengming = null;
sptou = null;
tou = null;
x