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:
parent
7f98d7ff3d
commit
db54dcdd1d
@ -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();
|
||||
|
||||
@ -27,7 +33,21 @@ public class Scale extends Field {
|
||||
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Scale.onExit()");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user