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

📄 rectangle.java

📁 坦克游戏
💻 JAVA
字号:
/*
 * Created on 2005-1-9
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package shape;

import java.awt.Point;

/**
 * @author AnSen
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class Rectangle extends MShape{
	public double x, y, width, height;

	public boolean isFill = false;

	public Rectangle(double x, double y, double width, double height, boolean isFill) {
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.isFill = isFill;
	}

	public void setLocation(double x, double y) {
		this.x = x;
		this.y = y;
	}

	public Point getPoint() {
		return new Point((int)Math.ceil(x + width / 2), 
				(int)Math.ceil(y + height / 2));
	}
	
	public void move(double dDirect,double dDistance){
		setLocation(x + Math.cos(dDirect) * dDistance, y
				+ Math.sin(dDirect) * dDistance);
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see shape.IShape#isSuperpose(int, int, int, int)
	 */
	public boolean isSuperpose(int left, int top, int width, int height) {

		return false;
	}
	
	/* (non-Javadoc)
	 * @see shape.IShape#isAcross(double, double, double, double)
	 */
	public boolean isAcross(double x1, double y1, double x2, double y2) {
		if (isLineAcross(x1, y1, x2, y2, x, y, x+width, y)) {
			return true;
		}
		if (isLineAcross(x1, y1, x2, y2, x, y,x, y+ height)) {
			return true;
		}
		if (isLineAcross(x1, y1, x2, y2, x + width, y, x + width, y + height)) {
			return true;
		}
		if (isLineAcross(x1, y1, x2, y2, x, y + height,	x + width, y + height)) {
			return true;
		}
		return false;
	}
	
	/* (non-Javadoc)
	 * @see shape.IShape#isConatin(shape.IShape)
	 */
	public boolean isConatin(IShape shape) {
		Rectangle rect=null;
		if(shape instanceof Polygon){
			Polygon pshp=(Polygon)shape;
			rect=pshp.getBoundBox();
		}else if(shape instanceof Rectangle){
			rect=(Rectangle)shape;
		}
		if(rect.x>x&&rect.y>y&&
				rect.width<width&&rect.height<height){
			return true;
		}else{
			return false;
		}
	}
	
	public Rectangle cloneShape(){
		return new Rectangle(x,y,width,height,false);
	}
	
}

⌨️ 快捷键说明

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