Android Open Source - ZorbsCity Simulator






From Project

Back to project page ZorbsCity.

License

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.

Java Source Code

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);
  }
}




Java Source Code List

jonathan.geoffroy.zorbscity.MainActivity.java
jonathan.geoffroy.zorbscity.Main.java
jonathan.geoffroy.zorbscity.ZorbCityGame.java
jonathan.geoffroy.zorbscity.client.GwtLauncher.java
jonathan.geoffroy.zorbscity.model.City.java
jonathan.geoffroy.zorbscity.model.Galaxy.java
jonathan.geoffroy.zorbscity.model.SimulatorEvent.java
jonathan.geoffroy.zorbscity.model.Simulator.java
jonathan.geoffroy.zorbscity.model.TimeLine.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.Building.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.Construction.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.Enterprise.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.House.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.Road.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.Storage.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.Structure.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.enterprises.ClothesFactory.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.enterprises.PowerHouse.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.houses.FreeHouse.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.houses.SimpleHouse.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.houses.TentHouse.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.storages.FoodStorage.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.storages.SecondaryStorage.java
jonathan.geoffroy.zorbscity.model.cityObjects.people.DeliveryMan.java
jonathan.geoffroy.zorbscity.model.cityObjects.people.Person.java
jonathan.geoffroy.zorbscity.model.cityObjects.resources.Cloth.java
jonathan.geoffroy.zorbscity.model.cityObjects.resources.Power.java
jonathan.geoffroy.zorbscity.model.cityObjects.resources.Resource.java
jonathan.geoffroy.zorbscity.model.cityObjects.resources.Wheat.java
jonathan.geoffroy.zorbscity.model.cityObjects.resources.Wool.java
jonathan.geoffroy.zorbscity.model.helpers.Coord2D.java
jonathan.geoffroy.zorbscity.model.helpers.NeededList.java
jonathan.geoffroy.zorbscity.model.helpers.ResourcesList.java
jonathan.geoffroy.zorbscity.model.simulator.events.ConsumeNeededResources.java
jonathan.geoffroy.zorbscity.model.simulator.events.ObjectCreatedEvent.java
jonathan.geoffroy.zorbscity.model.simulator.events.WeaknessEvent.java
jonathan.geoffroy.zorbscity.view.CityView.java
jonathan.geoffroy.zorbscity.view.shell.CityShellView.java