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

📄 highscore.java

📁 扫雷...不用介绍了吧. 压缩包里面有截图直接在WTK里面使用
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   HighScore.java

package com.innograte.j2me.games.minefield;

import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.RecordStore;

// Referenced classes of package com.innograte.j2me.games.minefield:
//            MinefieldMidlet

public class HighScore extends Canvas
    implements CommandListener
{

    public final String HIGH_SCORE_RS_NAME = "MinesHighScore";
    public final int numOfHighScores = 12;
    public String highScoreNames[];
    public int highScores[];
    private Command backCommand;
    private Command nameInputConfirmCommand;
    public MinefieldMidlet minesMidlet;
    public Displayable previousDisplayable;
    public int newHighScoreIndex;
    public TextField userInputName;

    public HighScore(MinefieldMidlet aMinesMidlet)
    {
        backCommand = new Command("Back", 2, 1);
        nameInputConfirmCommand = new Command("OK", 4, 1);
        previousDisplayable = null;
        minesMidlet = aMinesMidlet;
        highScoreNames = new String[12];
        highScores = new int[12];
        Object obj = null;
        try
        {
            RecordStore recordstore = RecordStore.openRecordStore("MinesHighScore", true);
            if(recordstore.getNumRecords() == 0)
            {
                ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
                DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
                dataoutputstream.writeInt(999);
                String s = "Empty.";
                for(int i = 0; i < 12; i++)
                {
                    highScores[i] = 999;
                    highScoreNames[i] = s;
                    recordstore.addRecord(s.getBytes(), 0, s.getBytes().length);
                    recordstore.addRecord(bytearrayoutputstream.toByteArray(), 0, 4);
                }

                recordstore.closeRecordStore();
            } else
            {
                for(int j = 0; j < 12; j++)
                {
                    ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(recordstore.getRecord(j * 2 + 2));
                    DataInputStream datainputstream = new DataInputStream(bytearrayinputstream);
                    highScores[j] = datainputstream.readInt();
                    highScoreNames[j] = new String(recordstore.getRecord(j * 2 + 1));
                }

                recordstore.closeRecordStore();
            }
            addCommand(backCommand);
            setCommandListener(this);
        }
        catch(Exception exception)
        {
            System.out.println(exception.toString());
            exception.printStackTrace();
        }
    }

    protected void showNotify()
    {
        repaint();
    }

    public void commandAction(Command command, Displayable displayable)
    {
        if(command == backCommand)
            Display.getDisplay(minesMidlet).setCurrent(previousDisplayable);
        else
        if(command == nameInputConfirmCommand)
        {
            try
            {
                if(userInputName.getString().length() > 0)
                    highScoreNames[newHighScoreIndex] = userInputName.getString();
                else
                    highScoreNames[newHighScoreIndex] = " ";
                RecordStore recordstore = RecordStore.openRecordStore("MinesHighScore", true);
                int i = minesMidlet.difficultyLevel * 4;
                int j = i + 4;
                for(int k = i; k < j; k++)
                {
                    ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
                    DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
                    dataoutputstream.writeInt(highScores[k]);
                    recordstore.setRecord(k * 2 + 2, bytearrayoutputstream.toByteArray(), 0, 4);
                    recordstore.setRecord(k * 2 + 1, highScoreNames[k].getBytes(), 0, highScoreNames[k].getBytes().length);
                }

                recordstore.closeRecordStore();
            }
            catch(Exception exception)
            {
                System.out.println(exception.toString());
                exception.printStackTrace();
            }
            Display.getDisplay(minesMidlet).setCurrent(this);
        }
    }

    public void paint(Graphics g)
    {
        byte byte0 = 2;
        int y = 3;
        g.setColor(255, 255, 255);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.setColor(0, 0, 0);
        g.fillRect(0, 0, getWidth(), byte0);
        g.fillRect(0, byte0, byte0, getHeight());
        g.fillRect(getWidth() - byte0, 0, byte0, getHeight());
        g.fillRect(0, getHeight() - byte0, getWidth(), byte0);
        Font font = Font.getFont(0, 1, 0);
        g.setFont(font);
        g.drawString("High Scores", getWidth() / 2, y, 17);
        y += font.getHeight();
        g.drawString(MinefieldMidlet.DIFFICULTY_STRINGS[minesMidlet.difficultyLevel], getWidth() / 2, y, 17);
        y += font.getHeight();
        g.fillRect(byte0, y, getWidth(), byte0);
        y += byte0 + 1;
        font = Font.getFont(0, 0, 0);
        g.setFont(font);
        int j = minesMidlet.difficultyLevel * 4;
        int k = j + 4;
        for(int l = j; l < k; l++)
        {
            g.drawString(String.valueOf(String.valueOf((new StringBuffer(String.valueOf(String.valueOf((l - j) + 1)))).append("-").append(highScoreNames[l]))), byte0 + 1, y, 20);
            g.drawString(String.valueOf(String.valueOf(highScores[l])).concat(" s"), getWidth() - byte0 - 1, y, 24);
            y += 12;
        }

    }

    public void processNewScore(int i, Displayable displayable)
    {
        previousDisplayable = displayable;
        int j = minesMidlet.difficultyLevel * 4;
        int k = j + 4;
        int l = j;
        do
        {
            if(l >= k)
                break;
            if(i < highScores[l])
            {
                for(byte byte0 = (byte)(k - 1); byte0 > l; byte0--)
                {
                    highScores[byte0] = highScores[byte0 - 1];
                    highScoreNames[byte0] = highScoreNames[byte0 - 1];
                }

                newHighScoreIndex = l;
                highScores[l] = i;
                Form form = new Form("New HighScore!");
                userInputName = new TextField(String.valueOf(String.valueOf((new StringBuffer("No.")).append((l - j) + 1).append(" ").append(i).append(" secs"))), "", 10, 0);
                form.append(userInputName);
                form.addCommand(nameInputConfirmCommand);
                form.setCommandListener(this);
                Display.getDisplay(minesMidlet).setCurrent(form);
                break;
            }
            l++;
        } while(true);
    }

    public void displayHighScore(Displayable displayable)
    {
        previousDisplayable = displayable;
        Display.getDisplay(minesMidlet).setCurrent(this);
    }
}

⌨️ 快捷键说明

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