?? tank.java
字號:
package demo;
import java.util.*;
import javax.microedition.lcdui.*;
import com.nokia.mid.ui.*;
import net.jscience.util.*;
public class Tank {
public String userName; //坦克名稱(用戶名)
public int speed; //射擊的速率
public int angle; //炮管的角度
public int move; //還可以移動多少次
public int life;
public int tmp_life = 0;
public int attackRadius;
public int missile_num = 1;
public Vector properties; //攜帶的物品:導彈 0$物品的Id$物品的名字$攻擊力$導彈個數$攻擊范圍$
//物品:1$物品的Id$物品的名字$血$移動力$
public int direction;
public int grade; //梯度
public int basicDamage;
public boolean isEnemy;
public Image img_l; //坦克的圖片
public int tank_x; //x坐標位置
public int tank_y; //y坐標位置
public static int TANK_VSCALE = 24;
public static int TANK_HSCALE = 18;
//攻擊力$導彈個數$攻擊范圍$移動力$
public int INIT_LIFE;
private int INIT_DEMAGE;
//private int INIT_MISSILE;
private int INIT_ATTACKAREA;
private int INIT_MOVE;
public boolean USED_PRO; //一輪內是否已經用過物品,用過就不能再用。
public Tank( /*BattleField battleCan,/**/String tankName,
int tankID, int move, int grade,
int initDemage,
int x, int y, int initLife,
boolean isEnemy, int radius) {
//tankID tankName tankPic move grade initLife initDamage
speed = 0; //導彈的速率
angle = 45; //炮管的角度
INIT_LIFE = life = initLife;
userName = tankName;
//System.out.println("******** tankID *******" + tankID);
try {
byte abyte[] = Main.b("t_l_" + tankID + ".png");
img_l = Image.createImage(abyte, 0, abyte.length);
abyte = null;
}
catch (Exception e) {
//System.out.println("hihihihi");
e.printStackTrace();
}
this.isEnemy = isEnemy;
//TANK_VSCALE = img_l.getHeight();
//TANK_HSCALE = img_l.getWidth();
tank_x = x; // 坦克中心點在屏幕上的坐標
tank_y = y - TANK_VSCALE / 2;
//System.out.println("tank_x : " + tank_x);
//System.out.println("tank_y : " + tank_y);
direction = x < 100 ? 1 : -1;
INIT_MOVE = this.move = move;
INIT_DEMAGE = basicDamage = initDemage;
//System.out.println("basicDamage = " + basicDamage);
INIT_ATTACKAREA = attackRadius = radius;
this.grade = grade;
//battleCanvas = battleCan; //戰場
properties = new Vector();
USED_PRO = false;
// 導彈 0$物品的Id$物品的名字$攻擊力$導彈個數$攻擊范圍$
}
//用來確定炮管的兩個坐標點
//計算公式如下
//x1 : 炮管開始x坐標x1 = k() + 9;
//y1 : 炮管開始y坐標y1 = h() + 9;
//x2 : 炮管末尾x坐標 x2 = x1 + 13 * cos(angle * t); // 13應該是炮管長度
//y2 : 炮管末尾y坐標 y2 = y1 - 13 * sin(angle * t);
/*public void getBarrelPosition() {
//炮管的初始位置
x1 = tank_x + 4;
y1 = tank_y + 4;
//根據角度g算出導彈發射裝置的末尾位置,并保存到s,y2
//先把角度g通toFP函數來轉化為定點整數
//t = toFP("0.0174532")
//調用mul函數來對兩個數進行乘法運算 k = 0.0174532*angle
k = MathFP.mul(MathFP.toFP(angle), t);
//cos(k)
p = MathFP.cos(k);
//sin(k)
o = MathFP.sin(k);
//toFP(13)
h = MathFP.toFP(13);
//toFP(x1)
n = MathFP.toFP(x1);
//toFP(y1)
w = MathFP.toFP(y1);
x2 = MathFP.toInt(MathFP.add(n, MathFP.mul(h, p)));
if (direction == -1) {
x2 = x2 - 2 * (x2 - x1); //相反方向
}
int i1 = MathFP.sub(w, MathFP.mul(h, o));
y2 = MathFP.toInt(i1);
}*/
public void setInit() {
move = INIT_MOVE;
speed = 0;
basicDamage = INIT_DEMAGE;
attackRadius = INIT_ATTACKAREA;
//angle = 25;
missile_num = 1; //導彈數目
USED_PRO = false; //沒有用過物品
Main.displayable.route.removeAllElements();
Main.displayable.route.addElement(new Integer(tank_x));
Main.displayable.route.addElement(new Integer(tank_y));
}
public void paint(Graphics g1) {
if (direction == 1) { // 向右
DirectGraphics dg = DirectUtils.getDirectGraphics(g1);
if (img_l != null)
dg.drawImage(img_l, tank_x - TANK_HSCALE / 2,
tank_y - TANK_VSCALE / 2, 20, 0x2000); //Image img, int x, int y, int anchor, int manipulation()FLIP_HORIZONTAL
}
else { // 向左
if (img_l != null)
g1.drawImage(img_l, tank_x - TANK_HSCALE / 2,
tank_y - TANK_VSCALE / 2,
Graphics.TOP | Graphics.LEFT); //0x2000, FLIP_HORIZONTAL
}
}
//角度判斷
public void increaseAngle() {
if (angle < 90) {
angle++;
}
}
//角度判斷
public void decreaseAngle() {
if (angle > 0) {
angle--;
}
}
public void moveTank(int dir) {
//boolean isRight = (dir == 1);
boolean scope = false;
//System.out.println("x = " + tank_x + " y = " + tank_y);
if (dir == 1) { //向右
//System.out.println("isRight!");
scope = tank_x <= Main.displayable.MAP_WIDTH - TANK_HSCALE / 2;
}
else { //向左
scope = tank_x >= TANK_HSCALE / 2;
}
if (scope) {
//System.out.println("x = " + tank_x + " y = " + tank_y);
int temp = Main.displayable.map.getTankY(this);
//System.out.println("temp = " + temp);
if (temp == -1) {
else {
if (temp == -2) { // 坦克死亡
if (userName.equals(Main.displayable.userName)) { // 是輪到自己
Main.displayable.isMe = false;
tank_y = Main.displayable.MAP_HEIGHT;
tank_x = tank_x + dir * TANK_HSCALE / 2;
if (tank_x < TANK_HSCALE / 2) {
tank_x = TANK_HSCALE / 2;
}
else {
if (tank_x >
Main.displayable.MAP_WIDTH - 1 -
TANK_HSCALE / 2) {
tank_x = Main.displayable.MAP_WIDTH - 1 -
TANK_HSCALE / 2;
}
}
Main.displayable.route.addElement(new Integer(tank_x));
Main.displayable.route.addElement(new Integer(tank_y));
/*System.out.println("add x = " + tank_x + ", y = " +
tank_y);
Main.displayable.repaint(0, 0,
Main.displayable.screen_w,
Main.displayable.screen_h);/**/
HttpClientHolder httpClientHolder = new
HttpClientHolder();
httpClientHolder.WriteByte( (byte) 37);
Main.displayable.writeRoute(httpClientHolder);
Main.displayable.route.removeAllElements();
Main.displayable.mHttpConnection.addSendMessage(
httpClientHolder);
}
try {
Thread.sleep(100L);
}
catch (InterruptedException ex) {
}
life = 0;
Main.displayable.repaint();
Main.displayable.now = Main.displayable.nextTank();
Main.displayable.scrollToNow();
Main.displayable.now.setInit();
Main.displayable.setGameStatus();
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號