Sfoglia il codice sorgente

Creation of ground classes and definition of the respective ground variables and functions

Edgardo Palza 8 anni fa
parent
commit
a39243ad96

BIN
bin/tests/Tests1.class


BIN
bin/ui/controller/Buildings.class


BIN
bin/ui/controller/Gadget.class


BIN
bin/ui/controller/IdCounter.class


BIN
bin/ui/controller/WireNode.class


BIN
bin/ui/controller/cpsObj.class


BIN
bin/ui/view/MyCanvas.class


+ 15 - 1
src/tests/Tests1.java

@@ -1,4 +1,5 @@
 package tests;
+import ui.controller.*;
 
 /**
  * First round of tests
@@ -6,5 +7,18 @@ package tests;
  */
 
 public class Tests1 {
-
+	
+	/**
+	 * Create some CPS object
+	 */
+	public static void main(String[] args) {
+		Buildings b1 = new Buildings();
+		System.out.println(b1.getID());
+		System.out.println(b1.getName());
+		Buildings b2 = new Buildings();
+		System.out.println(b2.getID());
+		WireNode w1 = new WireNode();
+		System.out.println(w1.getName());
+		System.out.println(w1.getID());
+	}
 }

+ 28 - 0
src/ui/controller/Buildings.java

@@ -0,0 +1,28 @@
+package ui.controller;
+
+public class Buildings extends CPSObj {
+	
+	/*Array of all consumers*/
+	Gadget[] consumers;
+	/*Array of all producers*/
+	Gadget[] producers;
+	/*Total of consumption*/
+	float currentEnergy;
+	/**
+	 * State of the building: 
+	 * 0 = fully supplied (currentEnergy == 0)
+	 * 1 = not enough energy (currentEnergy > 0)
+	 * 2 = oversupplied (currentEnergy < 0)
+	 */
+	int state;
+	
+	/**
+	 * Constructor
+	 * Set by default the name of the object equals to the category name, until the user changes it.
+	 */
+	public Buildings() {
+		super.setObjName("House");
+		super.name = super.getObjName();
+	}
+	
+}

+ 32 - 21
src/ui/controller/cpsObj.java → src/ui/controller/CPSObj.java

@@ -1,67 +1,78 @@
 package ui.controller;
 
-abstract class cpsObj {
-	/*Type of the Object*/
+abstract class CPSObj {
+	/* Type of the Object */
 	String objName;
-	/*Name given by the user*/
+	/* Name given by the user */
 	String name;
-	/*ID of the Obj.*/
+	/* ID of the Obj. */
 	int ID;
-	/*Path of the image for the Obj.*/
+	/* Path of the image for the Obj. */
 	String image;
-	/*Array of neighbors*/
-	cpsObj[] connectedTo;
-	/*Position with a X and Y value*/
+	/* Array of neighbors */
+	CPSObj[] connectedTo;
+	/* Position with a X and Y value */
 	int xCoord;
 	int yCoord;
-	
-	/*Obj type*/
+	public CPSObj() {
+		ID = IdCounter.nextId();
+	}
+	/* Obj type */
 	public String getObjName() {
 		return objName;
 	}
+
 	public void setObjName(String objName) {
 		this.objName = objName;
 	}
-	/*User defined Name*/
+
+	/* User defined Name */
 	public String getName() {
 		return name;
 	}
+
 	public void setName(String name) {
 		this.name = name;
 	}
-	/*Unique ID number*/
+
+	/* Unique ID number */
 	public int getID() {
 		return ID;
 	}
-	public void setID(int iD) {
-		ID = iD;
-	}
-	/*Image path*/
+
+	/* Image path */
 	public String getImage() {
 		return image;
 	}
+
 	public void setImage(String image) {
 		this.image = image;
 	}
-	/*Neighbors array*/
-	public cpsObj[] getConnectedTo() {
+
+	/* Neighbors array */
+	public CPSObj[] getConnectedTo() {
 		return connectedTo;
 	}
-	public void setConnectedTo(cpsObj[] connectedTo) {
+
+	public void setConnectedTo(CPSObj[] connectedTo) {
 		this.connectedTo = connectedTo;
 	}
-	/*Position (x and Y)*/
+
+	/* Position (x and Y) */
 	public int getxCoord() {
 		return xCoord;
 	}
+
 	public void setxCoord(int xCoord) {
 		this.xCoord = xCoord;
 	}
+
 	public int getyCoord() {
 		return yCoord;
 	}
+
 	public void setyCoord(int yCoord) {
 		this.yCoord = yCoord;
 	}
-	
+
 }

+ 49 - 0
src/ui/controller/Gadget.java

@@ -0,0 +1,49 @@
+package ui.controller;
+
+public class Gadget {
+	
+	/*Name of the gadget*/
+	String name;
+	/*Quantity*/
+	int amount;
+	/*Energy per gadget*/
+	float energy;
+	/*If the gadget is working xor not (true xor false)*/
+	boolean isWorking;
+	/*Total Energy*/
+	float totalEnergy;
+	
+	public Gadget() {
+		setName("TV");
+		setAmount(1);
+		setEnergy(10);
+		this.isWorking = true;
+		this.totalEnergy = energy*amount;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public int getAmount() {
+		return amount;
+	}
+
+	public void setAmount(int amount) {
+		this.amount = amount;
+	}
+
+	public float getEnergy() {
+		return energy;
+	}
+
+	public void setEnergy(float energy) {
+		this.energy = energy;
+	}
+	
+	
+}

+ 9 - 0
src/ui/controller/IdCounter.java

@@ -0,0 +1,9 @@
+package ui.controller;
+
+public class IdCounter {
+	private static int counter = 0;
+
+	public static synchronized int nextId() {
+		return ++counter;
+	}
+}

+ 26 - 0
src/ui/controller/WireNode.java

@@ -0,0 +1,26 @@
+package ui.controller;
+
+public class WireNode extends CPSObj {
+	
+	/**Input capacity of the WireNode.
+	 * For switches  = ??;
+	 * For transformer = ??;
+	 */
+	float energyIn;
+	
+	/**Input capacity of the WireNode.
+	 * For switches  = ??;
+	 * For transformer = ??;
+	 */
+	float energyOut;
+	
+	/**
+	 * Constructor
+	 * Set by default the name of the object equals to the category name, until the user changes it. 
+	 */
+	
+	public WireNode() {
+		super.setObjName("Switch");
+		super.name = super.getObjName();
+	}
+}