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

📄 airportbuilder.java.svn-base

📁 這是一個JAVA語言寫的多代理人程式用來模擬飛機起飛或是降落的程式
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
			ArrayList<WorldVector> taxiwayVertices = new ArrayList<WorldVector>();			taxiwayVertices.add(new WorldVector((gateConnection.x - (taxiwayWidth / 2)) - taxiwayPosition.x, gateConnection.y - taxiwayPosition.y, 0));			taxiwayVertices.add(new WorldVector((gateConnection.x + (taxiwayWidth / 2)) - taxiwayPosition.x, gateConnection.y - taxiwayPosition.y, 0));			taxiwayVertices.add(new WorldVector((runwayConnection.x + (taxiwayWidth / 2)) - taxiwayPosition.x, runwayConnection.y - taxiwayPosition.y, 0));			taxiwayVertices.add(new WorldVector((runwayConnection.x - (taxiwayWidth / 2)) - taxiwayPosition.x, runwayConnection.y - taxiwayPosition.y, 0));						//add new taxiway to the list of builder objects			BuilderObject newTaxiway = new BuilderObject("Taxiway" + (numTaxiways + 1), new GuiObject("Taxiway"), new WorldObjectState(taxiwayPosition), taxiwayWidth, taxiwayHeight);						newTaxiway.getObjectState().connections.add(new WorldVector(gateConnection.x - taxiwayPosition.x, gateConnection.y - taxiwayPosition.y, 0));			newTaxiway.getObjectState().connections.add(new WorldVector(runwayConnection.x - taxiwayPosition.x, runwayConnection.y - taxiwayPosition.y, 0));						newTaxiway.setBGColor(taxiwayColor);			newTaxiway.setVertices(taxiwayVertices);						builderObjects.add(newTaxiway);			numTaxiways++;		}				airportBuilderAnimation.repaint();				madeTaxiways = true;				airportBuilderPanel.setButtonEnabled("makeTaxiways", false);		airportBuilderPanel.setButtonEnabled("addGate", false);		airportBuilderPanel.enableRunwayButtons(false);	}		public void buildAirport(boolean distributedMode) {		saveLayout();		setVisible(false);		new StartGuiNoRMI(builderObjects, userControlled, cdControlled, gcControlled, lcControlled);	}		public void saveLayout() {		String objectStr = "";		BuilderObject builderObject;		GuiObject guiObject;		WorldObjectState objectState;		WorldVector vertex, connection, position, angularVelocity, positionOffset;				//serialize each builder object		for(int i = 0; i < builderObjects.size(); i++) {			builderObject = builderObjects.get(i);			guiObject = ((GuiObject) builderObject.getGuiObject());			objectState = ((WorldObjectState) builderObject.getObjectState());						objectStr += guiObject.type + ":";			objectStr += builderObject.getName() + ":";						objectStr += builderObject.width + "," + builderObject.height + ":";						position = objectState.position;			objectStr += position.x + "," + position.y + "," + position.z + ":";						positionOffset = guiObject.positionOffset;			objectStr += positionOffset.x + "," + positionOffset.y + "," + positionOffset.z + ":";						angularVelocity = objectState.angularVelocity;			objectStr += angularVelocity.x + "," + angularVelocity.y + "," + angularVelocity.z + ":";						for(int j = 0; j < objectState.vertices.size(); j++) {				vertex = objectState.vertices.get(j);				objectStr += vertex.x + "," + vertex.y + "," + vertex.z;				if(j != objectState.vertices.size() - 1) {					objectStr += ";";				}			}						objectStr += ":";						if(objectState.connections.isEmpty()) {				objectStr += "null";			} else {				for(int j = 0; j < objectState.connections.size(); j++) {					connection = objectState.connections.get(j);					objectStr += connection.x + "," + connection.y + "," + connection.z;					if(j != objectState.connections.size() - 1) {						objectStr += ";";					}				}			}						objectStr += "\n";		}				try {	        BufferedWriter out = new BufferedWriter(new FileWriter("airportLayout.txt"));	        out.write(objectStr);	        out.close();	    } catch (Exception e) {	      System.out.println(e.getMessage());	    }	}		public boolean loadLayout() {		try {	    	BufferedReader in = new BufferedReader(new FileReader(new File("airportLayout.txt")));	    	builderObjects = new ArrayList<BuilderObject>();	    				while(in.ready()) {				  String thisLine = in.readLine();				  				  //get all the serialized parts in an array				  String[] guiObjectAttrs = thisLine.split(":");									  String type = guiObjectAttrs[0]; //type				  String name = guiObjectAttrs[1]; //name				  				  String[] widthHeightStrArr = guiObjectAttrs[3].split(","); //width and height				  double width = Double.parseDouble(widthHeightStrArr[0]), height = Double.parseDouble(widthHeightStrArr[1]);				  				  String[] positionStrArr = guiObjectAttrs[3].split(","); //position WorldVector				  WorldVector position = new WorldVector(Double.parseDouble(positionStrArr[0]), Double.parseDouble(positionStrArr[1]), Double.parseDouble(positionStrArr[2]));				  				  String[] positionOffsetStrArr = guiObjectAttrs[4].split(","); //positionOffset WorldVector				  WorldVector positionOffset = new WorldVector(Double.parseDouble(positionOffsetStrArr[0]), Double.parseDouble(positionOffsetStrArr[1]), Double.parseDouble(positionOffsetStrArr[2]));				  				  String[] angularVelocityStrArr = guiObjectAttrs[5].split(","); //angularVelocity WorldVector				  WorldVector angularVelocity = new WorldVector(Double.parseDouble(angularVelocityStrArr[0]), Double.parseDouble(angularVelocityStrArr[1]), Double.parseDouble(angularVelocityStrArr[2]));				  				  ArrayList<WorldVector> vertices = new ArrayList<WorldVector>();				  String[] verticesStrArr = guiObjectAttrs[6].split(";"); //vertices ArrayList				  String[] vertexStrArr;				  				  for(int i = 0; i < verticesStrArr.length; i++) {					  vertexStrArr = verticesStrArr[i].split(",");					  vertices.add(new WorldVector(Double.parseDouble(vertexStrArr[0]), Double.parseDouble(vertexStrArr[1]), Double.parseDouble(vertexStrArr[2])));				  }				  				  ArrayList<WorldVector> connections = new ArrayList<WorldVector>();				  if(guiObjectAttrs[7].intern() != "null") {					  String[] connectionsStrArr = guiObjectAttrs[7].split(";"); //connections ArrayList					  String[] connectionStrArr;				  					  for(int i = 0; i < connectionsStrArr.length; i++) {						  connectionStrArr = connectionsStrArr[i].split(",");						  connections.add(new WorldVector(Double.parseDouble(connectionStrArr[0]), Double.parseDouble(connectionStrArr[1]), Double.parseDouble(connectionStrArr[2])));					  }				  }				  				  WorldObjectState objectState = new WorldObjectState();				  objectState.position = position;				  objectState.vertices = vertices;				  objectState.connections = connections;				  				  //based on the type, create a new builder object with the approriate fields				  GuiObject guiObject = new GuiObject(type.intern());				  if(guiObject.type == "Tower") {					  guiObject.bgColor = airportBuilderAnimation.towerColor;				  } else if(guiObject.type == "Gate") {					  guiObject.bgColor = airportBuilderAnimation.gateColor;				  } else if(guiObject.type == "Taxiway") {					  guiObject.bgColor = taxiwayColor;				  } else if(guiObject.type == "Runway") {					  guiObject.setTexture(airportBuilderAnimation.runwayTexture);					  objectState.angularVelocity = angularVelocity;					  guiObject.positionOffset = positionOffset;				  }				  builderObjects.add(new BuilderObject(name, guiObject, objectState, width, height));			}	      			in.close();	    } catch (Exception e) {	    	System.out.println("Error!  " + e);	    	return false;	    }		buildAirport(false);	    return true;	}		public void actionPerformed(ActionEvent e) {		if(e.getSource() == airportBuilderPanel.getButton("addRunwayType1") || 				e.getSource() == airportBuilderPanel.getButton("addRunwayType2")) {			addingRunway((e.getSource() == airportBuilderPanel.getButton("addRunwayType1")) ? 0 : 15);		} else if(e.getSource() == airportBuilderPanel.getButton("addGate")) {			addingGate();		} else if(e.getSource() == airportBuilderPanel.getButton("addTower")) {			addingTower();		} else if(e.getSource() == airportBuilderPanel.getButton("makeTaxiways")) {			makeTaxiways();		} else if(e.getSource() == airportBuilderPanel.getButton("finish")) {			buildAirport(airportBuilderPanel.getDistributedMode());		}				if(numRunways != 0 && numGates != 0 && madeTaxiways && addedTower) {			airportBuilderPanel.setButtonEnabled("finish", true);		}	}	public void mouseClicked(MouseEvent e) {		// TODO Auto-generated method stub			}	public void mouseEntered(MouseEvent e) {		// TODO Auto-generated method stub			}	public void mouseExited(MouseEvent e) {		// TODO Auto-generated method stub			}	public void mousePressed(MouseEvent e) {		// TODO Auto-generated method stub			}	public void mouseReleased(MouseEvent e) {		// TODO Auto-generated method stub			}}

⌨️ 快捷键说明

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