56 lines
1.3 KiB
Java
56 lines
1.3 KiB
Java
package cicaprojekt;
|
|
|
|
import java.util.Stack;
|
|
|
|
public class Scale extends Field {
|
|
private Gate gateConnected;
|
|
private int threshold;
|
|
private int weight;
|
|
|
|
|
|
public Scale(Gate gate, int threshold) {
|
|
gateConnected = gate;
|
|
this.threshold = threshold;
|
|
boxStack = new Stack<Box>();
|
|
}
|
|
|
|
@Override
|
|
public void onEntry(PlayerBase playerBase) {
|
|
gateConnected.setOpen(true);
|
|
}
|
|
|
|
@Override
|
|
public void onExit(PlayerBase playerBase) {
|
|
gateConnected.setOpen(false);
|
|
}
|
|
|
|
@Override
|
|
public Box getABox() {
|
|
if (boxStack.isEmpty())
|
|
return null;
|
|
weight -= boxStack.peek().weight();
|
|
stackChanged();
|
|
return boxStack.pop();
|
|
}
|
|
|
|
@Override
|
|
public void putABox(Box box) {
|
|
if (box == null)
|
|
return;
|
|
boxStack.push(box);
|
|
weight += box.weight();
|
|
stackChanged();
|
|
}
|
|
|
|
public void spawnStargate(Stargate stargate, Direction direction) {
|
|
adjacentTile.get(direction).spawnStargate(stargate, direction);
|
|
}
|
|
|
|
private void stackChanged() {
|
|
if (weight > threshold)
|
|
gateConnected.setOpen(true);
|
|
else
|
|
gateConnected.setOpen(false);
|
|
}
|
|
}
|