Android Open Source - ZorbsCity Time Line






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;
//from w ww.  j  av a 2s .c  om
import java.util.LinkedList;

import jonathan.geoffroy.zorbscity.model.cityObjects.buildings.Construction;

/**
 * The time-line count elapsed time (at each calling of nextStep). It check and call the trigger of elapsed events 
 * Adding & Removing will be sort the list. You should always call the method add(SimulatorEvent) & remove(SimulatorEvent). Don't force the index of adding.
 * This is clearly a violation of List because it not add at the end of the List
 * I will fix this semantic problem on a next version.
 * @author Jonathan GEOFFROY
 * @version 0.1
 */
public class TimeLine extends LinkedList<SimulatorEvent> {
  /**
   * Auto-generated serial (using eclipse)
   */
  private static final long serialVersionUID = 1547372495953597740L;

  /**
   * The time since for the city is running
   * Corresponding to the number of steps the simulator has already ran.
   */
  private long time;

  @Override
  public boolean add(SimulatorEvent e) {
    assert(e.getHandlerTime() > time) : "you cannot add an event if it handlerTime is already reached";
    int i = 0;
    for(SimulatorEvent val : this) {
      if(val.compareTo(e) > 0) {
        add(i, e);
        return true;
      }
      i++;
    }
    super.add(e);
    return true;
  }

  /**
   * Remove all events created by <construction>
   * @param construction
   */
  public void removeEventsFrom(Construction construction) {
    LinkedList<SimulatorEvent> toRemove = new LinkedList<SimulatorEvent>();
    for(SimulatorEvent e : this) {
      if (e.getCreator().equals(construction)) {
        toRemove.add(e);
      }
    }
    removeAll(toRemove);
  }

  /**
   * Do the next step of the simulation
   * call onTrigger(<sim>) for each SimulatorEvent which have reached the time of the next step
   * @param sim
   */
  public void nextStep(Simulator sim) {
    time++;

    SimulatorEvent event;
    boolean continued = true;

    while (continued && !isEmpty()) {
      event = getFirst();
      if(event.compareTo(time) <= 0) {
        removeFirst();
        event.onTrigger(sim);
      }
      else {
        continued = false;
      }
    }
  }

  public long getTime() {
    return time;
  }
}




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