⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gameoverscreen.java

📁 用 Jbulider 写的 是男人就撑20秒 希望大家能够喜欢
💻 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();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -