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

📄 score.java

📁 J2ME手机版游戏——配对赛源代码
💻 JAVA
字号:
/**
*游戏得分排行榜类
*@CopyRight:Move2008
*@Author:bedlang
*@Version 1.0 2003/7/22
*/
//Download by http://www.codefans.net
package move.game;

import move.util.RecordDB;

public class Score {

	int topX;
	RecordDB db = new RecordDB();
	String dbName;

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

	
	public Score(String DBName, int InitTopX)
	{
		dbName = DBName;
		db.open(DBName);
		topX = db.getNumRecord();
		if (topX<=0) init(InitTopX);
		fill();
		db.close();
	}
	
	//初使化记录库
	private void init(int t)
	{
		topX = t;
		for(int i=0;i<t;i++)
			db.addRecord("无名"+String.valueOf((5-i)*1000));
	}
	
	//将库中数据充满数组
	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);
			playerName[i] = db.getField(s,1,"");
			playerScore[i] = Integer.valueOf(db.getField(s,2,"")).intValue();
		}			
	}	

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

	/*
	 * 插入并保存得分
	 */
	public void insert(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();
	}
	
	/*
	 * 得到排行人次
	 */
	public int getTopX()
	{
		return topX;
	}

}

⌨️ 快捷键说明

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