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

📄 myarray.java

📁 Java编写的俄罗斯方块游戏 Java编写的俄罗斯方块游戏
💻 JAVA
字号:
package game;

public class MyArray implements java.io.Serializable
{
	public Score[] array;
	public int size;
	public final int MAX_LENGTH = 10;
	
	public MyArray()
	{
		array = new Score[MAX_LENGTH];
		size = 0;
	}
	
	public void add(Score score)
	{
		if(isEmpty())
		{
			array[0] = score;
			size++;
			return;
		}
		
		if(isFull())
		{
			if(array[MAX_LENGTH - 1].compareTo(score) < 0)
			{
				array[MAX_LENGTH - 1] = score;
				sort();
				return;
			}
			
		}
		
		array[size] = score;
		size++;
		sort();
	}
	
	private void sort()
	{
		int index = size - 1;
		int leftIndex = index - 1;
		Score temp = array[index];
		while(leftIndex >= 0 && array[leftIndex].compareTo(temp) < 0)
		{
			array[index] = array[leftIndex];
			index = leftIndex;
			leftIndex = index - 1;
		}
		
		array[index] = temp;
	}
	
	public Score getTair()
	{
		Score score = null;
		if(!isEmpty())
		{
			score = array[size - 1];
		}
		
		return score;
	}
	
	public boolean isEmpty()
	{
		return size == 0;
	}
	
	public boolean isFull()
	{
		return size == MAX_LENGTH;
	}
	
	public String toString()
	{
		StringBuffer buffer = new StringBuffer();
		for(int i = 0; i < size; i++)
		{
			buffer.append((i + 1) + "  " + array[i].name + "  " + array[i].score + "\n");
		}
		
		return buffer.toString();
	}
}

⌨️ 快捷键说明

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