GameOverScreen.java
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:4k
源码类别:

J2ME

开发平台:

Java

  1. import javax.microedition.lcdui.*;
  2. class GameOverScreen    extends Canvas
  3. {
  4.     private final escapeeMIDlet midlet;
  5.     private boolean wasBestTime;
  6.     private long time;
  7.     private long bestTime;
  8.     private int BULLETS_NUM;
  9.     GameOverScreen(escapeeMIDlet midlet, long time, int BULLETS_NUM)
  10.     {
  11.         super();
  12.         this.midlet = midlet;
  13.         this.time = time;
  14.         this.BULLETS_NUM = BULLETS_NUM;
  15.         setFullScreenMode(true);
  16.         if (midlet.checkBestTime(time))
  17.         {
  18.             wasBestTime = true;
  19.             bestTime = time;
  20.             SoundEffects.getInstance().startHighScoreSound();
  21.             midlet.vibrate(1000);
  22.         }
  23.         else
  24.         {
  25.             wasBestTime = false;
  26.             bestTime = midlet.getBestTime();
  27.             SoundEffects.getInstance().startGameOverSound();
  28.         }
  29.         midlet.flashBacklight(1000);    // 1 second
  30.     }
  31.     public void paint(Graphics g)
  32.     {
  33.         int CanvasWidth = getWidth();
  34.         int CanvasHeight = getHeight();
  35.         // clear screen to green
  36.         g.setColor(245,130,35);
  37.         g.fillRect(0, 0, CanvasWidth, CanvasHeight);
  38.         // Write message. We use a trick to make outlined text: we draw it
  39.         // offset one pixel to the top, bottom, left & right in white, then
  40.         // centred in black.
  41.         g.setFont(Font.getFont(Font.FACE_PROPORTIONAL,
  42.                                Font.STYLE_BOLD,
  43.                                Font.SIZE_LARGE));
  44.         int centerX = CanvasWidth / 2;
  45.         int centerY = CanvasHeight / 2;
  46.         g.setColor(0x00FFFFFF);   // white
  47.         drawText(g, centerX, centerY - 1);
  48.         drawText(g, centerX, centerY + 1);
  49.         drawText(g, centerX - 1, centerY);
  50.         drawText(g, centerX + 1, centerY);
  51.         g.setColor(0x00000000);   // black
  52.         drawText(g, centerX, centerY);
  53.     }
  54.     private void drawText(Graphics g, int centerX, int centerY)
  55.     {
  56.         int fontHeight = g.getFont().getHeight();
  57.         int textHeight = 5 * fontHeight;
  58.         int topY = centerY - textHeight / 2;
  59.         float Time_Second = (float)time/1000; 
  60.         float BestTime_Second = (float)bestTime/1000; 
  61.         String level;
  62.          
  63.         if(Time_Second<5){
  64.         level = "被歼灭者";
  65.         }else if(Time_Second<15){
  66.         level = "初级飞行员";
  67.         }else if(Time_Second<20){
  68.         level = "中级飞行员";
  69.         }else if(Time_Second<25){
  70.         level = "高级飞行员";
  71.         }else if(Time_Second<30){
  72.         level = "逃亡者";
  73.         }else{
  74.         level = "胜利大逃亡!";        
  75.         }
  76.         
  77.         g.drawString("GAME OVER",
  78.                      centerX,
  79.                      topY,
  80.                      Graphics.HCENTER | Graphics.TOP);
  81.         g.drawString("时间: " + Time_Second+ "s",
  82.                      centerX,
  83.                      topY + fontHeight,
  84.                      Graphics.HCENTER | Graphics.TOP);
  85.         g.drawString("等级: " + level,
  86.                      centerX,
  87.                      topY + 2 *fontHeight,
  88.                      Graphics.HCENTER | Graphics.TOP);
  89.        g.drawString("子弹:"+BULLETS_NUM+"发",
  90.                      centerX,
  91.                      topY + 3 * fontHeight,
  92.                      Graphics.HCENTER | Graphics.TOP);
  93.        g.drawString(wasBestTime ? "这是目前最好记录!" :
  94.                                    ("最长时间:" + BestTime_Second + "s"),
  95.                      centerX,
  96.                      topY + 4 * fontHeight,
  97.                      Graphics.HCENTER | Graphics.TOP);
  98.     }
  99.     
  100.     public void keyPressed(int keyCode)
  101.     {
  102.         midlet.gameOverDone();
  103.     }
  104. }