Scale - finished

This commit is contained in:
ericnerdo 2016-04-24 22:36:54 +02:00
parent fd64fd9165
commit 1c8566d96c

View File

@ -4,7 +4,6 @@ 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 threshold;
private int weight; private int weight;
@ -12,28 +11,34 @@ public class Scale extends Field {
public Scale(Gate gate, int threshold){ public Scale(Gate gate, int threshold){
gateConnected = gate; gateConnected = gate;
this.threshold = threshold; this.threshold = threshold;
itemsOnTile = new Stack<Pickable>(); boxStack = new Stack<Box>();
} }
public void onEntry() { @Override
public void onEntry(PlayerBase playerBase) {
gateConnected.setOpen(true); gateConnected.setOpen(true);
} }
public void onExit() { @Override
public void onExit(PlayerBase playerBase) {
gateConnected.setOpen(false); gateConnected.setOpen(false);
} }
@Override @Override
public Pickable removeItemFromTile() { public Box getABox() {
weight -= itemsOnTile.peek().weight(); if(boxStack.isEmpty())
return null;
weight -= boxStack.peek().weight();
stackChanged(); stackChanged();
return itemsOnTile.pop(); return boxStack.pop();
} }
@Override @Override
public void setItemOnTile(Pickable item) { public void putABox(Box box) {
itemsOnTile.push(item); if(box == null)
weight += item.weight(); return;
boxStack.push(box);
weight += box.weight();
stackChanged(); stackChanged();
} }