?? tank.java
字號:
}
break;
}
driveStartTime = tickTime;
}
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 18JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* return player tank object.
* @return player tank object.
*/
public static PlayerTank getPlayerTank(){
return (PlayerTank)TANK_POOL[0];
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 15JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Set the layerManager for tanks.
*/
public static void setLayerManager(LayerManager manager) {
layerManager = manager;
if (layerManager != null){
for (int i = 0; i < POOL_SIZE; i++)
layerManager.append(TANK_POOL[i]);
}
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 15JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Set the Battle field for tanks.
*/
public static void setBattleField(BattleField field) {
battleField = field;
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 15JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Operation be done in each tick.
*/
public void tick(){
if(isVisible()){
think();
drive();
shoot();
}
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 16JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Tank thinks before move.
*/
public abstract void think();
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 16JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Tank shoots.
* @return the bullet the tank shoots.
*/
public abstract Bullet shoot();
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 16JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Initialize tank status.
*/
public abstract void initTank();
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 16JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Tank try to move (dx,dy)
* @param dx the delta x
* @param dy the delta y
*/
private void tryMove(int dx, int dy) {
move(dx, dy);
if (overlapsTank(this))
move(-dx, -dy);
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 16JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Explode a tank.
*/
protected void explode() {
Explosion.explode(getRefPixelX(), getRefPixelY(), Explosion.BIG);
setVisible(false);
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 15JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Get an tank object.
* @param i the index of tank.
*/
protected static Tank getTank(int i) {
if(i>POOL_SIZE-1){
return null;
}
if(TANK_POOL[i]!=null){
return TANK_POOL[i];
}else{
return null;
}
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 16JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Check if there's overlap of tanks.
* @param sprite the tank need to be checked
* @return true, overlap.
*/
protected static boolean overlapsTank(Sprite sprite) {
for (int i = 0; i < POOL_SIZE; i++) {
if (sprite != TANK_POOL[i] &&
TANK_POOL[i].isVisible() &&
sprite.collidesWith(TANK_POOL[i], false))
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 16JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* change the direction of current tank.
* @param direction new direction for the tank.
*/
protected void changeDirection(int direction) {
this.direction = direction;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -