📄 bombcolorblock.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 java.awt.GradientPaint;import java.awt.Graphics2D;import java.awt.image.BufferedImage;import sourceforge.net.projects.jcollapse.engine.block.BombBlock;/** * @author erico * */public class BombColorBlock extends BombBlock implements DisplayableGraphic { private boolean m_Composite; private Color m_Color; private BufferedImage m_BufferedImage; public BombColorBlock( String name, boolean enable, String nameOfBlockToDestroy, Color color ) { this( name, enable, nameOfBlockToDestroy, color, true ); } public BombColorBlock( String name, boolean enable, String nameOfBlockToDestroy, Color color, boolean composite ) { super( name, enable, nameOfBlockToDestroy ); setComposite( composite ); setColor( color ); } /** * This Block can have gradient fill to display a beautiful image (slow) or * plan color image (fast) * @return true if component have gradient fill. Plan image, return false */ public boolean isComposite() { return m_Composite; } /** * This Block can have gradient fill to display a beautiful image (slow) or * plan color image (fast) * @param composite set true if you plan to use gradient fill * To use plan image, set false */ public void setComposite( boolean composite ) { m_Composite = composite; if( composite ) setColor( getColor() ); else m_BufferedImage = null; } /** * Set the Color of this Block * @param color the Color for this object */ public void setColor( Color color ) { if( color == null || ( getColor() != null && getColor().equals( color ) ) ) { return; } m_Color = color; //if composite is true if( isComposite() ) { Graphics2D g; m_BufferedImage = new BufferedImage( 32, 32, BufferedImage.TYPE_4BYTE_ABGR_PRE ); g = (Graphics2D)m_BufferedImage.getGraphics(); g.setPaint( new GradientPaint( 1, 1, getColor().brighter(), 30, 30, getColor().darker() ) ); g.fillRect( 7, 12, 18, 20 ); g.setColor( Color.BLACK ); g.drawLine( 17, 12, 17, 4 ); g.setColor( Color.GRAY ); g.drawLine( 15, 12, 15, 4 ); g.setColor( Color.YELLOW ); g.drawLine( 13, 2, 18, 6 ); g.drawLine( 13, 6, 18, 2 ); } } /** * Get the Color for this Block * @return the color for this Block */ public Color getColor() { return m_Color; } /* (non-Javadoc) * @see sourceforge.net.projects.jcollapse.game.blocks.PrintableBlock#drawBlock(java.awt.Graphics, int, int, int, int) */ public void drawBlock(Graphics2D graphics, int x, int y, int width, int height) { if( isComposite() ) { graphics.drawImage( m_BufferedImage, x, y, width, height, null ); } else { graphics.setColor( getColor() ); graphics.fillRect( x+5, y+12, 14, 15 ); graphics.setColor( Color.BLACK ); graphics.drawLine( x+13, y+12, x+13, y+4 ); graphics.setColor( Color.GRAY ); graphics.drawLine( x+11, y+12, x+11, y+4 ); graphics.setColor( Color.YELLOW ); graphics.drawLine( x+9, y+2, x+14, y+6 ); graphics.drawLine( x+9, y+6, x+14, y+2 ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -