📄 maincanvas.java
字号:
setStatus(MISSION_RUNNING);
startTime = System.currentTimeMillis();
// 进行必要的清理
otta.reset();
otta.setLocation(initRow, initColumn);
otta.setPath(initRow, initColumn);
selectedToolIndex = -1;
byte value;
for (int i = 0; i < 12; i++) {
for (int j = 0; j < 10; j++) {
if(missionCount == 7 && missionNum == 0)
value = info.mission[7][i * 10 + j];
else
value = info.mission[missionNum][i * 10 + j];
if (value < STUFF_BOMB) {
base[i][j] = value;
stuffs[i][j] = null;
} else {
stuffs[i][j] = new Magic(value, i, j);
base[i][j] = 0;
}
}
}
for (int k = 0; k < 9; k++)
tools[k] = (k < initTools.length) ? initTools[k] : 0;
System.gc();
}
public static void setStatus(int state) {
if (state == missionStatus)
return;
missionStatus = state;
if (missionStatus == MISSION_COMPLETED) {
playSound(playerWin, 1);
int i = missionNum / 8;
int m = missionNum % 8;
record[i] |= (0x01 << m);
showMenu();
} else if (missionStatus == MISSION_FAIL) {
showMenu();
}
}
public static void playSound(Player player, int count) {
if (Start.isSoundOpen) {
try {
nowPlayer.deallocate();
nowPlayer = player;
nowPlayer.setLoopCount(count);
nowPlayer.start();
} catch (MediaException e) {
e.printStackTrace();
}
}
}
public static boolean canCross(int row, int column) {
return stuffs[row][column] == null;
}
public static void save() {
try {
RecordStore recordStore = RecordStore.openRecordStore("Otta", false);
recordStore.setRecord(1, record, 0, record.length);
recordStore.closeRecordStore();
} catch (Exception e) {}
}
public static void removeSelectedTool() {
tools[selectedToolIndex] = 0;
selectedToolIndex = -1;
}
public static boolean addTool(int type) {
for (int i = 0; i < tools.length; i++) {
if (tools[i] <= 0) {
tools[i] = type;
return true;
}
}
return false;
}
public static Magic getStuff(int row, int column) {
if (row < 0 || row >= 12 || column < 0 || column >= 10)
return null;
return stuffs[row][column];
}
private void initial() {
try {
// 初始化图片资源
image_logo = Image.createImage("/Image/logo.png");
image_otta = Image.createImage("/Image/otta.png");
Image words = Image.createImage("/Image/words.png");
Image others = Image.createImage("/Image/images.png");
image_stone = Image.createImage("/Image/stone.png");
image_explode = Image.createImage("/Image/explode.png");
Image mirror = Image.createImage("/Image/mirror.png");
image_laser = Image.createImage("/Image/laser.png");
image_toolbar = Image.createImage("/Image/toolbar.png");
image_bottom = Image.createImage("/Image/bottom.png");
background = Image.createImage("/Image/background.png");
window = Image.createImage("/Image/message.png");
word2 = Image.createImage("/Image/word2.png");
link = Image.createImage("/Image/linkback.png");
select = Image.createImage("/Image/select.png");
menub = Image.createImage("/Image/bar.png");
num = Image.createImage("/Image/number.png");
level = Image.createImage("/Image/level.png");
chen = Image.createImage("/Image/chen.png");
for (int j = 0; j < 11; j++)
number[j] = Image.createImage(num, j*6, 0, 6, 8, Sprite.TRANS_NONE);
image_broking = Image.createImage(mirror, 0, 0, 96, 24, Sprite.TRANS_NONE);
image_mirror = Image.createImage(mirror, 96, 0, 16, 24, Sprite.TRANS_NONE);
word_start = Image.createImage(words, 0, 0, 28, 13, Sprite.TRANS_NONE);
word_continue = Image.createImage(words, 30, 0, 28, 13, Sprite.TRANS_NONE);
word_setting = Image.createImage(words, 59, 0, 28, 13, Sprite.TRANS_NONE);
word_option = Image.createImage(words, 88, 0, 28, 13, Sprite.TRANS_NONE);
word_quit = Image.createImage(words, 118, 0, 28, 13, Sprite.TRANS_NONE);
word_mission = Image.createImage(words, 148, 0, 28, 13, Sprite.TRANS_NONE);
word_success = Image.createImage(words, 178, 0, 28, 13, Sprite.TRANS_NONE);
word_failure = Image.createImage(words, 206, 0, 28, 13, Sprite.TRANS_NONE);
word_retry = Image.createImage(words, 236, 0, 28, 13, Sprite.TRANS_NONE);
word_nextMission = Image.createImage(words, 266, 0, 42, 13, Sprite.TRANS_NONE);
word_mainMenu = Image.createImage(words, 310, 0, 42, 13, Sprite.TRANS_NONE);
image_ice = Image.createImage(others, 48, 0, 48, 16, Sprite.TRANS_NONE);
image_target = Image.createImage(others, 96, 0, 32, 16, Sprite.TRANS_NONE);
image_firing = Image.createImage(others, 32, 0, 16, 16, Sprite.TRANS_NONE);
image_tools[0] = Image.createImage(others, 128, 0, 16, 16, Sprite.TRANS_NONE);
image_tools[1] = Image.createImage(others, 144, 0, 16, 16, Sprite.TRANS_NONE);
image_tools[2] = Image.createImage(others, 160, 0, 16, 16, Sprite.TRANS_NONE);
image_tools[3] = Image.createImage(others, 176, 0, 16, 16, Sprite.TRANS_MIRROR);
image_tools[4] = Image.createImage(others, 176, 0, 16, 16, Sprite.TRANS_NONE);
image_tools[5] = Image.createImage(others, 192, 0, 16, 16, Sprite.TRANS_NONE);
image_bomb = Image.createImage(others, 192, 0, 32, 16, Sprite.TRANS_NONE);
image_hand = Image.createImage(others, 224, 2, 12, 14, Sprite.TRANS_NONE);
hand = Image.createImage(others, 160, 0, 16, 16, Sprite.TRANS_NONE);
image_cup = Image.createImage(others, 236, 3, 12, 13, Sprite.TRANS_NONE);
image_floors[0] = Image.createImage(others, 0, 0, 16, 16, Sprite.TRANS_NONE);
image_floors[1] = Image.createImage(others, 16, 0, 16, 16, Sprite.TRANS_NONE);
image_tools[10] = Image.createImage(image_laser, 4, 0, 16, 16, Sprite.TRANS_NONE);
image_tools[11] = Image.createImage(image_laser, 56, 0, 16, 16, Sprite.TRANS_NONE);
image_tools[12] = Image.createImage(image_laser, 100, 4, 16, 16, Sprite.TRANS_NONE);
image_tools[13] = Image.createImage(image_tools[11], 0, 0, 16, 16, Sprite.TRANS_MIRROR);
image_tools[15] = Image.createImage(image_mirror, 0, 0, 16, 16, Sprite.TRANS_NONE);
image_tools[14] = Image.createImage(image_tools[15], 0, 0, 16, 16, Sprite.TRANS_MIRROR);
mainMenuItems[0] = word_continue;
mainMenuItems[1] = word_start;
mainMenuItems[2] = word_setting;
mainMenuItems[3] = word_option;
mainMenuItems[4] = word_quit;
} catch(Exception e){}
}
private Image resizeImage(Image src, int destW, int destH) {
int srcW = src.getWidth();
int srcH = src.getHeight();
// 目标像素数组
int[] destPixels = new int[destW * destH];
// 原像素数组
int[] srcPixels = new int[srcW * srcH];
src.getRGB(srcPixels, 0, srcW, 0, 0, srcW, srcH);
// 重新计算像素值
int ratioW = (srcW << 13) / destW;
int ratioH = (srcH << 13) / destH;
int[] tmpPixels = new int[destW * srcH];
int argb;
int a, r, g, b;
int count;
for (int y = 0; y < srcH; ++y) {
for (int destX = 0; destX < destW; ++destX) {
count = 0;
a = 0;
r = 0;
b = 0;
g = 0;
int srcX = (destX * ratioW) >> 13;
int srcX2 = ((destX + 1) * ratioW) >> 13;
do
{
argb = srcPixels[srcX + y * srcW];
a += ((argb & 0xff000000) >> 24);
r += ((argb & 0x00ff0000) >> 16);
g += ((argb & 0x0000ff00) >> 8);
b += (argb & 0x000000ff);
++count;
++srcX;
}
while (srcX <= srcX2 && srcX + y * srcW < srcPixels.length);
a /= count;
r /= count;
g /= count;
b /= count;
tmpPixels[destX + y * destW] = ((a << 24) | (r << 16)
| (g << 8) | b);
}
}
for (int x = 0; x < destW; ++x) {
for (int destY = 0; destY < destH; ++destY) {
count = 0;
a = 0;
r = 0;
b = 0;
g = 0;
int srcY = (destY * ratioH) >> 13;
int srcY2 = ((destY + 1) * ratioH) >> 13;
do {
argb = tmpPixels[x + srcY * destW];
a += ((argb & 0xff000000) >> 24);
r += ((argb & 0x00ff0000) >> 16);
g += ((argb & 0x0000ff00) >> 8);
b += (argb & 0x000000ff);
++count;
++srcY;
} while (srcY <= srcY2 && x + srcY * destW < tmpPixels.length);
a /= count;
a = (a > 255) ? 255 : a;
r /= count;
r = (r > 255) ? 255 : r;
g /= count;
g = (g > 255) ? 255 : g;
b /= count;
b = (b > 255) ? 255 : b;
destPixels[x + destY * destW] = ((a << 24) | (r << 16)
| (g << 8) | b);
}
}
return Image.createRGBImage(destPixels, destW, destH, true);
}
//载入用户自定义的声音文件
public void loadCustomSound() {
try {
FileConnection fileConn =(FileConnection)Connector.open(Start.fileURL);
InputStream is = fileConn.openInputStream();
int length = Start.fileURL.length()-3;
String s = Start.fileURL.substring(length);
if(s.equalsIgnoreCase("mid"))
player_custom = Manager.createPlayer(is, "audio/midi");
else if(s.equalsIgnoreCase("mp3"))
player_custom = Manager.createPlayer(is, "audio/mpeg");
} catch(Exception e){}
}
//建立HTTP连接
public boolean getHttpConnection(String url) throws IOException {
HttpConnection con = null;
InputStream is = null;
StringBuffer str = new StringBuffer();
try {
con = (HttpConnection)Connector.open(url);
is = con.openInputStream();
int temp;
while ((temp = is.read()) != -1) {
str.append((char)temp);
}
is.close();
con.close();
str.length();
if(str.length() == 3343)
{
missionCount = 7;
isLinking = false;
return true;
}
else
{
isLinking = false;
return false;
}
} catch(Exception e) {
isLinking = false;
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -