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

📄 ranking.java

📁 Bamboo Dance, game for mobile device It containt only source code, not any document related.
💻 JAVA
字号:
import java.io.*;
import javax.microedition.rms.*;

public class Ranking {

  public Ranking() {
    r3 = null;
    r5 = null;
    enum = null;
    try {
      r1 = RecordStore.openRecordStore("ranking", true);
      r2 = RecordStore.openRecordStore("ranking2", true);
      r3 = RecordStore.openRecordStore("ranking3", true);
      r4 = RecordStore.openRecordStore("sound", true);
      r5 = RecordStore.openRecordStore("state", true);
      enum = r1.enumerateRecords(null, null, true);
      if (!enum.hasNextElement()) {
        setup();
      }
    } catch (Exception exception) {}
  }

  public void saveData() {
    try {
      r1.closeRecordStore();
      r2.closeRecordStore();
      r3.closeRecordStore();
      r1 = RecordStore.openRecordStore("ranking", true);
      r2 = RecordStore.openRecordStore("ranking2", true);
      r3 = RecordStore.openRecordStore("ranking3", true);
    } catch (Exception exception) {}
  }

  private void setup() {
    try {
      for (int i = 0; i < 5; i++) {
        ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
        DataOutputStream dataoutputstream = new DataOutputStream(
            bytearrayoutputstream);
        dataoutputstream.writeUTF("AAA");
        byte abyte0[] = bytearrayoutputstream.toByteArray();
        r1.addRecord(abyte0, 0, abyte0.length);
        bytearrayoutputstream.close();
        dataoutputstream.flush();
      }

      for (int j = 0; j < 5; j++) {
        ByteArrayOutputStream bytearrayoutputstream1 = new
            ByteArrayOutputStream();
        DataOutputStream dataoutputstream1 = new DataOutputStream(
            bytearrayoutputstream1);
        dataoutputstream1.writeUTF("0");
        byte abyte1[] = bytearrayoutputstream1.toByteArray();
        r2.addRecord(abyte1, 0, abyte1.length);
        r3.addRecord(abyte1, 0, abyte1.length);
        if (j < 2) {
          r5.addRecord(abyte1, 0, abyte1.length);
        }
        bytearrayoutputstream1.close();
        dataoutputstream1.flush();
      }

      ByteArrayOutputStream bytearrayoutputstream2 = new ByteArrayOutputStream();
      DataOutputStream dataoutputstream2 = new DataOutputStream(
          bytearrayoutputstream2);
      dataoutputstream2.writeUTF("0");
      byte abyte2[] = bytearrayoutputstream2.toByteArray();
      r4.addRecord(abyte2, 0, abyte2.length);
      bytearrayoutputstream2.close();
      dataoutputstream2.flush();
    } catch (Exception exception) {
      System.out.println("ranking exception:" + exception);
    }
  }

  public int[] getLevel() {
    int ai[] = {
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    try {
      for (int i = 0; i < 5; i++) {
        ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(r3.
            getRecord(i + 1));
        DataInputStream datainputstream = new DataInputStream(
            bytearrayinputstream);
        ai[i] = Integer.parseInt(datainputstream.readUTF());
      }

    } catch (Exception exception) {}
    return ai;
  }

  public int[] getScore() {
    int ai[] = {
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    try {
      for (int i = 0; i < 5; i++) {
        ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(r2.
            getRecord(i + 1));
        DataInputStream datainputstream = new DataInputStream(
            bytearrayinputstream);
        ai[i] = Integer.parseInt(datainputstream.readUTF());
      }

    } catch (Exception exception) {}
    return ai;
  }

  public void saveState(int i, int j) {
    int ai[] = {
        i, j
    };
    try {
      r5 = RecordStore.openRecordStore("state", true);
      for (int k = 0; k < 2; k++) {
        ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
        DataOutputStream dataoutputstream = new DataOutputStream(
            bytearrayoutputstream);
        dataoutputstream.writeUTF("" + ai[k]);
        byte abyte0[] = bytearrayoutputstream.toByteArray();
        r5.setRecord(1 + k, abyte0, 0, abyte0.length);
        bytearrayoutputstream.close();
        dataoutputstream.flush();
      }

      r5.closeRecordStore();
    } catch (Exception exception) {}
  }

  public int[] getState() {
    int ai[] = {
        0, 0
    };
    for (int i = 0; i < 2; i++) {
      try {
        ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(r5.
            getRecord(1 + i));
        DataInputStream datainputstream = new DataInputStream(
            bytearrayinputstream);
        ai[i] = Integer.parseInt(datainputstream.readUTF());
      } catch (Exception exception) {}
    }

    return ai;
  }

  public int getSound() {
    int i = 1;
    try {
      ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(r4.
          getRecord(1));
      DataInputStream datainputstream = new DataInputStream(
          bytearrayinputstream);
      i = Integer.parseInt(datainputstream.readUTF());
    } catch (Exception exception) {}
    return i;
  }

  public String[] getName() {
    String as[] = new String[10];
    try {
      for (int i = 0; i < 5; i++) {
        ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(r1.
            getRecord(i + 1));
        DataInputStream datainputstream = new DataInputStream(
            bytearrayinputstream);
        as[i] = datainputstream.readUTF();
      }

    } catch (Exception exception) {}
    return as;
  }

  public void saveSound(int i) {
    try {
      r4.closeRecordStore();
      r4 = RecordStore.openRecordStore("sound", true);
      ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
      DataOutputStream dataoutputstream = new DataOutputStream(
          bytearrayoutputstream);
      dataoutputstream.writeUTF("" + i);
      byte abyte0[] = bytearrayoutputstream.toByteArray();
      r4.setRecord(1, abyte0, 0, abyte0.length);
      bytearrayoutputstream.close();
      dataoutputstream.flush();
      r4.closeRecordStore();
    } catch (Exception exception) {}
  }

  public void save(int ai[], String as[], int ai1[], int i) {
    try {
      for (int j = 0; j < 5; j++) {
        ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
        DataOutputStream dataoutputstream = new DataOutputStream(
            bytearrayoutputstream);
        dataoutputstream.writeUTF(as[j]);
        byte abyte0[] = bytearrayoutputstream.toByteArray();
        r1.setRecord(1 + j, abyte0, 0, abyte0.length);
        bytearrayoutputstream.close();
        dataoutputstream.flush();
      }

      for (int k = 0; k < 5; k++) {
        ByteArrayOutputStream bytearrayoutputstream1 = new
            ByteArrayOutputStream();
        DataOutputStream dataoutputstream1 = new DataOutputStream(
            bytearrayoutputstream1);
        dataoutputstream1.writeUTF("" + ai[k]);
        byte abyte1[] = bytearrayoutputstream1.toByteArray();
        r2.setRecord(1 + k, abyte1, 0, abyte1.length);
        bytearrayoutputstream1.close();
        dataoutputstream1.flush();
      }

      for (int l = 0; l < 5; l++) {
        ByteArrayOutputStream bytearrayoutputstream2 = new
            ByteArrayOutputStream();
        DataOutputStream dataoutputstream2 = new DataOutputStream(
            bytearrayoutputstream2);
        dataoutputstream2.writeUTF("" + ai1[l]);
        byte abyte2[] = bytearrayoutputstream2.toByteArray();
        r3.setRecord(1 + l, abyte2, 0, abyte2.length);
        bytearrayoutputstream2.close();
        dataoutputstream2.flush();
      }

      saveSound(i);
    } catch (Exception exception) {}
  }

  public void exit() {
    try {
      r1.closeRecordStore();
      r2.closeRecordStore();
      r3.closeRecordStore();
    } catch (Exception exception) {}
  }

  private RecordStore r1;
  private RecordStore r2;
  private RecordStore r3;
  private RecordStore r4;
  private RecordStore r5;
  RecordEnumeration enum;
}

⌨️ 快捷键说明

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