Android Open Source - ZorbsCity Galaxy






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  av  a2 s  .co m*/
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashMap;

import jonathan.geoffroy.zorbscity.model.helpers.Coord2D;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;

/**
 * The Galaxy is a container of Cities. So all Cities are in the Galaxy.
 * The Galaxy is a global view of the World, i.e. on all player (& computer) cities.
 * While you can see or search any cities, no one is loaded by the Galaxy. You have to choose one and begin to play with to load it.
 * @author Jonathan GEOFFROY
 * @version 0.1
 */
public class Galaxy implements Serializable {
  /**
   * auto-generated serial (using eclipse IDE)
   */
  private static final long serialVersionUID = 7732169533388534682L;

  /**
   * The name of the galaxy
   * useful to load the galaxy
   */
  private String name;

  /**
   * Contains all cities of the map, describing by there coordinates
   * Note that as explained previously, on the name of cities are loaded, not the cities themselves
   */
  private HashMap<Coord2D, String> cities;

  public Galaxy(String name) {
    super();
    this.name = name;
    cities = new HashMap<Coord2D, String>();
  }

  /**
   * Load the galaxy galaxyName
   * @param galaxyName the name of the Galaxy
   * @return the loaded Galaxy, or null if the galaxy don't exist
   */
  public static Galaxy load(String galaxyName) {
    Galaxy g = null;
    try {
      FileHandle handle = Gdx.files.local("data/galaxies/" + galaxyName + ".galaxy");
      ObjectInputStream reader = null;
      reader = new ObjectInputStream(new FileInputStream(handle.file()));
      g = (Galaxy) reader.readObject();
      reader.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
    return g;
  }

  /**
   * Save this galaxy in the file: ./data/galaxies/_name_.galaxy
   * erase the old file if the galaxy already exists
   */
  public void save() {
    try {
      FileHandle handle = Gdx.files.local("data/galaxies/" + name + ".galaxy");
      ObjectOutputStream writer = new ObjectOutputStream(handle.write(false));
      writer.writeObject(this);
      writer.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  
  
  public String getName() {
    return name;
  }

  public HashMap<Coord2D, String> getCities() {
    return cities;
  }

  public Object getCity(Coord2D coord) {
    return cities.get(coord);
  }
}




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