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;
import java.util.Stack;
public class Scale extends Field {
private Gate gateConnected;
private Stack<Pickable> itemsOnTile;
private int threshold;
private int weight;
public Scale(Gate gate){
Menu.addTab();
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Scale.Scale(" + gate + ")");
gateConnected = gate;
itemsOnTile = new Stack<Pickable>();
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Scale.Scale()");
Menu.removeTab();
@ -28,6 +34,20 @@ public class Scale extends Field {
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) {
Menu.addTab();
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()");
Menu.removeTab();
}
private void stackChanged() {
if(weight > threshold)
gateConnected.setOpen(true);
else
gateConnected.setOpen(false);
}
}