?? tank.java
字號:
if (temp > tank_y) {
tank_x = tank_x + dir * TANK_HSCALE / 2;
//System.out.println("yes below , tank_x = " + tank_x);
}
else {
tank_x = tank_x + dir;
//System.out.println("no overhead, tank_x++ = " + tank_x);
}
if (tank_x < TANK_HSCALE / 2) {
tank_x = TANK_HSCALE / 2;
//System.out.println("tank_y = " + tank_y);
}
else {
if (tank_x >
Main.displayable.MAP_WIDTH - 1 - TANK_HSCALE / 2) {
tank_x = Main.displayable.MAP_WIDTH - 1 -
TANK_HSCALE / 2;
}
else {
if (temp > tank_y) {
tank_y = Main.displayable.map.getDownNotNull(tank_x,
tank_y) - TANK_VSCALE / 2;
Main.displayable.content[0] = "tank_y down = " +
tank_y;
}
else {
tank_y = temp;
}
}
}
//System.out.println("b add x = " + tank_x +
// ", y = " +
// tank_y);
Main.displayable.route.addElement(new Integer(tank_x));
Main.displayable.route.addElement(new Integer(tank_y));
if (tank_y >
Main.displayable.screen_h * 3 / 4 -
Main.displayable.SCREEN_Y &&
-Main.displayable.SCREEN_Y <=
Main.displayable.MAP_HEIGHT - Main.displayable.screen_h) {
Main.displayable.setTranslateY( (short) ( -Math.min(temp -
tank_y,
Main.displayable.MAP_HEIGHT - Main.displayable.SCREEN_Y)));
}
if (dir == 1) {
if (tank_x >
Main.displayable.screen_w * 3 / 4 -
Main.displayable.SCREEN_X &&
-Main.displayable.SCREEN_X <=
Main.displayable.MAP_WIDTH - Main.displayable.screen_w
) {
Main.displayable.setTranslateX( -1);
}
}
if (dir == -1) {
if (tank_x <
-Main.displayable.SCREEN_X +
Main.displayable.screen_w / 4 &&
Main.displayable.SCREEN_X < 0
) {
Main.displayable.setTranslateX(1);
}
}
move--;
Main.displayable.repaint();
}
}
//System.out.println("after moveTank x = " + tank_x + " y = " + tank_y);
}
//是否對導彈的速度加速
public void accelerate() {
if (speed < 70) {
speed++;
}
//Main.displayable.repaint(4, 4, 80, 40);
}
//這個函數用來判斷時候與導彈碰撞
public boolean isCollision(Missile e1) {
//計算導彈的位置
if (e1.m_x > tank_x - 8 && e1.m_x < tank_x + 8 &&
e1.m_y > tank_y - 8 &&
e1.m_y < tank_y + 8) { // 擊中坦克
return true;
}
else {
return false;
}
}
public void addProperties(String property) {
//properties.insertElementAt(property, 0);
if (properties.size() < 4) {
properties.addElement(property);
}
}
public String getProperty(int index, int token) {
int maxToken = -1;
int mode = Integer.parseInt(getStringBetween(index, 0));
if (mode == 0) {
maxToken = 6;
}
if (mode == 1) {
maxToken = 5;
}
if (index < properties.size() && index >= 0 && 0 <= token &&
token <= maxToken) {
return getStringBetween(index, token);
}
//以后可能還會有其他的物品
return "";
}
/*
public int getPropertyID(int index) {
//攜帶的物品:導彈 0$物品的Id$物品的名字$攻擊力$導彈個數$攻擊范圍$
//物品:1$物品的Id$物品的名字$血$移動力$
//System.out.println("index = " + index + "properties.size() " + properties.size());
if (index < properties.size() && index >= 0) {
String id = getStringBetween(index, 1);
//System.out.println("get Prop id: " + id);
return Integer.parseInt(id);
}
else {
return -1;
}
}
public String getPropertyName(int index) {
if (index < properties.size() && index >= 0) {
String id = getStringBetween(index, 2);
return id;
}
else {
return null;
}
}
public int getAttackDemage(int index) {
if (index < properties.size() && index >= 0) {
String id = getStringBetween(index, 3);
return Integer.parseInt(id);
}
else {
return 0;
}
}
public int getMissilesNum(int index) {
if (index < properties.size() && index >= 0) {
String id = getStringBetween(index, 4);
return Integer.parseInt(id);
}
else {
return 0;
}
}
public int getAttackArea(int index) {
if (index < properties.size() && index >= 0) {
String id = getStringBetween(index, 5);
return Integer.parseInt(id);
}
else {
return 0;
}
}
public int getBlood(int index) {
if (index < properties.size() && index >= 0) {
String id = getStringBetween(index, 3);
return Integer.parseInt(id);
}
else {
return 0;
}
}
public int getMove(int index) {
if (index < properties.size() && index >= 0) {
String id = getStringBetween(index, 4);
return Integer.parseInt(id);
}
else {
return 0;
}
}
*/
public String getStringBetween(int index, int start) {
//攜帶的物品:導彈 0$物品的Id$物品的名字$攻擊力$導彈個數$攻擊范圍$
//物品 1$物品的Id$物品的名字$血$移動力$
int temp = -1;
String s = (String) properties.elementAt(index);
for (int n = 1; n <= start; n++) {
temp = s.indexOf("$", temp + 1);
}
String result = s.substring(temp + 1, s.indexOf("$", temp + 1));
return result;
}
/*public boolean isMissile(int index) {
String s = (String) properties.elementAt(index);
return Integer.parseInt(s.substring(0, 1)) == 0;
}*/
public int getInitLife() {
return INIT_LIFE;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -