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

📄 levellist.java

📁 非常好的java collapse游戏代码
💻 JAVA
字号:
/*
 * JCollapse - Java Collapse Game
 * Copyright (C) 2005 Erico Gon鏰lves Rimoli
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package sourceforge.net.projects.jcollapse.game.levels;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;

import sourceforge.net.projects.jcollapse.game.components.DLHelper;

/**
 * This class store an array of Level's that can be used by LevelFactory to
 * build new Level's
 * @author erico
 *
 */
public class LevelList {
	private ArrayList<URL> m_LevelList;
	
	private static final String CP_URL = "CPURL:";
	private static final String ABS_URL = "ABSURL:";
	
	/**
	 * Constructor Load a level list into memory, but don't load the level data
	 * @param levelListLocation the location for level list
	 */
	public LevelList( URL levelListLocation ) {
		initializeComponents();
		
		if( levelListLocation != null )
			loadLevelList( levelListLocation );
	}
	
	/**
	 * Default constructor
	 */
	public LevelList() {
		this( null );
	}
	
	private void initializeComponents() {
		m_LevelList = new ArrayList<URL>(15);
	}

	/** 
	 * Load a list of levels
	 * @param levelListLocation the URL containing a list of levels
	 * @throws LevelException fired when any error occurs loading level list
	 */
	private void loadLevelList( URL levelListLocation ) throws LevelException {
		BufferedReader br = null;
		String line;
		
		clear();
		
		try {
			br = new BufferedReader( new InputStreamReader( levelListLocation.openStream() ) );
			
			
			while( br.ready() ) {
				line = br.readLine();
				
				if( line.startsWith( "#" ) )
					continue;

				//CLASSPATH URL
				if( line.startsWith( CP_URL ) )
					m_LevelList.add( DLHelper.getInstance().getURL( line.substring( CP_URL.length() ) ) );
				//ABSOLUTE URL
				else if( line.startsWith( ABS_URL ) )
					m_LevelList.add( new URL( line.substring( ABS_URL.length() ) ) );
				else
					continue;
				
			}//while
		} catch( IOException ex1 ) {
			throw new LevelException( "Error loading level list: " + ex1.getMessage(), ex1 );
		} finally {
			if( br != null )
				try {
					br.close();
				}catch( IOException ex1 ){}
		}
	}
	
	/**
	 * Get Level from index
	 * @param index the index of level
	 * @return the Level object
	 */
	public Level getLevel( int index ) {
		return LevelFactory.loadLevel( m_LevelList.get( index ), true );
	}
	
	/**
	 * Quantity of load levels
	 * @return quantity of load levels
	 */
	public int size() {
		return m_LevelList.size();
	}
	
	/**
	 * Clear the list of levels 
	 */
	public void clear() {
		m_LevelList.clear();
	}
}

⌨️ 快捷键说明

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