📄 score.java
字号:
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public final class Score extends Sprite implements Actor{
/**
* score 100
*/
public final static int SCORE_100 =0;
/**
* score 200
*/
public final static int SCORE_200 =1;
/**
* score 300
*/
public final static int SCORE_300 =2;
/**
* score 400
*/
public final static int SCORE_400 =3;
/**
* score 500
*/
public final static int SCORE_500 =4;
/**
* the score value.
*/
private int scoreValue=-1;
/**
* maximun number of score in the battle field.
*/
private static final int POOL_SIZE = 10;
/**
* This pool store all scores.
*/
private static Score SCORE_POOL[];
/**
* the start time of the displaying the score.
*/
private long startTime=0;
/**
* the score live time, default 1 second
*/
private static long livePeriod=1000;
/**
* Tank should know about the battle field.
*/
private static BattleField battleField;
/**
* Tank should know about the layer manager.
*/
private static LayerManager layerManager;
/**
* initial the score pool.
*/
static {
SCORE_POOL = new Score[POOL_SIZE];
for(int i=0;i<POOL_SIZE;i++){
SCORE_POOL[i]=new Score();
SCORE_POOL[i].setVisible(false);
}
}
public void setValue(int value){
this.scoreValue=value;
setFrame(value);
}
public int getValue(){
return this.scoreValue;
}
private Score() {
super(ResourceManager.getInstance().getImage(ResourceManager.SCORE),
ResourceManager.getInstance().
getImage(ResourceManager.SCORE).getWidth()/5,
ResourceManager.getInstance().
getImage(ResourceManager.SCORE).getHeight());
}
public void tick(){
if(isVisible()){
long tickTime = System.currentTimeMillis();
if(startTime>0){
if(tickTime-startTime>livePeriod){
setVisible(false);
startTime=0;
return;
}
}
}
}
public static Score show(int x, int y,int value) {
for (int i = 0; i < POOL_SIZE; ++i) {
Score score = SCORE_POOL[i];
if (!score.isVisible()) {
score.startTime=System.currentTimeMillis();
score.setRefPixelPosition(x, y);
score.setValue(value);
score.setVisible(true);
return score;
}
}
return null;
}
public static void setLayerManager(LayerManager manager) {
layerManager = manager;
if (layerManager != null){
for (int i = 0; i < POOL_SIZE; i++)
layerManager.append(SCORE_POOL[i]);
}
}
public static void setBattleField(BattleField field) {
battleField = field;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -