mapelement.java

来自「a java game code for java」· Java 代码 · 共 53 行

JAVA
53
字号

/**
 * Title:        吃豆子<p>
 * Description:  小游戏<p>
 * Copyright:    Copyright (c) Nothing<p>
 * Company:      Raindrop<p>
 * @author Nothing
 * @version 1.0
 */
package eatbean;

import eatbean.util.*;
//
import java.awt.Image;
import java.util.Hashtable;

public abstract class MapElement {
	protected static final int ELEMENT_MAX_SIZE = 16;
	protected static final int ELEMENT_MIN_SIZE = 16;
	protected int x, y;
	protected int style;
	protected int width, height;
	public MapElement(int style, int x, int y) {
		this.style = style;
		this.x = x;
		this.y = y;
		parseWidthAndHeight();
	}
	abstract public void parseWidthAndHeight();
	//public int getX() { return x; }
	//public int getY() { return y; }
	public int getWidth() { return width; }
	public int getHeight() { return height; }
	//protected int getOffsetX() { return (ELEMENT_MAX_SIZE-width)/2; }
	//protected int getOffsetY() { return (ELEMENT_MAX_SIZE-height)/2; }
	public int getTop() { return y; }
	public int getLeft() { return x; }
	public int getRight() { return x+width; }
	public int getBottom() { return y+height; }
	/** 此对象的位置描述方式有待改进 */
	public Rect getRect() { return new Rect(x, y, width, height); }	//有待改进
	protected Image getImage(Hashtable imgBuffTable, Hashtable styleTable, int imgIndex) {
		Integer key = new Integer(imgIndex);
		Image result = (Image)imgBuffTable.get(key);
		if(result == null) {
			String fileName = styleTable.get(key).toString();
			result = ImageTool.getMapImage(fileName);
			if(result != null) imgBuffTable.put(key, result);
		}
		return result;
	}
	abstract public void draw(OffScreen offScreen);
}

⌨️ 快捷键说明

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