Back to project page ZorbsCity.
The source code is released under:
GNU General Public License
If you think the Android project ZorbsCity listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package jonathan.geoffroy.zorbscity.model; //w w w.j a va 2s . c om import jonathan.geoffroy.zorbscity.model.cityObjects.buildings.Construction; import jonathan.geoffroy.zorbscity.model.cityObjects.buildings.House; import jonathan.geoffroy.zorbscity.model.cityObjects.buildings.Structure; import jonathan.geoffroy.zorbscity.model.cityObjects.people.Person; import jonathan.geoffroy.zorbscity.model.helpers.Coord2D; /** * The simulator of a City * Just call nextStep() when you want to run the next step of simulation * A step is defined by run simulationAct() for each Building & each Person of the city * @author Jonathan GEOFFROY * @version 0.1 */ public class Simulator { /** * The city which the Simulator is using for the next step */ private City city; private TimeLine timeLine; public Simulator(City city) { super(); assert(city != null) : "The city of the simulator shouldn't be null!"; this.city = city; timeLine = new TimeLine(); } /** * Run the next step of the simulation * delegates method for timeline.nextStep() */ public void nextStep() { timeLine.nextStep(this); } /** * add the structure s into the City, at coords coordinates. * delegate method for city.add(Structure, Coord2D) * @param s the structure to add * @param coords the coordinates of the new structure s */ public void add(Structure s, Coord2D coords) { city.add(s, coords); } public void add(Construction c, Coord2D coords) { city.add(c, coords); c.onAddedIntoCity(this); } /** * Add the person into the City, on the Road * So compute the person coordinates by using person.getFrom() Building * @param person the person to add */ public void add(Person person) { city.add(person); // TODO: compute the person coordinates by using person.getFrom() Building } /** * Remove the structure into the City, at coords coordinates * Delegate method for city.rm(Coord2D) * @param coord2d * @return true if there is anything removed */ public boolean rm(Coord2D coords) { return city.rm(coords, false); } /** * Destroy a construction & remove it from list of city's constructions * also replace all terrain of building mapping by a destroyed terrain * should be used when user want to remove a structure. If removing is due to simulation (example: Weakness), use destroy method * @param construction the construction to remove */ public void rm(Construction construction) { city.rm(construction.getCoords(), false); timeLine.removeEventsFrom(construction); } /** * Destroy the construction * Same as rm, but the construction is replaced by DESTROYED_MAPPING in the map * should be called when the construction is removed due to the simulation (example: Weakness, War ...) * @param construction */ public void destroy(Construction construction) { city.rm(construction.getCoords(), true); timeLine.removeEventsFrom(construction); } /** * Add a person from the building from * @param from the building where the new Person is coming */ public void createPerson(Construction from) { // TODO Auto-generated method stub } /** * Change a House to another House * @param previousHouse * @param nextHouse */ public void transform(House previousHouse, House nextHouse) { rm(previousHouse); add(nextHouse, previousHouse.getCoords()); } public TimeLine getTimeLine() { return timeLine; } public void addInhabitants(int number) { // TODO count the number of inhabitants } /** * Add <numberPeople> people into <b> * delegate method for <b>.addPeople(<numPeople>) * @param b * @param numberPeople */ public void addPeopleInto(Construction c, int numberPeople) { c.addPeople(this, numberPeople); } }