📄 menuscreen.java~2~
字号:
package com.soccer;
import com.nokia.mid.ui.FullCanvas;
import java.io.PrintStream;
import javax.microedition.lcdui.*;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
public class MenuScreen extends FullCanvas implements Runnable {
public MenuScreen(GameMidlet gamemidlet) {
selected = 0;
state = 0;
displayWarning = false;
src = gamemidlet;
try {
ground = Image.createImage("/ground.png");
menu = new Image[3];
for (int i = 0; i < 3; i++) {
menu[i] = Image.createImage("/menu" + Integer.toString(i + 1) + ".png");
}
arrow = Image.createImage("/arrow.png");
logo = Image.createImage("/logo.png");
pressok = Image.createImage("/pressok.png");
help = Image.createImage("/help.png");
oppTeam = Image.createImage("/oponents.png");
ourTeam = Image.createImage("/our.png");
selectDiff = Image.createImage("/different.png");
form = Image.createImage("/form.png");
formWidth = form.getWidth() / 16;
} catch (Exception exception) {
System.out.println(exception);
}
readDataFromDB();
t = new Thread(this);
t.start();
}
public void readDataFromDB() {
try {
RecordStore recordstore = RecordStore.openRecordStore("SoccerProps", true);
if (recordstore.getNumRecords() > 0) {
RecordEnumeration recordenumeration = recordstore.enumerateRecords(null, null, false);
byte abyte0[] = recordenumeration.nextRecord();
command = abyte0[0];
commandColor = abyte0[1];
recordenumeration = null;
}
recordstore.closeRecordStore();
recordstore = null;
} catch (Exception exception) {
System.out.println(exception);
}
}
public void writeDataToDB() {
try {
RecordStore.deleteRecordStore("SoccerProps");
} catch (Exception exception) {
System.out.println(exception);
}
try {
RecordStore recordstore = RecordStore.openRecordStore("SoccerProps", true);
byte abyte0[] = {
(byte) command, (byte) commandColor
};
recordstore.addRecord(abyte0, 0, 2);
recordstore.closeRecordStore();
recordstore = null;
} catch (Exception exception1) {
System.out.println(exception1);
}
}
public void paint(Graphics g) {
if (state == 0) {
g.drawImage(logo, 0, 0, 0);
} else {
g.drawImage(ground, 0, 0, 0);
switch (state) {
case 1: // '\001'
g.setColor(0);
g.fillRect(42, 68 + 14 * selected, 91, 14);
g.drawImage(menu[state - 1], 50, 70, 0);
break;
case 2: // '\002'
g.setColor(0);
g.fillRect(42, 68 + 14 * selected, 91, 14);
g.drawImage(arrow, 44, 70 + 14 * difficulty, 0);
g.drawImage(menu[state - 1], 50, 70, 0);
g.drawImage(pressok, (getWidth() - pressok.getWidth()) / 2,
getHeight() - pressok.getHeight() - 5, 0);
break;
case 3: // '\003'
g.setClip( (getWidth() - formWidth) / 2, 85, formWidth,
form.getHeight());
g.drawImage(form,
(getWidth() - formWidth) / 2 - formWidth * commandColor,
85, 0);
g.setClip(0, 0, getWidth(), getHeight());
g.setColor(0);
g.fillRect(42, 127, 91, 14);
g.setColor(0x80ff80);
g.setFont(Font.getFont(0, 0, 8));
for (int i = -1; i < 3; i++) {
if (command + i >= 0 && command + i < commands.length) {
g.drawString(commands[command + i], 50, 115 + 14 * (i + 1), 16);
}
}
g.drawImage(menu[state - 1],
(getWidth() - menu[state - 1].getWidth()) / 2, 70, 0);
g.drawImage(pressok, (getWidth() - pressok.getWidth()) / 2,
getHeight() - pressok.getHeight() - 5, 0);
g.drawImage(ourTeam, (getWidth() - ourTeam.getWidth()) / 2,
getHeight() - pressok.getHeight() - 15, 0);
break;
case 5: // '\005'
g.setClip( (getWidth() - formWidth) / 2, 85, formWidth,
form.getHeight());
g.drawImage(form,
(getWidth() - formWidth) / 2 - formWidth * compCommandColor,
85, 0);
g.setClip(0, 0, getWidth(), getHeight());
g.setColor(0);
g.fillRect(42, 127, 91, 14);
g.setColor(0x80ff80);
g.setFont(Font.getFont(0, 0, 8));
for (int j = -1; j < 3; j++) {
if (compCommand + j >= 0 && compCommand + j < commands.length) {
g.drawString(commands[compCommand + j], 50, 115 + 14 * (j + 1),
16);
}
}
g.drawImage(menu[state - 3],
(getWidth() - menu[state - 3].getWidth()) / 2, 70, 0);
g.drawImage(pressok, (getWidth() - pressok.getWidth()) / 2,
getHeight() - pressok.getHeight() - 5, 0);
g.drawImage(oppTeam, (getWidth() - oppTeam.getWidth()) / 2,
getHeight() - pressok.getHeight() - 15, 0);
if (displayWarning) {
g.drawImage(GameScreen.mground,
(getWidth() - GameScreen.mground.getWidth()) / 2,
(getHeight() - GameScreen.mground.getHeight()) / 2, 0);
g.drawImage(selectDiff, (getWidth() - selectDiff.getWidth()) / 2,
(getHeight() - selectDiff.getHeight()) / 2, 0);
}
break;
case 4: // '\004'
g.drawImage(help, 0, 0, 0);
break;
}
if (state != 4) {
g.drawImage(pressok, (getWidth() - pressok.getWidth()) / 2,
getHeight() - pressok.getHeight() - 5, 0);
}
}
}
public void keyReleased(int i) {
int j = getGameAction(i);
if (state == 5 && j == 8) {
displayWarning = false;
repaint();
}
}
public void keyPressed(int i) {
int j = getGameAction(i);
if (i == -6) {
GameScreen.softKey1Pressed();
} else
if (i == -7) {
GameScreen.softKey2Pressed();
}
if (state == 1) {
switch (j) {
default:
break;
case 1: // '\001'
if (selected > 0) {
selected--;
}
SPlayer.play(0);
break;
case 6: // '\006'
if (selected < 5) {
selected++;
}
SPlayer.play(0);
break;
case 8: // '\b'
SPlayer.play(0);
if (selected == 0) {
GameMidlet.gameScreen.startGame(0);
GameMidlet.m_display.setCurrent(GameMidlet.gameScreen);
break;
}
if (selected == 1) {
GameMidlet.gameScreen.startGame(1);
GameMidlet.m_display.setCurrent(GameMidlet.gameScreen);
break;
}
if (selected == 2) {
state = 3;
selected = command;
break;
}
if (selected == 3) {
state = 2;
selected = 0;
break;
}
if (selected == 4) {
state = 4;
break;
}
if (selected == 5) {
src.destroyGame();
}
break;
}
repaint();
serviceRepaints();
} else
if (state == 2) {
switch (j) {
default:
break;
case 1: // '\001'
SPlayer.play(0);
if (selected > 0) {
selected--;
}
break;
case 6: // '\006'
SPlayer.play(0);
if (selected < 3) {
selected++;
}
break;
case 8: // '\b'
SPlayer.play(0);
if (selected == 3) {
state = 1;
} else {
difficulty = selected;
}
break;
}
repaint();
serviceRepaints();
} else
if (state == 3) {
switch (j) {
case 3: // '\003'
case 4: // '\004'
case 7: // '\007'
default:
break;
case 1: // '\001'
SPlayer.play(0);
if (command > 0) {
command--;
commandColor--;
}
break;
case 6: // '\006'
SPlayer.play(0);
if (command < commands.length - 1) {
command++;
commandColor++;
}
break;
case 2: // '\002'
SPlayer.play(0);
if (commandColor > 0) {
commandColor--;
command--;
}
break;
case 5: // '\005'
SPlayer.play(0);
if (commandColor < 15) {
commandColor++;
command++;
}
break;
case 8: // '\b'
SPlayer.play(0);
writeDataToDB();
state = 5;
selected = 2;
break;
}
repaint();
serviceRepaints();
} else
if (state == 5) {
switch (j) {
case 3: // '\003'
case 4: // '\004'
case 7: // '\007'
default:
break;
case 1: // '\001'
SPlayer.play(0);
if (compCommand > 0) {
compCommand--;
compCommandColor--;
}
break;
case 6: // '\006'
SPlayer.play(0);
if (compCommand < commands.length - 1) {
compCommand++;
compCommandColor++;
}
break;
case 2: // '\002'
SPlayer.play(0);
if (compCommandColor > 0) {
compCommandColor--;
compCommand--;
}
break;
case 5: // '\005'
SPlayer.play(0);
if (compCommandColor < 15) {
compCommandColor++;
compCommand++;
}
break;
case 8: // '\b'
SPlayer.play(0);
if (command == compCommand || commandColor == compCommandColor) {
displayWarning = true;
} else {
state = 1;
selected = 2;
}
break;
}
repaint();
serviceRepaints();
} else
if (state == 4 && j == 8) {
SPlayer.play(0);
state = 1;
repaint();
serviceRepaints();
}
}
public void run() {
try {
MenuScreen _tmp = this;
Thread.sleep(6000L);
} catch (Exception exception) {}
logo = null;
state = 1;
repaint();
serviceRepaints();
}
static Image ground;
static Image arrow;
static Image logo;
static Image menu[];
static Image form;
static Image pressok;
static Image help;
static Image oppTeam;
static Image ourTeam;
static Image selectDiff;
private static final String db = "SoccerProps";
public static final int menuItemHeight = 14;
public static final int menuItemWidth = 91;
public static final int colors = 16;
private final int menuX = 50;
private final int menuY = 70;
public static final String commands[] = {
"Hyax", "Buyvan", "Kobentree", "Shallsee", "Tartmoon", "Fadenorth",
"Winter", "Joubendus", "Taxio", "Meelawn",
"Paradis", "Nuntess", "Mgritte", "Ramia", "Youthright", "Benefic"
};
public static int difficulty = 0;
public static int command = 0;
public static int commandColor = 0;
public static int compCommand = 1;
public static int compCommandColor = 1;
static int formWidth = 0;
private int selected;
private int state;
boolean displayWarning;
Thread t;
GameMidlet src;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -