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

📄 componentsmanager.java

📁 Java版拼图游戏
💻 JAVA
字号:
/*
 * @(#)ComponentManager.java 1.0 03/08/21
 * Copyright 2003 Entao Zhang, All rights reserved.
 */

import java.awt.Component;

/**
 * mainPane管理抽象类
 */
public abstract class ComponentsManager {
	protected AbstractUnitPane ir;
	//事件处理类.
	protected ComponentsEventListener el;
	//打乱算法类.
	protected ConfuseArray confuse;
	
	public ComponentsManager(AbstractUnitPane ir){
		this.ir=ir;
	}
	
	//生成mainPane.
	public abstract Component buildMainPanel();
	
	//如需要可重载本方法
	public void beConfused(){
	}
	
	//组件在游戏运行状态和非运行状态的转换.
	public abstract void componentStateChange(int where);
	
	//组件在游戏运行状态和非运行状态的更新转换(全部).
	public void componentsStateChange(){
		for (int i=0; i<ir.gridLength; i++){
			componentStateChange(i);
		}
	}
	
	//当前处理组件的状态更新方法.
	public abstract void swapStateChange(boolean state);
	
	public void setEventListener(ComponentsEventListener el){
		this.el=el;
	}
	
	public void setConfuse(ConfuseArray confuse){
		this.confuse=confuse;
	}
	
	public int runConfuse(int[] buttonN, int x, int y){
		if (confuse==null){
			return ConfuseArray.confuseError;
		}
		return confuse.runConfuse(buttonN,x,y);
	}
	
	//测试一个grid周围的8个grids的有效可访问性.即是否超出边界.
	public boolean[] checkAround(int loc){
		boolean around[]={true,true,true,true,true,true,true,true};
		int locX=loc%ir.x, locY=loc/ir.x;
		if (locY == 0){
			around[0]=false;
			around[1]=false;
			around[2]=false;
		}
		if (locY == ir.y-1){
			around[5]=false;
			around[6]=false;
			around[7]=false;
		}
		if (locX == 0){
			around[0]=false;
			around[3]=false;
			around[5]=false;
		}
		if (locX == ir.x-1){
			around[2]=false;
			around[4]=false;
			around[7]=false;
		}
		return around;
	}
}

⌨️ 快捷键说明

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