GameOverScreen.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:4k
源码类别:
J2ME
开发平台:
Java
- import javax.microedition.lcdui.*;
- class GameOverScreen extends Canvas
- {
- private final escapeeMIDlet midlet;
- private boolean wasBestTime;
- private long time;
- private long bestTime;
- private int BULLETS_NUM;
- GameOverScreen(escapeeMIDlet midlet, long time, int BULLETS_NUM)
- {
- super();
- this.midlet = midlet;
- this.time = time;
- this.BULLETS_NUM = BULLETS_NUM;
- setFullScreenMode(true);
- if (midlet.checkBestTime(time))
- {
- wasBestTime = true;
- bestTime = time;
- SoundEffects.getInstance().startHighScoreSound();
- midlet.vibrate(1000);
- }
- else
- {
- wasBestTime = false;
- bestTime = midlet.getBestTime();
- SoundEffects.getInstance().startGameOverSound();
- }
- midlet.flashBacklight(1000); // 1 second
- }
- public void paint(Graphics g)
- {
- int CanvasWidth = getWidth();
- int CanvasHeight = getHeight();
- // clear screen to green
- g.setColor(245,130,35);
- g.fillRect(0, 0, CanvasWidth, CanvasHeight);
- // Write message. We use a trick to make outlined text: we draw it
- // offset one pixel to the top, bottom, left & right in white, then
- // centred in black.
- g.setFont(Font.getFont(Font.FACE_PROPORTIONAL,
- Font.STYLE_BOLD,
- Font.SIZE_LARGE));
- int centerX = CanvasWidth / 2;
- int centerY = CanvasHeight / 2;
- g.setColor(0x00FFFFFF); // white
- drawText(g, centerX, centerY - 1);
- drawText(g, centerX, centerY + 1);
- drawText(g, centerX - 1, centerY);
- drawText(g, centerX + 1, centerY);
- g.setColor(0x00000000); // black
- 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;
- float Time_Second = (float)time/1000;
- float BestTime_Second = (float)bestTime/1000;
- String level;
- if(Time_Second<5){
- level = "被歼灭者";
- }else if(Time_Second<15){
- level = "初级飞行员";
- }else if(Time_Second<20){
- level = "中级飞行员";
- }else if(Time_Second<25){
- level = "高级飞行员";
- }else if(Time_Second<30){
- level = "逃亡者";
- }else{
- level = "胜利大逃亡!";
- }
- g.drawString("GAME OVER",
- centerX,
- topY,
- Graphics.HCENTER | Graphics.TOP);
- g.drawString("时间: " + Time_Second+ "s",
- centerX,
- topY + fontHeight,
- Graphics.HCENTER | Graphics.TOP);
- g.drawString("等级: " + level,
- centerX,
- topY + 2 *fontHeight,
- Graphics.HCENTER | Graphics.TOP);
- g.drawString("子弹:"+BULLETS_NUM+"发",
- centerX,
- topY + 3 * fontHeight,
- Graphics.HCENTER | Graphics.TOP);
- g.drawString(wasBestTime ? "这是目前最好记录!" :
- ("最长时间:" + BestTime_Second + "s"),
- centerX,
- topY + 4 * fontHeight,
- Graphics.HCENTER | Graphics.TOP);
- }
- public void keyPressed(int keyCode)
- {
- midlet.gameOverDone();
- }
- }