This commit is contained in:
muskenum 2016-04-24 22:59:10 +02:00
commit f38642c06b
12 changed files with 125 additions and 68 deletions

View File

@ -1,6 +1,6 @@
package cicaprojekt;
public class Box implements cicaprojekt.Pickable, cicaprojekt.Destroyable
public class Box implements Pickable, Destroyable
{
private int weight = 5;

View File

@ -36,13 +36,13 @@ public class Dungeon {
case 'Z':
Field zpmfield = new Field();
zpmfield.setItemOnTile(new ZPM());
zpmfield.setZPMOnTile(new ZPM());
dungeon[y][x] = zpmfield;
break;
case 'B':
Field boxfield = new Field();
boxfield.setItemOnTile(new Box());
boxfield.putABox(new Box());
dungeon[y][x] = boxfield;
break;

View File

@ -5,27 +5,13 @@ import java.util.Map;
public class Field extends cicaprojekt.Tile
{
public static Map<Direction, Tile> testAdjacentTile = new HashMap<Direction, Tile>();
public static Field testField = new Field();
private static boolean testAdjTileSet = false;
private static int recursionLimit = 0;
public Field() {
setItemOnTile(new Box());
adjacentTile = testAdjacentTile;
setTestAdjacentTile();
super();
}
private void setTestAdjacentTile() {
if(!testAdjTileSet) {
testAdjacentTile.put(Direction.NORTH, Field.testField);
testAdjacentTile.put(Direction.EAST, Field.testField);
testAdjacentTile.put(Direction.SOUTH, Field.testField);
testAdjacentTile.put(Direction.WEST, Field.testField);
testAdjTileSet = true;
}
}
@Override
public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) {
@ -34,9 +20,15 @@ public class Field extends cicaprojekt.Tile
adjacentTile.get(direction).spawnStargate(stargate, direction);
}
public void onEntry() {
public void onEntry(PlayerBase playerBase) {
if(boxStack.size() > 0)
return;
playerBase.setCurrentTile(this);
if(zpmOnTile != null)
playerBase.pickZPM(this);
}
public void onExit() {
public void onExit(PlayerBase playerBase) {
return;
}
}

View File

@ -2,15 +2,25 @@ package cicaprojekt;
public class Gap extends cicaprojekt.Tile
{
public Gap(){
super();
}
@Override
public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) {
adjacentTile.get(direction).spawnStargate(stargate, direction);
}
public void onEntry() {
this.removeItemFromTile().destroy();
public void onEntry(PlayerBase playerBase) {
playerBase.destroy();
}
public void onExit() {
public void onExit(PlayerBase playerBase) throws IllegalStateException {
throw new IllegalStateException("Hiba! A szakadékból nem jut ki semmi!");
}
@Override
public void putABox(Box box) {
box.destroy();
}
}

View File

@ -1,18 +1,29 @@
package cicaprojekt;
public class Gate extends cicaprojekt.Tile
public class Gate extends Tile
{
private boolean open = false;
public Gate(){
super();
}
public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) {
public void spawnStargate(Stargate stargate, Direction direction) {
if(this.open) adjacentTile.get(direction).spawnStargate(stargate, direction);
}
public void onEntry() {
public void onEntry(PlayerBase playerBase) {
if(open){
playerBase.setCurrentTile(this);
}
else
return;
}
public void onExit() {
public void onExit(PlayerBase playerBase) throws IllegalStateException {
if(!open){
throw new IllegalStateException("Hiba! Te hogy kerültél a csukott ajtóba?");
}
}
public boolean isOpen() {

View File

@ -1,5 +1,6 @@
package cicaprojekt;
import java.util.ArrayList;
import java.util.List;
public class Player extends PlayerBase{
@ -8,20 +9,27 @@ public class Player extends PlayerBase{
public Player(Tile startTile, Direction startDirection){
zpmContainer = new ArrayList<>();
currentTile = startTile;
facingDirection = startDirection; /* Be lehetne állítani egy defaultot is, nem tudom, mennyire kéne */
}
public void boxLift() {
boxLifted = (Box) currentTile.getAdjacentTile(facingDirection).removeItemFromTile();
boxLifted = (Box) currentTile.getAdjacentTile(facingDirection).getABox();
}
public void boxDrop() {
currentTile.getAdjacentTile(facingDirection).setItemOnTile(boxLifted);
currentTile.getAdjacentTile(facingDirection).putABox(boxLifted);
boxLifted = null;
}
public void shootStargate(Stargate stargate) {
@Override
public void pickZPM(Tile tile)
{
zpmContainer.add(tile.getZPMFromTile());
}
public void shootStargate(Stargate stargate) {
this.currentTile.getAdjacentTile(facingDirection).spawnStargate(stargate, facingDirection);
}
}

View File

@ -6,8 +6,7 @@ public class PlayerBase implements Destroyable{
protected Direction facingDirection;
public void destroy() {
}
public void destroy() {}
public Tile getCurrentTile() {
return currentTile;
@ -20,10 +19,12 @@ public class PlayerBase implements Destroyable{
public void move(Direction direction) {
this.setFacingDirection(direction);
Tile tile = this.getCurrentTile().getAdjacentTile(direction);
tile.onEntry();
tile.onEntry(this);
setCurrentTile(tile);
}
public void pickZPM(Tile tile) { /* PlayerBase does not collect ZPM modules */ }
public void rotateLeft() {
switch (facingDirection) {
case NORTH:

View File

@ -4,7 +4,6 @@ import java.util.Stack;
public class Scale extends Field {
private Gate gateConnected;
private Stack<Pickable> itemsOnTile;
private int threshold;
private int weight;
@ -12,32 +11,38 @@ public class Scale extends Field {
public Scale(Gate gate, int threshold){
gateConnected = gate;
this.threshold = threshold;
itemsOnTile = new Stack<Pickable>();
boxStack = new Stack<Box>();
}
public void onEntry() {
@Override
public void onEntry(PlayerBase playerBase) {
gateConnected.setOpen(true);
}
public void onExit() {
@Override
public void onExit(PlayerBase playerBase) {
gateConnected.setOpen(false);
}
@Override
public Pickable removeItemFromTile() {
weight -= itemsOnTile.peek().weight();
public Box getABox() {
if(boxStack.isEmpty())
return null;
weight -= boxStack.peek().weight();
stackChanged();
return itemsOnTile.pop();
return boxStack.pop();
}
@Override
public void setItemOnTile(Pickable item) {
itemsOnTile.push(item);
weight += item.weight();
public void putABox(Box box) {
if(box == null)
return;
boxStack.push(box);
weight += box.weight();
stackChanged();
}
public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) {
public void spawnStargate(Stargate stargate, Direction direction) {
adjacentTile.get(direction).spawnStargate(stargate, direction);
}

View File

@ -5,21 +5,29 @@ public class Stargate {
public static final Stargate yellowStargate = new Stargate();
public static final Stargate blueStargate = new Stargate();
public static final Stargate redStargate = new Stargate();
public static final Stargate greenStargate = new Stargate();
public /*final*/ Stargate other; //TODO find better ways to do this
private cicaprojekt.Wall currentWall;
private Wall currentWall;
private Stargate() {
isSpawned = false;
}
public static void init() {
yellowStargate.other = blueStargate;
blueStargate.other = yellowStargate;
redStargate.other = greenStargate;
greenStargate.other = redStargate;
}
public cicaprojekt.Wall getCurrentWall() {
public Wall getCurrentWall() {
return currentWall;
}
public void setCurrentWall(cicaprojekt.Wall wall) {
public void setCurrentWall(Wall wall) {
currentWall = wall;
}

View File

@ -2,20 +2,16 @@ package cicaprojekt;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
public abstract class Tile {
protected Map<Direction, Tile> adjacentTile;
private Pickable itemOnTile;
protected ZPM zpmOnTile;
protected Stack<Box> boxStack;
public Tile(){
adjacentTile = new HashMap<Direction, Tile>();
adjacentTile.put(Direction.NORTH, Field.testField);
adjacentTile.put(Direction.EAST, Field.testField);
adjacentTile.put(Direction.SOUTH, Field.testField);
adjacentTile.put(Direction.WEST, Field.testField);
itemOnTile = new Box();
}
public Tile getAdjacentTile(Direction direction) {
@ -23,20 +19,34 @@ public abstract class Tile {
}
public void setAdajacentTile(Tile newTile, Direction direction) {
adjacentTile.put(direction, newTile);
}
public abstract void spawnStargate(Stargate stargate, Direction direction);
public abstract void onEntry();
public abstract void onEntry(PlayerBase playerBase);
public abstract void onExit();
public abstract void onExit(PlayerBase playerBase);
public Pickable removeItemFromTile() {
Pickable item = itemOnTile;
return item;
public void setZPMOnTile(ZPM zpm) {
zpmOnTile = zpm;
}
public void setItemOnTile(Pickable item) {
itemOnTile = item;
public ZPM getZPMFromTile() {
ZPM zpm = zpmOnTile;
zpmOnTile = null;
return zpm;
}
public void putABox(Box box) {
if(box == null)
return;
boxStack.push(box);
}
public Box getABox(){
if(boxStack.isEmpty())
return null;
return boxStack.pop();
}
}

View File

@ -3,6 +3,9 @@ package cicaprojekt;
public class Wall extends Tile {
private Stargate sg;
public Wall(){
super();
}
public void spawnStargate(Stargate stargate, Direction direction) {
if(sg == null)
@ -11,13 +14,20 @@ public class Wall extends Tile {
return;
}
public void clearStargate(){
public void clearStargate() {
sg = null;
}
public void onEntry() {
public void onEntry(PlayerBase playerBase) {
if(sg == null) {
return;
}
else {
sg.teleport(playerBase.facingDirection);
}
}
public void onExit() {
public void onExit(PlayerBase playerBase) throws IllegalStateException {
throw new IllegalStateException("Hiba! Te hogy kerültél a falba?");
}
}

View File

@ -5,3 +5,5 @@ W O B S W
W W G W W
W F Z F W
W W W W W
1-3-2-2-5