📄 battlefield.java
字号:
}
private void createMapList(String maps[]) {
if (moreMapList == null) {
moreMapList = new List("Maps", 3, maps, null);
}
else {
for (; moreMapList.size() > 0; moreMapList.delete(0)) {
;
}
for (int i = 0; i < maps.length; i++) {
moreMapList.append(maps[i], null);
}
}
moreMapList.addCommand(okCommand);
moreMapList.addCommand(new Command("MoreMap", 4, 1));
moreMapList.addCommand(backCommand);
moreMapList.setCommandListener(this);
//System.out.println("finish set moremap list!!!!!!!!");
}
private void createChatList(String messages[]) {
//获取当前最新20条消息
if (chatList == null) {
chatList = new List("Chat", 3);
chatList.append("Welcome to ChatRoom!", null);
chatList.addCommand(chatCommand);
chatList.addCommand(refreshCommand);
chatList.addCommand(backCommand);
chatList.setCommandListener(this);
}
else {
for (; chatList.size() > 1; chatList.delete(1)) {
;
}
}
for (int i = 0; i < messages.length; i++) {
chatList.append(messages[i], null);
}
}
/**
* 包括Tank,Missile,Item三个部分,根据需要显示
*/
/*private void createShopForm(int type) {
String name = "";
switch (type) {
case 0:
name = "Missile";
break;
case 1:
name = "buy item";
break;
case 2:
name = "sell Item";
break;
}
shopForm = new Form(name);
Image shopImages[] = new Image[3];
try {
for (int i = 0; i < 3; i++) {
shopImages[i] = Image.createImage(
"/demo/res/bullet.png");
}
}
catch (Exception e) {
e.printStackTrace();
}
String shopNames[] = new String[3];
for (int j = 0; j < 3; j++) {
shopNames[j] = name + Integer.toString(j);
}
ChoiceGroup shop = new ChoiceGroup(name, 1, shopNames, shopImages);
shopForm.append(shop);
shopForm.addCommand(okCommand);
shopForm.addCommand(backCommand);
shopForm.setCommandListener(new CommandListener() {
public void commandAction(Command command,
Displayable displayable) {
if (command == okCommand) { //进行操作
}
if (command == backCommand) {
display.setCurrent(shopForm);
}
}
});
display.setCurrent(shopForm);
}*/
private void createGameQueue(String gameQueue[]) {
onlineGames = new List("Game List", 3, gameQueue, null);
onlineGames.addCommand(joinCommand);
onlineGames.addCommand(detailCommand);
onlineGames.addCommand(new Command("MoreGame", 4, 1));
onlineGames.addCommand(backCommand);
onlineGames.setCommandListener(this);
display.setCurrent(onlineGames);
}
public boolean isClision(Missile e1) { //e1是missle
boolean flag = false;
boolean mod = false; //是否修改过地图
for (int i = 0; i < runs.length; i++) {
if (runs[i].isCollision(e1)) {
flag = true; //炸到某个坦克了
if (!mod) { //还没有修改过地图
map.exacuteCrash(e1.m_x,
Math.min(MAP_HEIGHT,
map.getDownNotNull(e1.m_x,
e1.m_y)), e1.attackRadius);
for (int j = 0; j < runs.length; j++) { // 修改各个坦克的坐标
runs[j].tank_y = Math.min(MAP_HEIGHT,
map.getDownNotNull(runs[j].tank_x,
runs[j].tank_y +
runs[j].TANK_VSCALE / 2) - runs[j].TANK_VSCALE / 2);
//System.out.println("runs[" + j + "].tank_x = " + runs[j].tank_x);
//System.out.println("runs[" + j + "].tank_y = " + runs[j].tank_y);
}
mod = true;
}
break;
}
}
if (!flag) { // 如果没有撞到任何坦克
if (map.isCollision(e1)) { // 撞地
for (int j = 0; j < runs.length; j++) { // 修改各个坦克的坐标
runs[j].tank_y = Math.min(MAP_HEIGHT,
map.getDownNotNull(runs[j].tank_x,
runs[j].tank_y +
runs[j].TANK_VSCALE / 2) -
runs[j].TANK_VSCALE / 2);
//System.out.println("runs[" + j + "].tank_x = " + runs[j].tank_x);
//System.out.println("runs[" + j + "].tank_y = " + runs[j].tank_y);
}
flag = true;
}
}
return flag;
}
public void setTranslateX(int x) {
SCREEN_X = SCREEN_X + x;
if ( -SCREEN_X <= 0) {
SCREEN_X = 0;
}
if ( -SCREEN_X >= MAP_WIDTH - screen_w) {
SCREEN_X = screen_w - MAP_WIDTH;
}
}
public void setTranslateY(int y) {
SCREEN_Y = SCREEN_Y + y;
if ( -SCREEN_Y <= 0) {
SCREEN_Y = 0;
}
if ( -SCREEN_Y >= MAP_HEIGHT - screen_h) {
SCREEN_Y = screen_h - MAP_HEIGHT;
}
}
public void drawWindLine(Graphics g) {
g.setColor(255, 255, 255);
g.drawString("wind", 43 - SCREEN_X, 13 - SCREEN_Y, 20);
g.setColor(0, 0, 0);
g.drawRect(19 - SCREEN_X, 14 - SCREEN_Y, 21, 8);
g.drawRect(70 - SCREEN_X, 14 - SCREEN_Y, 21, 8); ;
g.setColor(66, 186, 255);
g.fillRect(20 - SCREEN_X, 15 - SCREEN_Y, 20, 7);
g.fillRect(71 - SCREEN_X, 15 - SCREEN_Y, 20, 7);
g.setColor(202, 236, 255);
if (map.m_nWindPower < 0) {
g.fillRect(40 - SCREEN_X + map.m_nWindPower, 15 - SCREEN_Y,
Math.abs(map.m_nWindPower), 7);
}
else {
g.fillRect(71 - SCREEN_X, 15 - SCREEN_Y, map.m_nWindPower, 7);
}
}
/** to Create the backgroud*/
private void drawBG(Graphics g) {
try {
g.setColor(mapColor[ (cur_mapid - 1) % 4]);
g.fillRect( -SCREEN_X, -SCREEN_Y, screen_w, screen_h);
if (map != null) {
map.paint(g);
}
g.setColor(0, 0, 0);
g.drawRect( -SCREEN_X + 19, 3 - SCREEN_Y, 71, 8); //力度条的外框
drawWindLine(g);
Font f = Font.getFont(Font.FACE_SYSTEM,
Font.STYLE_BOLD,
Font.SIZE_MEDIUM);
g.setFont(f);
if (gameStatus > 5 && isMe && runs.length > 1) {
g.setColor(mapColor[ (cur_mapid - 1) % 4]);
g.fillRect(-SCREEN_X + 2,-SCREEN_Y + 10,16,16);
g.setColor(255, 50, 50);
g.drawString("" + count_time, -SCREEN_X,
-SCREEN_Y + 10, 20);
}
//掉物品
drawItemAnimation(g);
for (int index = 0; index < runs.length; index++) {
Tank ct = null;
try {
ct = runs[index];
}
catch (ArrayIndexOutOfBoundsException ex) {
break;
}
if (ct != null) {
if (ct.life > 0) {
ct.paint(g);
if (ct.life < 20) {
g.setColor(248, 103, 114);
}
else {
if (!runs[index].isEnemy) {
g.setColor(91, 255, 91);
}
else {
g.setColor(117, 255, 255);
}
}
f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD,
Font.SIZE_SMALL);
g.setFont(f);
g.drawString(ct.userName + "",
ct.tank_x + 5,
ct.tank_y - 25,
g.TOP | g.LEFT); //画坦克名字
f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
Font.SIZE_SMALL);
g.setFont(f);
g.drawString(ct.life + "",
ct.tank_x + 5,
ct.tank_y - 15,
g.TOP | g.LEFT);
}
}
}
if (arrow != null) {
g.drawImage(arrow, now.tank_x - 4, now.tank_y - 35, 20);
}
g.setColor(255, 255, 0);
//打印战场的消息
for (int i = 0; i < content.length; i++) {
if (!content[i].equals("")) {
g.drawString(content[i], 5 - SCREEN_X,
25 + i * 13 - SCREEN_Y, 20);
}
}
if (now != null) {
if (now.userName.equals(userName)) {
if(compass != null)
g.drawImage(compass, 28 - SCREEN_X,
screen_h - SCREEN_Y - 16,
20);
int x = MathFP.toInt(MathFP.mul(MathFP.toFP(15),
MathFP.cos(
MathFP.mul(MathFP.toFP(now.angle),
MathFP.toFP("0.0174532")))));
int y = MathFP.toInt(MathFP.mul(MathFP.toFP(15),
MathFP.sin(
MathFP.mul(MathFP.toFP(now.angle),
MathFP.toFP("0.0174532")))));
int h;
if (now.angle == 90) {
h = 45 - SCREEN_X;
}
else {
h = 45 + now.direction * x - SCREEN_X;
}
g.drawLine(45 - SCREEN_X, screen_h - SCREEN_Y - 1, h,
screen_h - SCREEN_Y - y - 1);
if(view != null)
g.drawImage(view, screen_w - SCREEN_X - 60,
screen_h - SCREEN_Y - 17, 20);
if(move != null)
g.drawImage(move, screen_w - SCREEN_X - 40,
screen_h - SCREEN_Y - 17, 20);
if (now.userName.equals(userName) && now.USED_PRO) {
if(curUsed != null)
g.drawImage(curUsed, screen_w - SCREEN_X - 20,
screen_h - SCREEN_Y - 17, 20);
}
else {
if(prop != null);
g.drawImage(prop, screen_w - SCREEN_X - 20,
screen_h - SCREEN_Y - 17, 20);
}
}
}
}
catch (Exception e) {
e.printStackTrace();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -