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

📄 gameboard.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.engine.board;

/**
 * The Game Board.
 * Contains the main Board and base Board.
 * @author erico
 */
public class GameBoard {
	private Board m_MainBoard;
	private Board m_BaseBoard;
	
	/**
	 * Constructor for GameBoard
	 * @param width the quantity of Block's in x axis
	 * @param height the quantity of Block's in y axis
	 */
	public GameBoard( int width, int height ) {
		m_MainBoard = new Board( width, height );
		m_BaseBoard = new Board( width, 1 ); //aways have one row
	}
	
	/**
	 * Get the GameBoard width
	 * @return the quantity of Block's in x axis
	 */
	public int getBoardWidth() {
		return m_MainBoard.getBoardWidth();
	}
	
	/**
	 * Get the GameBoard height
	 * @return the quantity of Block's in y axis
	 */
	public int getBoardHeight() {
		return m_MainBoard.getBoardHeight();
	}
	
	/**
	 * Set size of GameBoard
	 * @param width the quantity of Block's in x axis
	 * @param height the quantity of Block's in y axis
	 */
	public void setBoardSize( int width, int height ) {
		m_MainBoard.setBoardSize( width, height );
		m_BaseBoard.setBoardSize( width, 1 );
	}
	
	/**
	 * Get the main game Board
	 * @return the main game Board
	 */
	public Board getMainBoard() {
		return m_MainBoard;
	}

	/**
	 * Get the base Board that uses as buffer to store
	 * the Blocks as a buffer
	 * @return return base Board
	 */
	public Board getBaseBoard() {
		return m_BaseBoard;
	}
	
	/**
	 * Return true if base Board are full
	 * @return true if base Board are full
	 */
	public boolean isBaseBoardFull() {
		return !m_BaseBoard.isNullBlock( m_BaseBoard.getBoardWidth() - 1 , 0 );
	}
	
	/**
	 * Return true if base Board is empty
	 * @return true if base Board is empty
	 */
	public boolean isBaseBoardEmpty() {
		return m_BaseBoard.isNullBlock( 0 );
	}
	
	/**
	 * Return true if main Board are full, in other words, if
	 * last row contain one or more Block's
	 * @return true if main Board is full
	 */
	public boolean hasBlockOnTop() {
		return hasBlockOnRow( getBoardHeight() );
	}
	
	/**
	 * Test if has block on determined row. Rows can be counted down to up.
	 * @param row the row number
	 * @return true if has block on specified row
	 */
	public boolean hasBlockOnRow( int row ) {
		int end = row * getBoardWidth();
		for( int i = ( row - 1 ) * getBoardWidth(); i < end; i++ )
			if( m_MainBoard.getBlock( i ) != null )
				return true;
		
		return false;
	}
	
	/**
	 * Clear all GameBoard (base Board and main Board)<br>
	 * All objects in base Board and main Board will be removed from memory 
	 */
	public void clear() {
		m_BaseBoard.clear();
		m_MainBoard.clear();
	}
}

⌨️ 快捷键说明

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