package src;
import java.io.*;
import java.util.Date;
import java.util.Random;
import javax.microedition.lcdui.*;
class Map
{
private static int px = 128;
private static int py = 128;
private static int picx = 13;
private static int picy = 13;
private static int mx = 10;
private static int my = 9;
private static int picCount = 14;
private Image image[];
private int rolex, roley, selectx, selecty;
private boolean flag = false;
private int map[][];
private static int e = 255;
private Image start;
private int imagecount;
private boolean load;
private boolean flagmap;
private int state;
private int number;
private int cx[], cy[], cmc;
private int sx, sy, ex, ey;
private boolean clean;
static int max = 10;
private int level[];
private int num;
private boolean timeFlag;
private Image end;
private int value;
public int gamex;
private int gameCount;
public Map()
{
rolex = 3;
roley = 3;
map = new int[my][mx];
cx = new int[my * 3];
cy = new int[my * 3];
for (int y = 0; y < my; y++)
{
for (int x = 0; x < mx; x++)
{
map[y][x] = e;
}
}
load = false;
clean = false;
imagecount = 0;
flagmap = false;
level = new int[max];
num = 0;
timeFlag = false;
value = 0;
gamex = 0;
gameCount = 0;
}
private int GetGameLevel()
{
int iV;
Date tDate = new Date();
Random tRand = new Random(tDate.getTime());
if ((num == 0) || (num == max))
{
iV = Math.abs(tRand.nextInt()) % max;
level[0] = iV;
num = 1;
return iV;
}
while(true)
{
iV = Math.abs(tRand.nextInt()) % max;
for (int i = 0; i < num; i++)
{
if (level[i] == iV)
break;
if (i == (num - 1))
{
num++;
level[i + 1] = iV;
return iV;
}
}
}
}
public boolean LoadGameLevelMap()
{
InputStream is = null;
int iT;
char iC;
String strFile;
iT = 0;
iC = 0;
timeFlag = false;
end = null;
value ++;
strFile = "/Res/Data/" + GetGameLevel() + ".llk";
try
{
is = getClass().getResourceAsStream(strFile);
for (int y = 0; y < my; y++)
{
for (int x = 0; x < mx; x++)
{
if ((y == 0) || (x == 0) || (y == my - 1)
|| (x == mx - 1))
{
map[y][x] = e;
continue;
}
iT = is.read();
iC = (char) iT;
map[y][x] = iC;
if (iC < picCount)
imagecount++;
}
}
is.close();
}
catch (java.io.IOException ex)
{
ex.printStackTrace();
return false;
}
flagmap = true;
return true;
}
public boolean LoadGameImage()
{
String strFileName;
if (load)
return true;
image = new Image[picCount];
strFileName = "";
for (int i = 0; i < picCount; i++)
{
try
{
strFileName = "/Res/Icons/" + i + ".png";
image[i] = Image.createImage(strFileName);
}
catch (java.io.IOException e)
{
e.printStackTrace();
return false;
}
}
try
{
start = Image.createImage("/Res/Icons/Statusbar.png");
}
catch (java.io.IOException e)
{
e.printStackTrace();
return false;
}
load = true;
return true;
}
public void LoadGameEndImg(boolean isSuccessFile)
{
String strFile;
if (isSuccessFile)
strFile = "/Res/Icons/End_Success.PNG";
else
strFile = "/Res/Icons/End_Failed.PNG";
try
{
end = Image.createImage(strFile);
}
catch (java.io.IOException e)
{
e.printStackTrace();
return;
}
}
public int DrawScreen(Graphics g, int iTimeCount, boolean bCleanFlag,boolean bCleanStart)
{
int iRtn;
iRtn = 0;
if (flagmap)
{
return iRtn;
}
if ((bCleanFlag) && (bCleanStart == false))
{
map[sy][sx] = e;
map[ey][ex] = e;
clean = false;
gameCount += 10;
if (imagecount == 0)
iRtn = 1;
}
PaintGameMap(g);
PaintCourse(g);
PaintStatusBar(g, iTimeCount);
if ((bCleanFlag) && (bCleanStart))
{
PaintCleanFlag(g);
}
if (timeFlag)
{
iRtn = 2;
}
return iRtn;
}
public void PaintGameEnd(Graphics g,int iTime)
{
String strGameAmt,strGameLevelValue,strTime;
strTime = String.valueOf(iTime);
strGameAmt = String.valueOf(gameCount);
strGameLevelValue = String.valueOf(value);;
try
{
g.drawImage(end, 0, 0, Graphics.LEFT | Graphics.TOP);
g.setColor(0, 0, 255);
g.drawString(strGameLevelValue, 55, 74, 33);
g.drawString(strGameAmt, 70, 94, 33);
g.drawString(strTime, 80, 114, 33);
} catch (Exception ex)
{
ex.printStackTrace();
}
}
private void PaintIniMap(Graphics g)
{
int iy, ihigh;
g.setColor(0, 223, 255);
iy = state * 8;
ihigh = (8 - state) * 18;
g.fillRect(0, iy, 128, ihigh);
System.out.println("PaintIniMap: " + state);
}
public void SetIniMapState(int ms)
{
state = ms;
if (ms == 0)
{
flagmap = false;
}
System.out.println("SetIniMapState: " + ms);
}
private void PaintCleanStatus()
{
System.out.println("sx:" + sx + "/sy:" + sy);
System.out.println("ex:" + ex + "/ey:" + ey);
for (int i = 0; i < cmc; i++) {
System.out.println("x:" + cx[i] + "/y:" + cy[i]);
}
}
public void PaintCleanFlag1(Graphics g)
{
int tx1, ty1, tx2, ty2;
g.setColor(2, 255, 2);
tx1 = 0;
ty1 = 0;
tx2 = 0;
ty2 = 0;
tx1 = cx[0];
ty1 = cy[0];
for (int i = 1; i < cmc; i++)
{
tx2 = cx[i];
ty2 = cy[i];
if ((tx1 == tx2) || (ty1 == ty2))
continue;
tx2 = cx[i - 1];
ty2 = cy[i - 1];
// up
if ((ty1 == 0) && (ty2 == 0))
{
if (tx1 == 0)
{
tx1 = 2;
}
else if (tx1 == mx - 1)
{
tx1 = 5 + tx1 * (tx1 - 1) * 13 + (tx1 - 1) * 2 + 2;
}
else
tx1 = 5 + tx1 * (tx1 - 1) * 13 + (tx1 - 1) * 2 + 6;
ty1 = 2;
if (tx2 == 0)
{
tx2 = 2;
}
else if (tx2 == mx - 1)
{
tx2 = 5 + tx2 * (tx2 - 1) * 13 + (tx2 - 1) * 2 + 2;
}
else
tx2 = 5 + tx2 * (tx2 - 1) * 13 + (tx2 - 1) * 2 + 6;
ty2 = 2;
// down
}
else if ((ty1 == my - 1) && (ty2 == my - 1))
{
if (tx1 == 0)
{
tx1 = 2;
}
else if (tx1 == mx - 1)
{
tx1 = 5 + tx1 * (tx1 - 1) * 13 + (tx1 - 1) * 2 + 2;
}
else
tx1 = 5 + tx1 * (tx1 - 1) * 13 + (tx1 - 1) * 2 + 6;
ty1 = 5 + ty1 * (ty1 - 1) * 13 + (ty1 - 1) * 2 + 2;
if (tx2 == 0)
{
tx2 = 2;
}
else if (tx2 == mx - 1)
{
tx2 = 5 + tx2 * (tx2 - 1) * 13 + (tx2 - 1) * 2 + 2;
}
else
tx2 = 5 + tx2 * (tx2 - 1) * 13 + (tx2 - 1) * 2 + 6;
ty2 = ty1;
// left
}
else if ((tx1 == 0) && (tx2 == 0))
{
if (ty1 == 0)
ty1 = 2;
else if (ty1 == my - 1)
ty1 = 5 + ty1 * (ty1 - 1) * 13 + (ty1 - 1) * 2 + 2;
else
ty1 = 5 + ty1 * (ty1 - 1) * 13 + (ty1 - 1) * 2 + 6;
tx1 = 2;
if (ty2 == 0)
ty2 = 2;
else if (ty2 == my - 1)
ty2 = 5 + ty2 * (ty2 - 1) * 13 + (ty2 - 1) * 2 + 2;
else
ty2 = 5 + ty2 * (ty2 - 1) * 13 + (ty2 - 1) * 2 + 6;
tx2 = 2;
//right
}
else if ((tx1 == mx - 1) && (tx2 == mx - 1))
{
if (ty1 == 0)
ty1 = 2;
else if (ty1 == my - 1)
ty1 = 5 + ty1 * (ty1 - 1) * 13 + (ty1 - 1) * 2 + 2;
else
ty1 = 5 + ty1 * (ty1 - 1) * 13 + (ty1 - 1) * 2 + 6;
tx1 = 5 + ty1 * (ty1 - 1) * 13 + (ty1 - 1) * 2 + 2;
if (ty2 == 0)
ty2 = 2;
else if (ty2 == my - 1)
ty2 = 5 + ty2 * (ty2 - 1) * 13 + (ty2 -
没有合适的资源?快使用搜索试试~ 我知道了~
J2ME开发技术原理与实践教程
共276个文件
class:89个
java:43个
png:38个
需积分: 0 49 下载量 160 浏览量
2008-07-08
09:31:15
上传
评论
收藏 605KB RAR 举报
温馨提示
J2ME开发技术原理与实践教程
资源详情
资源评论
资源推荐
收起资源包目录
J2ME开发技术原理与实践教程 (276个子文件)
GameMap.class 20KB
GameMap.class 15KB
RDGameCanvas.class 8KB
RDGameCanvas.class 7KB
MainMIDP.class 5KB
MainMIDP.class 5KB
MyCanvas.class 4KB
MIDletServer.class 4KB
MyCanvas.class 4KB
MyCanvas.class 4KB
GameCanvas.class 4KB
MIDletServer.class 4KB
MyCanvas.class 4KB
EnemyTank.class 4KB
Data.class 4KB
EnemyTank.class 4KB
GameCanvas.class 4KB
Data.class 4KB
Memoire.class 3KB
Sound.class 3KB
Memoire.class 3KB
Client.class 3KB
MainMIDlet.class 3KB
Sound.class 3KB
Client.class 3KB
MainMIDlet.class 3KB
UICanvas.class 3KB
RDMIDlet.class 3KB
ReadHTTP.class 3KB
Calculator.class 3KB
TankGame.class 3KB
ReadHTTP.class 3KB
MIDletMedia.class 3KB
RDMIDlet.class 3KB
UICanvas.class 3KB
TankGame.class 3KB
MIDletMedia.class 3KB
TankBom.class 3KB
Calculator.class 3KB
CalculatorMIDlet.class 3KB
Tel.class 3KB
Vedio.class 3KB
Tel.class 3KB
CalculatorMIDlet.class 2KB
Vedio.class 2KB
TankBom.class 2KB
AcceptMessage.class 2KB
AcceptMessage.class 2KB
SendMessage.class 2KB
SendMessage.class 2KB
Add.class 2KB
Add.class 2KB
EnemyTank$1.class 2KB
EnemyTank$1.class 2KB
BackGround.class 2KB
Bom.class 2KB
PingTu.class 2KB
BackGround.class 2KB
MyCanvas$1.class 2KB
PingTu.class 2KB
MiFengMove.class 2KB
Bom.class 2KB
MyComparator.class 2KB
MyCanvas$1.class 2KB
spriteArray.class 2KB
spriteArray.class 2KB
MiFengMove.class 2KB
SendFrame.class 2KB
AcceptSocket.class 1KB
SendFrame.class 1KB
InOutThread.class 1KB
MyComparator.class 1KB
SupportColor.class 1KB
SupportColor.class 1KB
RDGameCanvas$NewLayerManager.class 1KB
RDGameCanvas$NewLayerManager.class 1KB
MiFeng.class 1KB
MiFeng.class 1KB
ShiJian.class 1014B
ShiJian.class 1014B
UITimer.class 975B
MyCanvas.class 943B
UITimer.class 935B
MyCanvas.class 903B
Server.class 761B
Accept.class 709B
Accept.class 669B
TongJi.class 454B
TongJi.class 454B
.classpath 226B
.classpath 226B
.classpath 226B
.classpath 226B
.classpath 226B
.classpath 226B
.classpath 226B
.classpath 226B
.classpath 226B
.classpath 226B
.classpath 226B
共 276 条
- 1
- 2
- 3
vtudiv
- 粉丝: 24
- 资源: 46
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0