Android Open Source - ZorbsCity Simulator Event






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 w w.  j  ava 2 s.c o  m*/
import jonathan.geoffroy.zorbscity.model.cityObjects.buildings.Construction;

/**
 * A SimulatorEvent is an event that will be triggered when the Simulator time-lime reach the handlerTime time.
 * When that's happening, the method onTrigger is called, i.e. the method ontriggeredEvent from creator is called.
 *
 * @author Jonathan GEOFFROY
 * @version 0.1
 */
public abstract class SimulatorEvent implements Comparable<Long> {
  /**
   * The building which has emitted this event from the Simulator
   */
  private Construction creator;

  /**
   * The time when this event should be triggered
   */
  private long handlerTime;

  public SimulatorEvent(Construction creator, long handlerTime) {
    super();
    this.creator = creator;
    this.handlerTime = handlerTime;
  }

  public Construction getCreator() {
    return creator;
  }

  public void setCreator(Construction creator) {
    this.creator = creator;
  }

  public long getHandlerTime() {
    return handlerTime;
  }

  public void setHandlerTime(long handlerTime) {
    this.handlerTime = handlerTime;
  }
  
  public void incHandlerTime(int handlerInc) {
    handlerTime += handlerInc;
  }


  @Override
  /**
   * Compare the handlerTime between this and e
   * It's the result of handlerTime - other
   * Means that if handlerTime is triggered after e, the result is positive 
   */
  public int compareTo(Long other) {
    return (int) (handlerTime - other);
  }

  public int compareTo(SimulatorEvent other) {
    return (int)(handlerTime - other.handlerTime);
  }

  /**
   * Should be called when the simulator time-line has reached  the handlerTime time.
   * @param sim 
   */
  public void onTrigger(Simulator sim) {
    creator.onTriggeredEvent(this, sim);    
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((creator == null) ? 0 : creator.hashCode());
    result = prime * result + (int) (handlerTime ^ (handlerTime >>> 32));
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    SimulatorEvent other = (SimulatorEvent) obj;
    if (creator == null) {
      if (other.creator != null)
        return false;
    } else if (!creator.equals(other.creator))
      return false;
    if (handlerTime != other.handlerTime)
      return false;
    return true;
  }
}




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