📄 gamescreen.java
字号:
import com.nokia.mid.ui.FullCanvas;
import java.util.Random;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
public class Gamescreen extends FullCanvas {
public Gamescreen(MIDlet midlet1) {
midlet = midlet1;
r1 = new Run(this);
t1 = new Thread(r1);
r1.sleepTime = 100;
t1.start();
rnd = new Random();
try {
mbounce = Image.createImage("/image/mbounce.png");
} catch (Exception exception) {}
}
private void init() {
player = new Player();
player.resetMotion();
reset();
player.setup();
gamestate = -1;
rank = new Ranking();
getRank();
}
private void reset() {
score = 0;
stepOK = false;
currentArrow = 0;
pandaFlag = 0;
frame = 0;
level = 1;
player.setup();
arrowNum = 3;
con = false;
}
private void loadImage() {
try {
chImg = Image.createImage("/image/ch.png");
pandaImg = Image.createImage("/image/panda.png");
bgImg = Image.createImage("/image/bg.png");
bgpatternImg = Image.createImage("/image/bgpattern.png");
arrowImg = Image.createImage("/image/arrow.png");
btitle01Img = Image.createImage("/image/btitle01.png");
btitle02Img = Image.createImage("/image/btitle02.png");
lifeImg = Image.createImage("/image/life.png");
hitcloudImg = Image.createImage("/image/hitcloud.png");
pattern01Img = Image.createImage("/image/pattern01.png");
pattern02Img = Image.createImage("/image/pattern02.png");
maintitleImg = Image.createImage("/image/maintitle.png");
menuwordImg = Image.createImage("/image/menuword.png");
buttonImg = Image.createImage("/image/button.png");
lvImg = Image.createImage("/image/lv.png");
nosImg = Image.createImage("/image/nos.png");
swordImg = Image.createImage("/image/sword.png");
ns = new Nsound();
} catch (Exception exception) {}
}
private void paintBigTitle01(Graphics g, int i, int j, int k) {
g.setClip(i, j, 97, 24);
Graphics _tmp = g;
Graphics _tmp1 = g;
g.drawImage(btitle01Img, i - k * 97, j, 0x10 | 4);
g.setClip(0, 0, 128, 128);
}
private void paintBigTitle02(Graphics g, int i, int j, int k) {
g.setClip(i, j, 81, 19);
Graphics _tmp = g;
Graphics _tmp1 = g;
g.drawImage(btitle02Img, i - k * 81, j, 0x10 | 4);
g.setClip(0, 0, 128, 128);
}
private void paintLife(Graphics g) {
g.setColor(0, 0, 0);
g.fillRect(0, 0, 128, 10);
g.setColor(255, 252, 0);
g.fillRect(25, 4, 50, 3);
for (int i = 0; i < player.life; i++) {
Graphics _tmp = g;
Graphics _tmp1 = g;
g.drawImage(lifeImg, 26 + i * 9, 2, 0x10 | 4);
}
g.setClip(76, 2, 20, 7);
Graphics _tmp2 = g;
Graphics _tmp3 = g;
g.drawImage(swordImg, 76, 2, 0x10 | 4);
paintNumber(g, score, 95, 2, 4);
Graphics _tmp4 = g;
Graphics _tmp5 = g;
g.drawImage(lvImg, 2, 1, 0x10 | 4);
paintNumber(g, level, 0, 2, 2);
}
private void open() {
pandaFlag = 4;
}
private void close() {
pandaFlag = 1;
}
private void paintNumber(Graphics g, int i, int j, int k, int l) {
int ai[] = new int[4];
ai[0] = (i / 1000) % 10;
ai[1] = (i / 100) % 10;
ai[2] = (i / 10) % 10;
ai[3] = i % 10;
for (int i1 = 4 - l; i1 < 4; i1++) {
g.setClip(j + i1 * 6, k, 6, 7);
Graphics _tmp = g;
Graphics _tmp1 = g;
g.drawImage(nosImg, (j + i1 * 6) - ai[i1] * 6, k, 0x10 | 4);
}
g.setClip(0, 0, 128, 128);
}
private boolean needRanking(int i) {
boolean flag = false;
for (int j = 0; j < 5; j++) {
if (i > rankScore[j]) {
flag = true;
j = 100;
}
}
return flag;
}
public void updateRank(String s) {
for (int i = 0; i < 5; i++) {
if (score > rankScore[i]) {
insertRank(score, s, 0, i);
i = 100;
}
}
}
private void insertRank(int i, String s, int j, int k) {
for (int l = 4; l > k; l--) {
rankName[l] = rankName[l - 1];
rankScore[l] = rankScore[l - 1];
rankLevel[l] = rankLevel[l - 1];
}
rankName[k] = s;
rankScore[k] = i;
rankLevel[k] = j;
}
void saveRank() {
rank.save(rankScore, rankName, rankLevel, 0);
rank.saveData();
}
private void getRank() {
rankName = rank.getName();
rankScore = rank.getScore();
rankLevel = rank.getLevel();
}
private void moveFlag() {
if (pandaFlag < 5) {
pandaFlag++;
} else {
pandaFlag = 0;
}
}
private void makeArrow() {
for (int i = 0; i < arrowNum; i++) {
arrowSet[i] = getRand(4);
}
stepOK = false;
currentArrow = 0;
}
private void processArrow(int i) {
if (currentArrow < arrowNum && player.frame < 6 && player.dir == 1 &&
i == arrowSet[currentArrow]) {
currentArrow++;
if (currentArrow == arrowNum) {
stepOK = true;
score += 10;
if (score % 100 == 0) {
gamestate = 4;
frame = 20;
}
}
}
}
private void paintMenuWord(Graphics g, int i, int j, int k) {
g.setClip(i, j, 51, 6);
Graphics _tmp = g;
Graphics _tmp1 = g;
g.drawImage(menuwordImg, i - k * 51, j, 0x10 | 4);
g.setClip(0, 0, 128, 128);
}
private void paintArrow(Graphics g, int i, int j, int k, int l) {
g.setClip(i, j, 8, 8);
Graphics _tmp = g;
Graphics _tmp1 = g;
g.drawImage(arrowImg, i - k * 8, j - l * 8, 0x10 | 4);
}
private void paintMainMenu(Graphics g) {
for (int i = 0; i < 128; i += 30) {
for (int j = 0; j < 128; j += 30) {
Graphics _tmp = g;
Graphics _tmp1 = g;
g.drawImage(pattern02Img, i, j, 0x10 | 4);
}
}
paintSelectBox(g, 25, 31 + selected * 14);
paintPlayer(g, 10, 25 + selected * 14, 0);
if (con) {
paintMenuWord(g, 46, 34, 0);
}
paintMenuWord(g, 45, 48, 1);
if (ns.ok) {
paintMenuWord(g, 46, 62, 2);
} else {
paintMenuWord(g, 46, 62, 3);
}
paintMenuWord(g, 41, 76, 4);
paintMenuWord(g, 43, 89, 5);
paintMenuWord(g, 60, 103, 6);
paintBigTitle01(g, 15, 3, 0);
}
private void paintSelectBox(Graphics g, int i, int j) {
g.setColor(0, 0, 0);
g.fillRect(i, j, 78, 11);
g.setColor(255, 0, 0);
g.drawRect(i, j, 78, 11);
}
private void paintMenu(Graphics g) {
g.setClip(0, 0, 128, 128);
g.setColor(203, 255, 182);
g.fillRect(0, 118, 35, 10);
g.fillRect(96, 118, 32, 10);
g.setColor(152, 89, 0);
g.drawRect(35, 114, 61, 14);
g.setColor(254, 255, 182);
g.drawRect(36, 115, 59, 13);
g.setColor(175, 159, 254);
g.drawRect(37, 116, 57, 12);
g.setColor(0, 0, 0);
g.fillRect(38, 117, 55, 10);
}
private void paintPanda(Graphics g, int i, int j, int k) {
g.setClip(i, j, 122, 31);
Graphics _tmp = g;
Graphics _tmp1 = g;
g.drawImage(pandaImg, i, j - 31 * k, 0x10 | 4);
}
private void paintPlayer(Graphics g, int i, int j, int k) {
g.setClip(i, j, 41, 35);
Graphics _tmp = g;
Graphics _tmp1 = g;
g.drawImage(chImg, i - 41 * k, j, 0x10 | 4);
}
private void paintBG(Graphics g) {
Graphics _tmp = g;
Graphics _tmp1 = g;
g.drawImage(bgImg, 0, 10, 0x10 | 4);
for (int i = 0; i < 63; i += 30) {
for (int j = 0; j < 128; j += 30) {
Graphics _tmp2 = g;
Graphics _tmp3 = g;
g.drawImage(bgpatternImg, 0 + j, 64 + i, 0x10 | 4);
}
}
}
private boolean isTouch(int i, int j, int k, int l, int i1, int j1, int k1,
int l1) {
boolean flag = false;
if (i < i1 + k1 && i + k > i1 && j < j1 + l1 && j + l > j1) {
flag = true;
}
return flag;
}
private void paintButton(Graphics g, int i, int j, int k) {
g.setClip(i, j, 28, 8);
Graphics _tmp = g;
Graphics _tmp1 = g;
g.drawImage(buttonImg, i - k * 28, j, 0x10 | 4);
g.setClip(0, 0, 128, 128);
}
private void paintArrow(Graphics g) {
for (int i = 0; i < arrowNum; i++) {
if (i < currentArrow) {
paintArrow(g, 38 + i * 9, 118, arrowSet[i], 1);
} else {
paintArrow(g, 38 + i * 9, 118, arrowSet[i], 0);
}
}
}
private int getRand(int i) {
return Math.abs(rnd.nextInt() % i);
}
public void paint(Graphics g) {
g.setColor(255, 255, 255);
g.fillRect(0, 0, 128, 128);
switch (gamestate) {
case -10:
Graphics _tmp = g;
Graphics _tmp1 = g;
g.drawImage(mbounce, 1, 20, 0x10 | 4);
g.setColor(0, 0, 0);
Graphics _tmp2 = g;
Graphics _tmp3 = g;
g.drawString("loading.....", 30, 50, 0x10 | 4);
gamestate = -9;
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -