📄 tank.java~1~
字号:
package demo;
import com.nokia.mid.ui.DirectGraphics;
import com.nokia.mid.ui.DirectUtils;
import java.util.Vector;
import java.io.IOException;
import java.io.PrintStream;
import javax.microedition.lcdui.*;
import net.jscience.util.MathFP;
public class Tank {
public int ID; //坦克战场内标号
public String userName; //坦克名称(用户名)
public int speed; //射击的速率
public int angle; //炮管的角度
public int move; //还可以移动多少次
public int life;
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 z;
public static int y;
public static int TANK_VSCALE = 24;
public static int TANK_HSCALE = 18;
public BattleField battleCanvas; //场景
//攻击力$导弹个数$攻击范围$移动力$
private int INIT_LIFE;
private int INIT_DEMAGE;
private int INIT_MISSILE;
private int INIT_ATTACKAREA;
private int INIT_MOVE;
public boolean USED_PRO; //一轮内是否已经用过物品,用过就不能再用。
static final int t = MathFP.toFP("0.0174532");
int k;
int p;
int o;
int h;
int n;
int w;
//炮管的始末点
public int x1;
public int y1;
public int x2;
public int y2;
public Tank(BattleField battleCan, String tankName,
int tankID, int move, int grade, int initDemage,
int x, int y, int initLife, boolean isEnemy) {
//tankID tankName tankPic move grade initLife initDamage
speed = 0; //导弹的速率
angle = 45; //炮管的角度
INIT_LIFE = life = initLife;
userName = tankName;
//System.out.println("******** tankID *******" + tankID);
try {
img_l = Image.createImage("/demo/res/t_l_" + tankID + ".png");
}
catch (Exception e) {
e.printStackTrace();
}
this.isEnemy = isEnemy;
//TANK_VSCALE = img_l.getHeight();
//TANK_HSCALE = img_l.getWidth();
tank_x = x; // 坦克中心点在屏幕上的坐标
tank_y = y - TANK_VSCALE / 2;
direction = x < 100 ? 1 : -1;
INIT_MOVE = this.move = move;
INIT_DEMAGE = basicDamage = initDemage;
//System.out.println("basicDamage = " + basicDamage);
INIT_ATTACKAREA = attackRadius = 12;
this.grade = grade;
battleCanvas = battleCan; //战场
properties = new Vector();
USED_PRO = false;
/*addProperties("1$0$arale$10$100$"); // 1$物品的Id$物品的名字$血$移动力$
addProperties("1$1$bb$10$100$");
addProperties("1$2$dabao$10$100$");
addProperties("0$0$missile$0$2$0$"); */
// 导弹 0$物品的Id$物品的名字$攻击力$导弹个数$攻击范围$
//System.out.println("properties.size() = " + properties.size());
}
//用来确定炮管的两个坐标点
//计算公式如下
//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; //没有用过物品
battleCanvas.route.removeAllElements();
battleCanvas.route.addElement(new Integer(tank_x));
battleCanvas.route.addElement(new Integer(tank_y));
//System.out.println("D x = " + tank_x + " y = " + tank_y);
//System.out.println("&&&&&&&&&&&&&&&&&&&&after init route size: " + battleCanvas.route.size() );
/*//System.out.println("move: " + move);
//System.out.println("basicDamage: " + basicDamage);
//System.out.println("attackRadius: " + attackRadius);
//System.out.println("move: " + move);*/
}
public void paint(Graphics g1) {
if (direction == 1) { // 向右
DirectGraphics dg = DirectUtils.getDirectGraphics(g1);
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 { // 向左
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 moveLeft() {
if (tank_x >= TANK_HSCALE / 2) {
int temp = battleCanvas.map.getTankY(this);
//System.out.println("temp = " + temp);
if (temp == -1) {
}
else {
if (temp == -2) { //掉下屏幕以下了
if (userName.equals(battleCanvas.userName)) {
tank_y = battleCanvas.screen_h;
tank_x = tank_x - TANK_HSCALE / 2;
battleCanvas.route.addElement(new Integer(tank_x));
battleCanvas.route.addElement(new Integer(tank_y));
battleCanvas.repaint(0, 0, battleCanvas.MAP_WIDTH,
battleCanvas.screen_w);
HttpClientHolder httpClientHolder = new
HttpClientHolder();
httpClientHolder.WriteInt(37);
/*用户移动路径长度 Int(包括原点)
[ x Int
y Int ]
*/
httpClientHolder.WriteInt(battleCanvas.route.size());
for (int jj = 0; jj < battleCanvas.route.size(); jj++) {
int cordi;
if (jj % 2 == 0) {
cordi = ( (Integer) battleCanvas.route.
elementAt(jj)).
intValue(); // x
}
else {
cordi = ( (Integer) battleCanvas.route.
elementAt(jj)).
intValue() +
battleCanvas.now.TANK_VSCALE / 2; // y
}
httpClientHolder.WriteInt(cordi);
}
battleCanvas.route.removeAllElements();
battleCanvas.mHttpConnection.addSendMessage(
httpClientHolder);
}
//System.out.println("******** sleep to see ************");
try {
Thread.sleep(20L);
}
catch (InterruptedException ex) {
}
life = 0;
//System.out.println("******** begin to fade ***********");
battleCanvas.repaint(0, 0, battleCanvas.MAP_WIDTH,
battleCanvas.screen_w);
battleCanvas.now = battleCanvas.nextTank();
battleCanvas.now.setInit();
if (battleCanvas.now.userName.equals(battleCanvas.userName)) {
battleCanvas.gameStatus = battleCanvas.GAME_VIEW;
}
else {
battleCanvas.gameStatus = battleCanvas.GAME_OTHERS;
}
return;
}
if (temp > tank_y) {
tank_x = tank_x - TANK_HSCALE / 2;
}
else {
tank_x--; //每一步移动1个象素
}
if (temp >
battleCanvas.screen_h * 3 / 4 - battleCanvas.SCREEN_Y &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -