?? gameoverscreen.java
字號:
/*
* GameOverScreen.java
*
* Created on 2006年11月25日, 上午10:27
*
* 游戲結束屏 -- 顯示玩家得分、游戲時間、玩家能力評價、最高得分
*/
import javax.microedition.lcdui.*;
/**
*
* @author TOM
*/
public class GameOverScreen extends Canvas implements CommandListener{
private final ManMidlet midlet; //主類
private boolean isBestRecord; //是否最佳成績標志位
private long time; //游戲持續時間
private int record; //當前成績
private int bestRecord; //最佳成績
/** Creates a new instance of GameOverScreen */
public GameOverScreen(ManMidlet midlet,long time,int record) {
super();
this.midlet = midlet;
this.time = time;
this.record = record;
addCommand(new Command("確定",Command.OK,1)); //確認分數按鈕
setCommandListener(this);
if(midlet.checkBestRecord(record)){
isBestRecord = true;
bestRecord = record;
}else{
isBestRecord = false;
bestRecord = midlet.getBestRecord();
}
}
public void paint(Graphics g){
int CanvasWidth = getWidth();
int CanvasHeight = getHeight();
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD,Font.SIZE_LARGE));
int centerX = CanvasWidth / 2;
int centerY = CanvasHeight / 2;
g.setColor(0x00FFFFFF);
drawText(g,centerX,centerY-1); //粗體顯示內容
drawText(g,centerX,centerY+1);
drawText(g,centerX-1,centerY);
drawText(g,centerX+1,centerY);
g.setColor(0x000000);
drawText(g, centerX,centerY);
}
private void drawText(Graphics g, int centerX, int centerY){
int fontHeight = g.getFont().getHeight();
int textHeight = 5 * fontHeight;
int topY = centerY - textHeight/2;
String level; //玩家評價
if(time < 5000){
level = "胎兒";
}else if(time < 10000){
level = "嬰兒";
}else if(time < 15000){
level = "兒童";
}else if(time < 20000){
level = "青少年";
}else if(time < 30000){
level = "成年";
}else{
level = "您已經不需要再玩這個游戲了";
}
g.drawString("GAME OVER", centerX, topY, Graphics.HCENTER|Graphics.TOP);
g.drawString("時間:"+time/1000+"."+time%1000 + "s",centerX, topY+fontHeight,
Graphics.HCENTER|Graphics.TOP);
g.drawString("等級:"+level, centerX, topY+2*fontHeight,
Graphics.HCENTER|Graphics.TOP);
g.drawString("分數:"+record, centerX, topY+3*fontHeight,
Graphics.HCENTER|Graphics.TOP);
g.drawString(isBestRecord ? "這是目前最好紀錄!" : ("最高分"+bestRecord+"分"),
centerX, topY+4*fontHeight, Graphics.HCENTER|Graphics.TOP);
}
public void commandAction(Command command, Displayable displayable){
if (command.getCommandType() == Command.OK) {
midlet.gameOverDone();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -