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

📄 blockfactory.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.blocks;

import java.awt.Color;

import sourceforge.net.projects.jcollapse.engine.block.Block;
import sourceforge.net.projects.jcollapse.game.components.DLHelper;

public class BlockFactory {
	/**
	 * @author erico
	 * You must specify the class names of Block's here
	 */
	public static enum BLOCK_CLASS_NAME { ColorBlock, ImageBlock, BombColorBlock, BombImageBlock };
	
	/**
	 * Create Block's objects by name. <br>
	 * Available names are: <br>
	 * ColorBlock, SolidColorBlock
	 * @param className the name of class
	 * @param blockName the Block name 
	 * @param parameter1 the first parameter for Block. Each Block type can use it for diferent porpouse
	 * @param parameter2 the second parameter for Block. Each Block type can use it for diferent porpouse
	 * @return the created Block object
	 */
	public static Block createBlock( String className, String blockName, String parameter1, String parameter2 ) {
		//ColorBlock
		//-----------------------------------------------------------------------------------------
		if( className.compareToIgnoreCase( BLOCK_CLASS_NAME.ColorBlock.name() ) == 0 ) 
		{
			Color color = new Color(
					Integer.parseInt( parameter2.substring( 0, 3 ) ),
					Integer.parseInt( parameter2.substring( 4, 7 ) ),
					Integer.parseInt( parameter2.substring( 8, 11 ) ) );
			return new ColorBlock( blockName, true, Integer.parseInt( parameter1 ), color );
		}
		
		//ImageBlock
		//-----------------------------------------------------------------------------------------
		else if( className.compareToIgnoreCase( BLOCK_CLASS_NAME.ImageBlock.name() ) == 0 )
		{
			return new ImageBlock( blockName,
								   true,
								   Integer.parseInt( parameter1 ),
								   DLHelper.getInstance().getImage( parameter2 )
								 );
		}
		
		//BOMB_COLOR_BLOCK
		//-----------------------------------------------------------------------------------------
		else if( className.compareToIgnoreCase( BLOCK_CLASS_NAME.BombColorBlock.name() ) == 0 )
		{
			Color color = new Color(
					Integer.parseInt( parameter2.substring( 0, 3 ) ),
					Integer.parseInt( parameter2.substring( 4, 7 ) ),
					Integer.parseInt( parameter2.substring( 8, 11 ) ) );
			return new BombColorBlock( blockName, true, parameter1, color );
		}
		
		//BOMB_IMAGE_BLOCK
		//-----------------------------------------------------------------------------------------
		else if( className.compareToIgnoreCase( BLOCK_CLASS_NAME.BombImageBlock.name() ) == 0 )
		{
			return new BombImageBlock( blockName,
					   true,
					   parameter1,
					   DLHelper.getInstance().getImage( parameter2 )
					 );
		}
		
		//else (Other unknown Block's)
		//-----------------------------------------------------------------------------------------
		System.out.println( "Unknown Block name: " + className );
		return null;
	}
}

⌨️ 快捷键说明

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