📄 penguinscreen.java
字号:
* 用来记录并计算得分
*/
private int Score = 0;
private int ActualScore = 0;
/**
* 每个路标间隔
*/
private int ScoreGap = 100;
public int curScore = 0;
public int highScore = 0;
/**
* 存储图片
*/
private static Image mapImage;
private static Image menuImage;
private static Image runImage;
private static Image uploadImage;
/**
* 用户输入
*/
boolean FireKey = false;
int RemainSecond = 20;
/*
* 网络排名
*/
private NetData http;
public static int netScore[] = new int[5];
public static byte netName[][] = new byte[6][];
public static int netOrder[] = new int[5];
public static int netNameLen[] = new int[5];
public String httpData;
/*
* Load网络数据
*/
private int paintLoadPos = 0;
private boolean bNetStart = false;
private boolean bNetStop = false;
private long netTimeOut = 0;
private long errorTimeOut = 0;
private int posInHttpData = -1;
private static int PreState = MENU;
/*
* 各类的 图象 变量赋值
*/
static {
try {
mapImage = Image.createImage("/copyright.png");
menuImage = Image.createImage("/menu.png");
runImage = Image.createImage("/run.png");
uploadImage = Image.createImage("/loading.png");
for (int i = 0; i < 6; i++) {
name[i] = new byte[6];
}
for (int i = 0; i < 6; i++) {
netName[i] = new byte[16];
}
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
/**Construct the displayable*/
public PenguinScreen(PenguinMIDlet gameMIDlet) {
/**
* 初始化双buffer和声音变量
*/
try {
BufferSurface = Image.createImage(178, 208);
LastBuffer = Image.createImage(74, 58);
gsprite = LastBuffer.getGraphics();
ThisBuffer = Image.createImage(80, 56);
Bg = ThisBuffer.getGraphics();
pOnce = new MediaList("/logo.ott", "audio/midi");
pMain = new MediaList("/main.ott", "audio/midi");
pRecord = new MediaList("/record.ott", "audio/midi");
pReady = new MediaList("/ready.ott", "audio/midi");
pJump = new MediaList("/Jump.ott", "audio/midi");
pKnock = new MediaList("/Knock.ott", "audio/midi");
pDrop = new MediaList("/Drop.ott", "audio/midi");
pSlide = new MediaList("/Slide.ott", "audio/midi");
phut = new MediaList("/phut.ott", "audio/midi");
}
catch (Exception e) {
}
this.gameMIDlet = gameMIDlet;
/**
* 根据图片位置来初始化菜单,菜单机制见文档
*/
tempMenuNode = new MenuNode[9];
tempMenuNode[0] = new MenuNode(-1, 176, 5 * 18, 72, 18, INIT);
tempMenuNode[1] = new MenuNode(-1, 176, 6 * 18, 72, 18, OPTION);
tempMenuNode[2] = new MenuNode(-1, 176, 7 * 18, 72, 18, MENU);
tempMenuNode[3] = new MenuNode(-1, 176, 8 * 18, 72, 18, HELP);
tempMenuNode[4] = new MenuNode(-1, 176, 9 * 18, 72, 18, END);
tempMenuNode[5] = new MenuNode(-1, 176, 4 * 18, 72, 18, LINK);
tempMenuNode[6] = new MenuNode(2, 176, 0, 72, 18, LOCAL);
tempMenuNode[7] = new MenuNode(2, 176, 1 * 18, 72, 18, NET);
tempMenuNode[8] = new MenuNode(2, 176, 3 * 18, 72, 18, MENU);
menuArrow = new MenuNode( -1, 149, 208, 83, 24, -1);
mainMenu = new Menu(tempMenuNode, menuArrow, 55, 120, 1);
tempMenuNode = new MenuNode[2];
tempMenuNode[0] = new MenuNode( -1, 258, 168, 28, 14, RUN);
tempMenuNode[1] = new MenuNode( -1, 258, 182, 28, 14, MENU);
menuArrow = new MenuNode( -1, 189, 224, 16, 16, -1);
pauseMenu = new Menu(tempMenuNode, menuArrow, 78, 90, 0);
tempMenuNode = new MenuNode[2];
tempMenuNode[0] = new MenuNode( -1, 0, 91, 12, 12, LOCAL);
tempMenuNode[1] = new MenuNode( -1, 25, 91, 12, 12, SCOREUPLOAD);
menuArrow = new MenuNode( -1, 52, 91, 27, 18, -1);
uploadMenu = new Menu(tempMenuNode, menuArrow, 67, 109, 2);
uploadMenu.MENUITEMCELL = 38;
//demoAction array
for (int i = 0; i < 20; i++) {
demoAction[i] = -1;
}
//optionMenu array
for (int i = 0; i < optionMenu.length; i++) {
optionMenu[i] = 0;
}
// bDemo=true;
//Load score
loadRecord();
if (optionMenu[0] == 0) {
bDemo = true;
}
else {
bDemo = false;
}
if (optionMenu[1] == 0) {
bSound = true;
}
else
{
bSound = false;
}
}
/**
* 产生随机数
* @param maxvalue 结果最大值
* @return 大于等于零,小于maxvalue 的随机值
*/
public static int rand(int maxvalue) {
return (random.nextInt() << 1 >>> 1) % maxvalue;
}
/**
* 画图
* @param g 图形设备
* @param image 图片缓冲
* @param destX 屏幕坐标
* @param destY 屏幕坐标
* @param srcX 图片坐标
* @param srcY 图片坐标
* @param width 绘图尺寸
* @param height 绘图尺寸
*/
public static void drawImageEx(Graphics g, Image image, int destX,
int destY, int srcX, int srcY, int width,
int height) {
g.setClip(destX, destY, width, height);
g.drawImage(image, destX - srcX, destY - srcY, 0);
}
//画字符串
public static void drawStringEx(Graphics g, String str, int destX,
int destY, int width, int height) {
int strWidth = g.getFont().stringWidth(str);
int strHeight = g.getFont().getHeight();
int x = destX + (width - strWidth) / 2;
int y = destY + (height - strHeight) / 2;
g.setClip(destX, destY, width, height);
g.drawString(str, x, y, 0);
}
//带裁切的画图
public static void drawImageClip(Graphics g, Image image, int destX,
int destY, int srcX, int srcY, int width,
int height,
int clipX, int clipY, int clipWidth,
int clipHeight) {
int clipLeft, clipTop;
int clipRight, clipBottom;
clipLeft = destX;
clipTop = destY;
clipRight = destX + width;
clipBottom = destY + height;
if (clipX > clipLeft)
clipLeft = clipX;
if (clipY > clipTop)
clipTop = clipY;
if (clipX + clipWidth < clipRight)
clipRight = clipX + clipWidth;
if (clipY + clipHeight < clipBottom)
clipBottom = clipY + clipHeight;
g.setClip(clipLeft, clipTop, clipRight - clipLeft,
clipBottom - clipTop);
g.drawImage(image, destX - srcX, destY - srcY, 0);
}
/**
* 更新游戏状态,根据状态和上面定义的静态数组来切换所用图片
* @param void
*/
public void UpdateState(int newState) {
int oldStateGroup = -1;
int nowStateGroup = -1;
for (int i = 0; i < stateArray.length; i++) {
for (int j = 0; j < stateArray[i].length; j++) {
if (state == stateArray[i][j]) {
oldStateGroup = i;
}
if (newState == stateArray[i][j]) {
nowStateGroup = i;
}
if ( (oldStateGroup != -1) && (nowStateGroup != -1))break;
}
if ( (oldStateGroup != -1) && (nowStateGroup != -1))break;
}
if ( (nowStateGroup != -1) && (nowStateGroup != oldStateGroup)) {
switch (nowStateGroup) {
case 0:
// initMap("/copyright.png");
break;
case 1:
initMap(runImage);
break;
case 2:
initMap(menuImage);
break;
case 3:
initMap(uploadImage);
break;
default:
break;
}
}
bStateMapEntry = true;
bStateStringEntry = true;
state = newState;
}
/**
* 更新游戏运行中状态
*/
public void UpdateGameState(int newState) {
bGameStateMapEntry = true;
bGameStateStringEntry = true;
gameState = newState;
}
/**
* 主进程暂时停止
*/
public void delay(int num) {
try {
Thread.currentThread();
Thread.sleep(num);
}
catch (InterruptedException e) {
}
}
/**
* 根据存在手机上的数据读出高分记录
*/
public void loadRecord() {
byte data[] = null;
int len = -1;
int MaxRecord = 0;
// load from record
try {
//penguin 是文件名
RecordStore rs = RecordStore.openRecordStore("penguin", true);
if (rs.getNumRecords() >= 1) {
len = rs.getRecordSize(1);
data = new byte[len];
rs.getRecord(1, data, 0);
}
rs.closeRecordStore();
}
catch (Exception E) {
System.out.println(E.getMessage());
}
// read data
if (len > 0) {
ByteArrayInputStream byteInput = new ByteArrayInputStream(data);
DataInputStream input = new DataInputStream(byteInput);
// 读出设置里头Demo和音乐的开关
try {
optionMenu[0] = input.readInt();
optionMenu[1] = input.readInt();
}
catch (Exception e) {
System.out.println("read error" + e.getMessage());
}
// record list,读出名字和分数以及初始化高分和姓名长度数组
for (int i = 0; i < recordCnt; i++) {
try {
// input name
for (int j = 0; j < 6; j++) {
name[i][j] = input.readByte();
}
// input record
newsreel[i] = input.readInt();
if (newsreel[i] >= MaxRecord) {
MaxRecord = newsreel[i];
}
namelen[i] = input.readInt();
}
catch (Exception E) {
System.out.println(E.getMessage());
}
}
}
//BangBang Record,设置默认高分记录,其中保存在名字中的是字母表中的位置比如1代表'B',22代表'W'
if (MaxRecord == 0) {
name[0][0] = 1;
name[0][1] = 1;
name[0][2] = 22;
newsreel[0] = 200;
namelen[0] = 3;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -