123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- package classes;
- import java.util.ArrayList;
- import Interfaces.ComparableObject;
- import ui.model.idCounter;
- public abstract class CpsObject implements ComparableObject {
- /* Type of the Object */
- String objName;
- /* Name given by the user */
- String name;
- /* ID of the Obj. */
- int ID;
- /* Path of the image for the Obj. */
- String image;
- /* Array of neighbors */
- ArrayList<CpsObject> connections;
- /* Position with a X and Y value */
- Position position;
- /* Energy input and output of each object in the grid */
- float energyIn;
- float energyOut;
- /**
- * Constructor for an CpsObejct with an unique ID
- */
- public CpsObject(String objName) {
- setObjName(objName);
- setName(objName);
- setConnections(new ArrayList<CpsObject>());
- setPosition(new Position());
- setImage("/Images/Dummy_House.png");
- System.out.println("ID: " + ID + " of " + objName);
- }
- public CpsObject(CpsObject obj) {
- setObjName(obj.getObjName());
- setName(obj.getObjName());
- setConnections(new ArrayList<CpsObject>());
- setPosition(new Position());
- setID(idCounter.nextId());
- setEnergyIn(obj.getEnergyIn());
- setEnergyOut(obj.getEnergyOut());
- setImage(obj.getImage());
- }
- /* Obj type */
- public String getObjName() {
- return objName;
- }
- public void setObjName(String objName) {
- this.objName = objName;
- }
- /* User defined Name */
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- /* Unique ID number */
- public int getID() {
- return ID;
- }
- /**
- * @param iD
- * the iD to set
- */
- public void setID(int ID) {
- this.ID = ID;
- }
- /* Image path */
- public String getImage() {
- return image;
- }
- public void setImage(String image) {
- this.image = image;
- }
- /**
- * @return the connections
- */
- public ArrayList<CpsObject> getConnections() {
- return connections;
- }
- /**
- * @param connections
- * the connections to set
- */
- public void setConnections(ArrayList<CpsObject> connections) {
- this.connections = connections;
- }
- /* Neighbors array */
- public ArrayList<CpsObject> getConnectedTo() {
- return connections;
- }
- public void AddConnection(CpsObject toConnect) {
- connections.add(toConnect);
- }
- public void setPosition(Position pos) {
- this.position = pos;
- }
- /* Position (x and Y) */
- public void setPosition(int x, int y) {
- setPosition(new Position(x, y));
- }
- public Position getPosition() {
- return position;
- }
- /* Getter and Setters for the energy input and output */
- public float getEnergyIn() {
- return energyIn;
- }
- public void setEnergyIn(float energyIn) {
- this.energyIn = energyIn;
- }
- public float getEnergyOut() {
- return energyOut;
- }
- public void setEnergyOut(float energyOut) {
- this.energyOut = energyOut;
- }
- @Override
- public String getCompareName() {
- return objName;
- }
- }
|