📄 gamecanvas.java
字号:
import java.io.InputStream;
import javax.microedition.lcdui.*;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
class GameCanvas extends Canvas implements Runnable, CommandListener {
static CMIDlet parent;
Display display;
static Graphics g;
public static byte twoDbyteArray[][];
private static Image images[];
private static byte byteArray2[];
private static byte twoDbyteArray2[][];
private static byte donnoWhatis[][];
private static final String fileNames[] = { "file0", "file1", "file2", "file3" };
static boolean mainMenu = false;
static boolean enableSound = true;
static boolean enableTips = true;
static boolean Z = false;
static boolean C = false;
static boolean B = false;
static boolean D = false;
static boolean JJJJ = false;
static boolean S = false;
static boolean A = false;
static boolean E = false;
static int GAME_STATE;
static int no_of_run = 0;
static Base K[];
static Base L;
static Children7 M;
static Children1 N;
static Children3 O;
static Children5 P;
static Children2 Q;
static Children4 R;
static Children6 f;
static InputStream is;
static byte U[];
static byte V[];
static Image imageW;
static Image imageCompanyLogo;
static Image buffer_236x5;
static Image buffer_224x96;
static Image drawImage[] = new Image[5];
static long previousTime;
static Object c = new Object(); // object only for getresourceasstream
static int b[] = null;
static J d;
static boolean drawRect = false;
static boolean drawString = false;
static boolean j;
static int enumerateRecords;
static int fillRect;
static int getClass;
static int getFont;
static int getGraphics;
static Children2 s;
static int a;
static long someTimeinMs[] = { 0xf4240L, 0xf4240L, 0xf4240L, 0xf4240L, 0xf4240L, 0xf4240L, 0xf4240L };
static long e;
static long anotherTimeinMS;
static RecordStore recordStore;
static byte record[] = new byte[19];
static int length;
static long nextRecordId;
static long openRecordStore;
static String h;
static int loadingProgress = 0;
static int realize;
static int setClip;
static int setColor;
static int setFont;
static String storyString;
static short skip;
private static final String menuStrings[] = { "Pause", "Continue", "Sound is OFF", "Sound is ON", "Resume", "New Game", "Main Menu", "About", "Controls", "Exit", "Restart", "Tips are ON", "Tips are OFF" };
boolean stop;
long loadingFinishTime;
Command currentCommand;
Command commandMENU;
Command commandSELECT;
Command commandEMPTY;
private Font plain_text;
private Font bold_text;
private byte commandType;
private byte selectedId;
private byte q[][] = { { 5, 1, 3, 9, 8, 7, 11 }, { 4, 6, 0, 3, 9, 10, 11, 8 } };
private byte r[] = { 7, 8 };
static byte t[] = { 35, 32, 26, 28, 37, 36, 34, 30, 39, 38, 21, 25, 0, 0, 19, 22, 24, 31, 20, 17, 18, 16, 13, 12, 23, 29, 33, 27, 14, 15 };
int timeInterval;
static final void playSound(int soundId) {
}
public static final Image getImage(int imageId) {
return images[imageId];
}
public static final void initArrays() {
images = new Image[44];
twoDbyteArray = new byte[1][];
twoDbyteArray2 = new byte[4][];
donnoWhatis = new byte[4][4];
donnoWhatis[0][0] = 1;
donnoWhatis[0][1] = 1;
twoDbyteArray2[0] = new byte[2];
donnoWhatis[1][0] = 11;
donnoWhatis[1][1] = 0;
twoDbyteArray2[1] = new byte[11];
donnoWhatis[2][0] = 28;
donnoWhatis[2][1] = 0;
twoDbyteArray2[2] = new byte[28];
donnoWhatis[3][0] = 4;
donnoWhatis[3][1] = 0;
twoDbyteArray2[3] = new byte[4];
}
public static final void init2(int i) {
int j = i & 0xff; // 1111 1111
int k = (i & 0x3c00) >> 10; // 0011 1100 0000 0000
if ((twoDbyteArray2[k][j] & 1) == 0) {
twoDbyteArray2[k][j] |= 1;
if ((twoDbyteArray2[k][j] & 2) == 0)
donnoWhatis[k][3]++;
else
donnoWhatis[k][2]--;
}
}
public static final void init4(int i) {
int j = i & 0xff; //1111 1111
int k = (i & 0x3c00) >> 10; // 0011 1100 0000 0000
if ((twoDbyteArray2[k][j] & 1) > 0) {
twoDbyteArray2[k][j] &= 0xfe; // 1111 1110
if ((twoDbyteArray2[k][j] & 2) > 0)
donnoWhatis[k][2]++;
else
donnoWhatis[k][3]--;
}
}
public static final void closeRecordStore() {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < twoDbyteArray2[i].length; j++)
if ((twoDbyteArray2[i][j] & 1) > 0) {
twoDbyteArray2[i][j] &= 0xfe;
donnoWhatis[i][2]++;
}
donnoWhatis[i][3] = 0;
}
}
public final void readImages() {
int i3 = 0;
int j3 = 0;
for (int i = 0; i < 4; i++)
if (donnoWhatis[i][2] > 0) {
for (int j1 = 0; j1 < twoDbyteArray2[i].length; j1++) {
if ((twoDbyteArray2[i][j1] & 3) == 2) {
if (j1 < donnoWhatis[i][0])
images[i3] = null;
else
twoDbyteArray[j3] = null;
twoDbyteArray2[i][j1] &= 0xfd;
}
if (j1 < donnoWhatis[i][0])
i3++;
else
j3++;
}
donnoWhatis[i][2] = 0;
} else {
i3 += donnoWhatis[i][0];
j3 += donnoWhatis[i][1];
}
i3 = 0;
j3 = 0;
for (int i = 0; i < 4; i++)
if (donnoWhatis[i][3] > 0) {
try {
InputStream inputstream = parent.getClass().getResourceAsStream("/" + fileNames[i]);
int i2 = twoDbyteArray2[i].length * 4;
int l1 = i2;
int j2 = 0;
byte abyte0[] = new byte[i2];
inputstream.read(abyte0);
for (int j = 0; j < twoDbyteArray2[i].length; j++) {
int i1 = ((abyte0[j2++] & 0xff) << 8) + (abyte0[j2++] & 0xff);
short word0 = (short) (((abyte0[j2++] & 0xff) << 8) + (abyte0[j2++] & 0xff));
if ((twoDbyteArray2[i][j] & 3) == 1) {
if (l1 > i2) {
inputstream.skip(l1 - i2);
i2 = l1;
}
if (j < donnoWhatis[i][0]) {
byteArray2 = new byte[i1];
inputstream.read(byteArray2, 0, i1);
images[i3] = Image.createImage(byteArray2, 0, i1);
byteArray2 = null;
} else if (word0 == 0) {
twoDbyteArray[j3] = new byte[i1];
inputstream.read(twoDbyteArray[j3], 0, i1);
}
twoDbyteArray2[i][j] |= 6;
i2 += i1;
}
l1 += i1;
if (j < donnoWhatis[i][0])
i3++;
else
j3++;
}
inputstream.close();
} catch (Exception exception) {
}
donnoWhatis[i][3] = 0;
} else {
i3 += donnoWhatis[i][0];
j3 += donnoWhatis[i][1];
}
}
public GameCanvas() {
timeInterval = 125;
//w = 0L;
GAME_STATE = -1;
commandMENU = new Command("MENU", 4, 1);
commandEMPTY = new Command("", 4, 1);
commandSELECT = new Command("Select", 4, 1);
setCommandListener(this);
addCommand(new Command("", 4, 1));
addCommand(commandEMPTY);
currentCommand = commandEMPTY;
}
public final void init() {
plain_text = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL);
bold_text = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL);
initArrays();
init2(0);
readImages();
imageCompanyLogo = getImage(0);
init4(0);
GAME_STATE = 0;
previousTime = System.currentTimeMillis();
}
public final void run() {
if (GAME_STATE != 1)
for (; System.currentTimeMillis() - previousTime < (long) timeInterval; Thread.yield());
previousTime = System.currentTimeMillis();
repaint();
if (GAME_STATE == 14) {
parent.destroyApp(false);
parent.notifyDestroyed();
} else {
display.callSerially(this);
}
no_of_run++;
}
final void somethingBeforeQuit() {
imageW = null;
closeRecordStore();
readImages();
}
public final void commandAction(Command command, Displayable displayable) {
keyPressed(-7);
}
public static final void drawBackGround(int color) {
g.setColor(color);
g.fillRect(0, 0, 128, 128);
}
protected final void keyPressed(int keyCode) {
if (mainMenu)
switch (keyCode) {
case -7:
case -6:
case -5:
boolean flag = false;
switch (q[commandType][selectedId]) {
case 0: // '\0'
length = 0;
GAME_STATE = 13;
break;
case 1: // '\001'
fillRect = getClass;
if (fillRect != 0)
GAME_STATE = 5;
else
showStory();
break;
case 2: // '\002'
enableSound = true;
q[0][2] = 3;
q[1][3] = 3;
flag = true;
break;
case 3: // '\003'
enableSound = false;
q[0][2] = 2;
q[1][3] = 2;
flag = true;
break;
case 5: // '\005'
showStory();
break;
case 6: // '\006'
d = null;
showMenuCommand();
break;
case 7: // '\007'
getFont = 0;
skip = 4;
GAME_STATE = 9;
break;
case 8: // '\b'
if (GAME_STATE == 4)
drawString = true;
else
drawString = false;
getGraphics = 0;
skip = 4;
GAME_STATE = 10;
break;
case 9: // '\t'
writeRMS(false);
GAME_STATE = 14;
break;
case 10: // '\n'
GAME_STATE = 11;
break;
case 11: // '\013'
enableTips = false;
q[0][6] = 12;
q[1][6] = 12;
flag = true;
break;
case 12: // '\f'
enableTips = true;
q[0][6] = 11;
q[1][6] = 11;
flag = true;
break;
}
if (!flag) {
mainMenu = false;
if (GAME_STATE == 4) {
removeCommand(currentCommand);
addCommand(commandMENU);
currentCommand = commandMENU;
} else if (GAME_STATE != 3) {
removeCommand(currentCommand);
addCommand(commandEMPTY);
currentCommand = commandEMPTY;
}
}
break;
case -1:
case 49: // '1'
case 50: // '2'
case 51: // '3'
selectedId--;
if (selectedId < 0)
selectedId = (byte) (r[commandType] - 1);
break;
case -2:
case 55: // '7'
case 56: // '8'
case 57: // '9'
selectedId++;
if (selectedId >= r[commandType])
selectedId = 0;
break;
}
else
processKeyCode(keyCode, true);
}
protected final void keyReleased(int keyCode) {
Z = C = B = D = false;
S = JJJJ = false;
E = false;
if (!mainMenu)
processKeyCode(keyCode, false);
}
protected final void processKeyCode(int keyCode, boolean keyPress) {
if (keyPress)
switch (GAME_STATE) {
case 6: // '\006'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -