📄 battlefield.java
字号:
}
}
private void drawItemAnimation(Graphics g) {
if(items != null)
for (int i = 0; i < items.size(); i++) {
Resource tmp = (Resource) items.elementAt(i);
if (tmp != null) {
tmp.paint(g);
}
}
}
/** Required paint implementation */
protected void paint(Graphics g) {
switch (gameStatus) {
case GAME_INIT:
g.drawImage(comImage, 0, 0, 20);
break;
case GAME_VIEW:
g.translate(SCREEN_X, SCREEN_Y);
drawBG(g);
g.setColor(255, 255, 0);
if (now != null) {
if (now.userName.equals(userName)) {
g.drawRect(screen_w - SCREEN_X - 61,
screen_h - SCREEN_Y - 18,
16, 16);
g.drawRect(screen_w - SCREEN_X - 62,
screen_h - SCREEN_Y - 19,
18, 18);
}
}
break;
case GAME_OTHERS:
g.translate(SCREEN_X, SCREEN_Y);
drawBG(g);
if (missiles != null) {
missiles.paint(g);
}
if (crash != null) {
g.drawImage(crash, missiles.m_x - 10, missiles.m_y - 7, 20);
}
break;
case GAME_MOVE:
g.translate(SCREEN_X, SCREEN_Y);
drawBG(g);
g.setColor(255, 255, 0);
if (now != null) {
if (now.userName.equals(userName)) {
g.drawRect(screen_w - SCREEN_X - 41,
screen_h - SCREEN_Y - 18,
16, 16);
g.drawRect(screen_w - SCREEN_X - 42,
screen_h - SCREEN_Y - 19,
18, 18);
}
if (gameStatus == GAME_MOVE) { //画力量槽
drawPowerBelt(g, now.speed);
}
}
if (missiles != null) {
missiles.paint(g);
}
if (crash != null) {
g.drawImage(crash, missiles.m_x - 10, missiles.m_y - 7, 20);
}
break;
case GAME_PROPERTY:
g.translate(SCREEN_X, SCREEN_Y);
drawBG(g);
g.setColor(255, 255, 0);
if (now != null) {
if (now.userName.equals(userName)) {
g.drawRect(screen_w - SCREEN_X - 21,
screen_h - SCREEN_Y - 18,
16, 16);
g.drawRect(screen_w - SCREEN_X - 22,
screen_h - SCREEN_Y - 19,
18, 18);
g.setColor(255, 255, 255);
for (int k = 0; k < 4; k++) {
g.drawRect(screen_w - SCREEN_X - 25,
-SCREEN_Y + 24 + k * 17,
18, 18);
g.drawRect(screen_w - SCREEN_X - 24,
-SCREEN_Y + 25 + k * 17,
16, 16);
}
for (int k = 0; k < now.properties.size(); k++) {
if (item_pics[k] != null) {
g.drawImage(item_pics[k],
screen_w - SCREEN_X - 23,
-SCREEN_Y + 26 + k * 17, 20);
}
}
g.setColor(255, 81, 168);
g.drawRect(screen_w - SCREEN_X - 25,
-SCREEN_Y + 24 + propIndex * 17,
18, 18);
g.drawRect(screen_w - SCREEN_X - 24,
-SCREEN_Y + 25 + propIndex * 17,
16, 16);
if (now != null) {
if (now.properties.size() > 0) {
String s = now.getProperty(propIndex, 2);
Font f = Font.getFont(Font.FACE_SYSTEM,
Font.STYLE_PLAIN,
Font.SIZE_SMALL);
g.setFont(f);
g.drawString(s,
screen_w - SCREEN_X - 28 -
f.stringWidth(s),
-SCREEN_Y + 24 + propIndex * 17,
20);
}
}
}
}
break;
case GAME_OVER:
g.translate(SCREEN_X, SCREEN_Y);
drawBG(g);
g.setColor(255, 0, 128);
Font f1 = Font.getFont(Font.FACE_SYSTEM,
Font.STYLE_BOLD,
Font.SIZE_MEDIUM);
g.setFont(f1);
g.drawString(win,
(screen_w - f1.stringWidth(win)) / 2 - SCREEN_X,
screen_h / 2 - 20 - SCREEN_Y,
g.TOP | g.LEFT);
g.setColor(0, 255, 255);
g.drawString("Press Any Key To Exit!",
(screen_w -
f1.stringWidth("Press Any Key To Exit!")) / 2 -
SCREEN_X,
screen_h / 2 - 5 - SCREEN_Y,
g.TOP | g.LEFT);
break;
}
}
public int getTankIndex(String name) {
for (int index = 0; index < runs.length; index++) {
if (runs[index].userName.equals(name)) {
return index;
}
}
return -1;
}
public Tank nextTank() {
current++;
if (runs[current % runs.length].life > 0 &&
runs[current % runs.length].tank_y < MAP_HEIGHT) {
Tank t = runs[current % runs.length];
if (t.userName.equals(userName)) {
playSound(1);
isMe = true;
count_time = 20;
}
return t;
}
else {
return nextTank();
}
}
private void moveTank(short[] route) {
for (int i = 0; i < route.length / 2; i++) {
int old_y = now.tank_y;
now.tank_x = route[i * 2];
now.tank_y = route[i * 2 + 1] - now.TANK_VSCALE / 2;
if (i * 2 < route.length - 2) {
if (route[i * 2 + 2] > route[i * 2]) {
now.direction = 1;
if (now.tank_x > screen_w * 3 / 4 - SCREEN_X &&
-SCREEN_X <= MAP_WIDTH - screen_w) {
setTranslateX( -1);
}
}
else {
if (route[i * 2 + 2] < route[i * 2]) {
now.direction = -1;
if (now.tank_x < -SCREEN_X + screen_w / 4 &&
SCREEN_X < 0) {
setTranslateX(1);
}
}
}
if (now.tank_y > screen_h * 3 / 4 - SCREEN_Y &&
-SCREEN_Y <= MAP_HEIGHT - screen_h) {
setTranslateY( -Math.min(now.tank_y -
old_y,
MAP_HEIGHT - screen_h));
}
}
judgeGetProp(now);
repaint(0, 0, screen_w, screen_h);
try {
Thread.sleep(20L);
}
catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
public void scrollScreen(int dest_x, int dest_y, int len) {
while ( -SCREEN_X != dest_x || -SCREEN_Y != dest_y) {
if (dest_x > -SCREEN_X) {
if (dest_x > -SCREEN_X + len) {
setTranslateX( -len);
}
else {
setTranslateX( -SCREEN_X - dest_x);
}
}
if (dest_x < -SCREEN_X) {
if (dest_x + len < -SCREEN_X) {
setTranslateX(len);
}
else {
setTranslateX( -SCREEN_X - dest_x);
}
}
if (dest_y > -SCREEN_Y) {
if (dest_y > -SCREEN_Y + len) {
setTranslateY( -len);
}
else {
setTranslateY( -SCREEN_Y - dest_y);
}
}
if (dest_y < -SCREEN_Y) {
if (dest_y + len < -SCREEN_Y) {
setTranslateY(len);
}
else {
setTranslateY( -SCREEN_Y - dest_y);
}
}
repaint();
serviceRepaints();
try {
Thread.sleep(10L);
}
catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
//播放音乐
protected void playSound(int frequency) {
if(playSound){
Sound d = new Sound(soundData, Sound.FORMAT_TONE);
d.play(frequency);
}
}
private void parseAndToDo(HttpClientHolder httpClientHolder,
Displayable displayable) {
try {
byte type = httpClientHolder.ReadByte();
//System.out.println("type = " + type);
switch (type) {
case 0: //登錄成功
case 3:
playSound(1);
OperateRMS userRMS = new OperateRMS("User");
userRMS.openRSAnyway();
userRMS.UIManagerOut( (userName + "$" + pwd));
userRMS.closeRSAnyway();
loadingForm.delete(0);
loadingForm.append("Welcome to the MobileTank World");
mHttpConnection.sessionID = httpClientHolder.ReadUTF();
byte count = httpClientHolder.ReadByte();
Form advForm = new Form("bulletin");
for (int i = 0; i < count; i++) {
advForm.append(httpClientHolder.ReadUTF());
}
advForm.addCommand(okCommand);
advForm.setCommandListener(new CommandListener() {
public void commandAction(Command command,
Displayable displayable) {
if (mainList == null) {
String mainCaptions[] = {
"Quick Game",
"Join Game",
"Create Game",
"Search for game",
"Shop",
"Chat Room",
"Logon out",
"Setting",
"Help",
"Exit"
};
mainList = new List("MobileTank", 3,
mainCaptions, null);
mainList.addCommand(okCommand);
mainList.addCommand(backCommand);
mainList.setCommandListener(instance);
}
display.setCurrent(
mainList);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -