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

📄 animation.java.svn-base

📁 這是一個JAVA語言寫的多代理人程式用來模擬飛機起飛或是降落的程式
💻 SVN-BASE
字号:
package gui;import java.awt.*;import java.awt.geom.*;import java.awt.image.*;import java.util.ArrayList;import java.util.List;import javax.swing.*;import base.*;import interfaces.*;import gui.*;public class Animation implements AnimationInterface {	public static Graphics g;	public static JFrame frame;	private double originalZ;	private BufferedImage originalTexture;	private boolean firstScale = false;	private StatusGUI refStatusPane;	private MessageGUI refMessagePane;		public Animation() {			}		public Animation(MessageGUI refMessagePane, StatusGUI refStatusPane, String name) {		this.refMessagePane = refMessagePane;		this.refStatusPane = refStatusPane;		this.refMessagePane.addAgent(name);		this.refStatusPane.addAgent(name);	}		public Animation(MessageGUI refMessagePane, String name) {		this.refMessagePane = refMessagePane;		this.refMessagePane.addAgent(name);	}		public static void setGraphics(Graphics g) {		Animation.g = g;	}		public void clear() {		g.clearRect(0, 0, frame.getWidth(), frame.getHeight());	}	public void drawWorld(List<WorldObject> objects) {		clear();				//filter all the passed in objects based on their types		List<WorldObject> runways = new ArrayList<WorldObject>(),						  gates = new ArrayList<WorldObject>(),		  				  towers = new ArrayList<WorldObject>(),		  				  taxiways = new ArrayList<WorldObject>(),		  				  planes = new ArrayList<WorldObject>();				for(WorldObject o : objects) {			GuiObject guiObject = (GuiObject) o.getGuiObject();			if(guiObject != null) {				String type = guiObject.type;				if(type == "Plane") {					planes.add(o);				} else if(type == "Runway") {					runways.add(o);				} else if(type == "Gate") {					gates.add(o);				} else if(type == "Tower") {					towers.add(o);				} else if(type == "Taxiway") {					taxiways.add(o);				}			}		}				//draw objects in the order they should be drawn, z-index goes from smallest to largest		drawObjects(taxiways);		drawObjects(runways);		drawObjects(gates);		drawObjects(towers);		drawObjects(planes);	}	public void drawBuilderObjects(List<BuilderObject> objects) {		for(BuilderObject o : objects) {			drawObject(o);		}	}		public void drawObjects(List<WorldObject> objects) {		for(WorldObject o : objects) {			drawObject(o);		}	}		public void drawObject(WorldObject object) {		WorldObjectState objectState = object.getObjectState();		GuiObject guiObject = (GuiObject) object.getGuiObject();				if(guiObject != null) {			if(guiObject.bgColor != null) {				g.setColor(guiObject.bgColor);			}				ArrayList<WorldVector> vertices = (ArrayList<WorldVector>) (objectState.vertices);						Point p0 = new Point();						//if the gui object has a texture, update it then draw it			//otherwise draw the polygon			if(guiObject.texture != null) {				p0.x = (int) ((objectState.position.x - guiObject.positionOffset.x) + vertices.get(0).x);				p0.y = (int) ((objectState.position.y - guiObject.positionOffset.y) + vertices.get(0).y);								Graphics2D g2d = (Graphics2D) g;				AffineTransform origXform = g2d.getTransform();				guiObject.newXform = (AffineTransform) origXform.clone();								guiObject.updateTexture(object);								g2d.setTransform(guiObject.newXform);				g2d.drawImage(guiObject.texture, (int) object.objectState.position.x - (guiObject.texture.getWidth() / 2), (int) object.objectState.position.y - (guiObject.texture.getHeight() / 2), frame);				g2d.setTransform(origXform);				//g.drawImage(guiObject.texture, p0.x, p0.y, null);			} else if(!vertices.isEmpty()){				int[] x = new int[vertices.size()];				int[] y = new int[vertices.size()];							for(int i = 0; i < vertices.size(); i++) {					x[i] = (int) (objectState.position.x + vertices.get(i).x);					y[i] = (int) (objectState.position.y + vertices.get(i).y);				}				g.fillPolygon(x, y, vertices.size());								if(guiObject.type != "Taxiway") {					p0.x = x[0];					p0.y = y[0];				} else {					p0.x = (int) objectState.position.x;					p0.y = (int) objectState.position.y;				}			}						//print the name on screen for the user			g.setColor(Color.WHITE);			g.drawString(object.getName(), p0.x + 5, p0.y + 15);		}	}	public void logMessage(String from, String to, String message) {		if(refMessagePane != null) {			refMessagePane.logMessage(from, to, message);		}	}	public void updateStatus(String from, String message) {		//if(refStatusPane != null) {		//	refStatusPane.updateStatus(from, message);			//}	}}

⌨️ 快捷键说明

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