Implemented stack in Scale

Implemented a stack of items on the Scale, instead of one item, change was needed due to the modified specification
This commit is contained in:
Bokros Bálint 2016-04-19 11:26:10 +02:00
parent 7f98d7ff3d
commit db54dcdd1d

View File

@ -1,12 +1,18 @@
package cicaprojekt; package cicaprojekt;
import java.util.Stack;
public class Scale extends Field { public class Scale extends Field {
private Gate gateConnected; private Gate gateConnected;
private Stack<Pickable> itemsOnTile;
private int threshold;
private int weight;
public Scale(Gate gate){ public Scale(Gate gate){
Menu.addTab(); Menu.addTab();
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Scale.Scale(" + gate + ")"); System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Scale.Scale(" + gate + ")");
gateConnected = gate; gateConnected = gate;
itemsOnTile = new Stack<Pickable>();
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Scale.Scale()"); System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Scale.Scale()");
Menu.removeTab(); Menu.removeTab();
@ -28,6 +34,20 @@ public class Scale extends Field {
Menu.removeTab(); Menu.removeTab();
} }
@Override
public Pickable removeItemFromTile() {
weight -= itemsOnTile.peek().weight();
stackChanged();
return itemsOnTile.pop();
}
@Override
public void setItemOnTile(Pickable item) {
itemsOnTile.push(item);
weight += item.weight();
stackChanged();
}
public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) { public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) {
Menu.addTab(); Menu.addTab();
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Scale.spawnStarGate(stargate," + direction.name() + ")"); System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Scale.spawnStarGate(stargate," + direction.name() + ")");
@ -35,4 +55,11 @@ public class Scale extends Field {
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Scale.spawnStarGate()"); System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Scale.spawnStarGate()");
Menu.removeTab(); Menu.removeTab();
} }
private void stackChanged() {
if(weight > threshold)
gateConnected.setOpen(true);
else
gateConnected.setOpen(false);
}
} }