📄 galaxywarcanvas.java
字号:
g.setColor(0x00FFFF00);
switch(menuID) {
case 0:
info = "Sound";
break;
case 1:
if (isSoundOn)
info = "ON";
else
info = "OFF";
break;
case 2:
info = "Vibration";
break;
case 3:
if (isVibration)
info = "ON";
else
info = "OFF";
break;
case 4:
info = "Auto Upload";
break;
case 5:
if (isAutoUpload)
info = "ON";
else
info = "OFF";
break;
}
if (menuID >= OPTION_NUM) continue;
infoWidth = getStringWidth(info);
startX = (width - infoWidth) >> 1;
startY = panel_up.getHeight() + SPACING2
+ (font.getHeight() + SPACING) * i;
g.drawString(info,startX,startY,g.LEFT | g.TOP);
}
drawHintArrow(g,OPTION_NUM);
}
private void drawHelp(Graphics g) {
int menuID,infoWidth;
String info = "";
int startX,startY;
//panel的尺寸必须于屏幕实际尺寸相符
g.drawImage(panel_up, 0, 0, g.TOP | g.LEFT);
g.setColor(0x00FFFF00);
for (int i=0;i<showedNum;i++) {
menuID = menu[i];
switch(menuID) {
case 0:
info = "Help :";
break;
case 1:
info = "5 = Fire";
break;
case 2:
info = "2 = Move Up";
break;
case 3:
info = "8 = Move Down";
break;
case 4:
info = "4 = Move Left";
break;
case 5:
info = "6 = Move Right";
break;
}
if (menuID > HELP_NUM) continue;
infoWidth = getStringWidth(info);
startX = (width - infoWidth) >> 1;
startY = panel_up.getHeight() + SPACING2
+ (font.getHeight() + SPACING) * i;
g.drawString(info,startX,startY,g.LEFT | g.TOP);
}
drawHintArrow(g,HELP_NUM);
}
private void drawGameOver(Graphics g) {
int infoWidth,startX,startY;
String info;
g.drawImage(panel_up, 0, 0, g.TOP | g.LEFT);
g.setColor(0x00FFFF00);
info = "Game Over";
infoWidth = getStringWidth(info);
startX = (width - infoWidth) >> 1;
startY = panel_up.getHeight()
+ ((height - panel_up.getHeight()
- (font.getHeight() << 1) - SPACING) >> 1);
g.drawString(info,startX,startY,g.LEFT | g.TOP);
if (frameCounter >= MIDDLE) return;
g.setColor(0x00ff0000);
info = "Press Any Key";
infoWidth = getStringWidth(info);
startX = (width - infoWidth) >> 1;
startY = panel_up.getHeight()
+ ((height - panel_up.getHeight()
- (font.getHeight() << 1) - SPACING) >> 1)
+ font.getHeight() + SPACING;
g.drawString(info,startX,startY,g.LEFT | g.TOP);
}
private void drawAbout(Graphics g) {
int menuID,infoWidth;
String info = "";
int startX,startY;
//panel的尺寸必须于屏幕实际尺寸相符
g.drawImage(panel_up, 0, 0, g.TOP | g.LEFT);
g.setColor(0x00FFFF00);
for (int i=0;i<showedNum;i++) {
menuID = menu[i];
switch(menuID) {
case 0:
info = "About :";
break;
case 1:
info = "Powered by";
break;
case 2:
info = "GameisLive";
break;
case 3:
info = "Version : 1.0";
break;
case 4:
info = "Producer : Pacess";
break;
case 5:
info = "Programming : Prince";
break;
case 6:
info = "Art Design : Man";
break;
case 7:
info = "Music : Sam";
break;
case 8:
info = "www.iilcorp.com";
break;
}
if (menuID > ABOUT_NUM) continue;
infoWidth = getStringWidth(info);
startX = (width - infoWidth) >> 1;
startY = panel_up.getHeight() + SPACING2
+ (font.getHeight() + SPACING) * i;
g.drawString(info,startX,startY,g.LEFT | g.TOP);
}
drawHintArrow(g,ABOUT_NUM);
}
private void drawReport(Graphics g) {
int infoWidth;
int startX,startY;
String info;
Tank p = player[0];
g.drawImage(panel_up, 0, 0, g.TOP | g.LEFT);
g.setColor(0x00FFFF00);
info = "Level " + (round + 1);
infoWidth = getStringWidth(info);
startX = (width - infoWidth) >> 1;
startY = panel_up.getHeight() + SPACING2;
//+ (font.getHeight() + SPACING) * i;
g.drawString(info,startX,startY,g.LEFT | g.TOP);
if (gameState == 2)
info = "Well Done!";
else {
if (gameState == 1)
info = "You have winned!";
else
info = "Failed!";
}
infoWidth = getStringWidth(info);
startX = (width - infoWidth) >> 1;
startY = panel_up.getHeight() + SPACING2
+ font.getHeight() + SPACING;
g.drawString(info,startX,startY,g.LEFT | g.TOP);
info = "Score : " + p.score;
infoWidth = getStringWidth(info);
startX = (width - infoWidth) >> 1;
startY = panel_up.getHeight() + SPACING2
+ (font.getHeight() + SPACING) * 2;
g.drawString(info,startX,startY,g.LEFT | g.TOP);
}
private void drawHintArrow(Graphics g,int itemNum) {
int startX,startY;
int startID,endID;
int start;
boolean isStart,isEnd;
if (mode == MODE_MENU)
start = startMenu;
else
start = 0;
startID = menu[0];
endID = menu[showedNum -1];
if (startID == start && endID == itemNum - 1) return;
if (startID > start)
isStart = false;
else
isStart = true;
if (endID < itemNum - 1)
isEnd = false;
else
isEnd = true;
startX = (width - hint.getWidth()) >> 1;
startY = height - 2 - hint.getHeight();
if (!isStart && isEnd) {
g.setClip(startX,startY,hint.getWidth(),hint.getHeight() >> 1);
}
else if (isStart && !isEnd) {
g.setClip(startX,startY + (hint.getHeight() >> 1)
,hint.getWidth(),hint.getHeight() >> 1);
}
g.drawImage(hint,startX,startY,g.LEFT | g.TOP);
g.setClip(0,0,width,height);
}
private void updateMenu(int jumpNum) {
if (currentMenu > menu[showedNum-1])
for (int i = 0;i<showedNum;i++) {
menu[i] += jumpNum;
}
if (currentMenu < menu[0]) {
for (int i = 0;i<showedNum;i++) {
menu[i] -=jumpNum;
}
}
}
private void processPause() {
switch(currentMenu) {
case 0:
restartGame();
break;
case 1:
showOption();
break;
case 2:
showHelp();
break;
case 3:
showMainMenu();
break;
}
}
private void processMenu() {
stopSound();
switch(currentMenu) {
case 0:
continueGame();
break;
case 1:
newGame();
break;
case 2:
showHighScore();
break;
case 3:
//showScoreUpload();
showInternetRank();
break;
case 4:
showOption();
break;
case 5:
showHelp();
break;
case 6:
showAbout();
break;
case 7:
exitGame();
break;
}
}
private void processOption() {
switch(currentMenu) {
case 1:
isSoundOn = !isSoundOn;
if (isSoundOn)
playSound("/hit.mid", "audio/midi", 1);
updateSetting();
break;
case 3:
isVibration = !isVibration;
vibrate();
updateSetting();
break;
case 5:
isAutoUpload = !isAutoUpload;
updateSetting();
//if (isAutoUpload) {
// isFromOption = true;
//setAutoUpload();
// }
break;
}
}
private void initMap() {
InputStream is = null;
DataInputStream dis = null;
String fileName = "/data/m" + round + ".dat";
is = getClass().getResourceAsStream(fileName);
dis = new DataInputStream(is);
byte c;//get the char from map.dat
int x = 0;
int y = 0;
int id = 0;
try {
while(true) {
c = dis.readByte();
if (id == 0) {
mapWidth = c;
id ++;
continue;
}
if (id == 1) {
mapHeight = c;
map = new byte[mapHeight][mapWidth];
mapPWidth = mapWidth * IMAGESIZE;
mapPHeight = mapHeight * IMAGESIZE;
id ++;
continue;
}
map[y][x] = c;
if (x == mapWidth-1) {
if (y==mapHeight-1) break;
x = -1;
y ++;//new line
}
x ++;
}
dis.close();
//is.close();
}catch(Exception ex){
System.out.println("init map: " + ex);
}
}
private void initRound(){
InputStream is = null;
DataInputStream dis = null;
String fileName = "/data/r" + round + ".dat";
is = getClass().getResourceAsStream(fileName);
dis = new DataInputStream(is);
byte c;//get the char from roundX.dat
int x = 0;
int y = 0;
int id = 0;
int totalProp = 9;//change when item was changed.
try {
while(true) {
c = dis.readByte();
if (id == 0) {
maxPlayer = c;
player = new Tank[maxPlayer];
for (int i = 0; i < maxPlayer; i++) {
player[i] = new Tank();
}
id ++;
continue;
}
switch(x) {
case 0:
player[y].x = c * IMAGESIZE;
break;
case 1:
player[y].y = c * IMAGESIZE;
break;
case 2:
player[y].rivalry = c;
break;
case 3:
player[y].type = c;
break;
case 4:
player[y].img = c;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -