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

📄 score.java

📁 J2me实现的MSN Messeger客户端程序。聊天、添加好友、删除好友、阻止好友
💻 JAVA
字号:
package vitular.ui;

/**
 *游戏得分排行榜类
 *@CopyRight:eshouji.com
 *@Author:ceze
 *@Version 1.0 2004/4/22
 */
public class Score {

  private int topX; //排行版中排行条数
  private RecordDB db = new RecordDB();
  private String dbName;
  private int baseValue = 0;

  public String[] playerName;
  public int[] playerScore;

  /**
   *构造函数,InitTopX为总的排名数,BaseValue为默认的排行分
   */
  public Score(String DBName, int InitTopX, int BaseValue) {
    dbName = DBName;
    db.open(DBName);
    baseValue = BaseValue;
    topX = db.getNumRecords();
    if (topX <= 0) {
      init(InitTopX);
    }
    fill();
    db.close();
  }

  //初使化记录库
  private void init(int t) {
    topX = t;
    for (int i = 1; i <= t; i++) {
      db.addRecord("第" + i +"名" + "$" + String.valueOf( (topX - i - 1) * baseValue));
    }
  }

  //将库中数据充满数组
  private void fill() {
    playerName = new String[topX];
    playerScore = new int[topX];
    String s = null;

    for (int i = 0; i < topX; i++) {
      s = db.getRecord(i + 1); //数据库中数据索引不是从0开始
      playerName[i] = db.getField(s, 1, "$");
      playerScore[i] = Integer.valueOf(db.getField(s, 2, "$")).intValue();
    }
  }

  /**
   * 得分Score是否在TopX内
   * Name 玩家名字
   */
  public boolean isHighScore(int Score) {
    for (int i = 0; i < topX; i++) {
      if (playerScore[i] < Score) {
        return true;
      }
    }
    return false;
  }

  /**
   * 更新保存得分
   * 进入排行板, 返回true
   */
  public boolean update(String Name, int Score) {
    boolean setscore = false;

    for (int i = 0; i < topX && !setscore; i++) {
      if (playerScore[i] < Score) {
        for (int j = topX - 1; j > i; j--) {
          playerName[j] = playerName[j - 1];
          playerScore[j] = playerScore[j - 1];
        }
        playerName[i] = Name;
        playerScore[i] = Score;
        setscore = true;
      }
    }

    //保存
    db.open(dbName);
    for (int i = 0; i < topX; i++) {
      db.setRecord(i + 1, playerName[i] + "$" + playerScore[i]);
    }
    db.close();
    return setscore;
  }

  /**
   * 插入并保存成绩,使用默认玩家名
   * @param Score int
   */
  public boolean update(int Score){
    boolean setscore = false;

    for (int i = 0; i < topX && !setscore; i++) {
      if (playerScore[i] < Score) {
        for (int j = topX - 1; j > i; j--) {
          playerScore[j] = playerScore[j - 1];
        }
        playerScore[i] = Score;
        setscore = true;
      }
    }

    //保存
    db.open(dbName);
    for (int i = 0; i < topX; i++) {
      db.setRecord(i + 1, playerName[i] + "$" + playerScore[i]);
    }
    db.close();
    return setscore;
  }

  /**
   * 得到当前得分的排行人次
   */
  public int getTopX() {
    return topX;
  }

  /**
   * 得到当前的最高分
   * jj 2004.5.5补充
   */
  public int getHighScore(){
    try{
      return this.playerScore[0];
    }
    catch(Exception e){
      return 0;
    }

  }

}

⌨️ 快捷键说明

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