Merge branch 'master' of https://github.com/bokrosbalint/cicaprojekt
This commit is contained in:
commit
f38642c06b
@ -1,6 +1,6 @@
|
|||||||
package cicaprojekt;
|
package cicaprojekt;
|
||||||
|
|
||||||
public class Box implements cicaprojekt.Pickable, cicaprojekt.Destroyable
|
public class Box implements Pickable, Destroyable
|
||||||
{
|
{
|
||||||
private int weight = 5;
|
private int weight = 5;
|
||||||
|
|
||||||
|
@ -36,13 +36,13 @@ public class Dungeon {
|
|||||||
|
|
||||||
case 'Z':
|
case 'Z':
|
||||||
Field zpmfield = new Field();
|
Field zpmfield = new Field();
|
||||||
zpmfield.setItemOnTile(new ZPM());
|
zpmfield.setZPMOnTile(new ZPM());
|
||||||
dungeon[y][x] = zpmfield;
|
dungeon[y][x] = zpmfield;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'B':
|
case 'B':
|
||||||
Field boxfield = new Field();
|
Field boxfield = new Field();
|
||||||
boxfield.setItemOnTile(new Box());
|
boxfield.putABox(new Box());
|
||||||
dungeon[y][x] = boxfield;
|
dungeon[y][x] = boxfield;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -5,27 +5,13 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class Field extends cicaprojekt.Tile
|
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;
|
private static int recursionLimit = 0;
|
||||||
|
|
||||||
|
|
||||||
public Field() {
|
public Field() {
|
||||||
setItemOnTile(new Box());
|
super();
|
||||||
adjacentTile = testAdjacentTile;
|
|
||||||
setTestAdjacentTile();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
@Override
|
||||||
public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) {
|
public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) {
|
||||||
@ -34,9 +20,15 @@ public class Field extends cicaprojekt.Tile
|
|||||||
adjacentTile.get(direction).spawnStargate(stargate, direction);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,15 +2,25 @@ package cicaprojekt;
|
|||||||
|
|
||||||
public class Gap extends cicaprojekt.Tile
|
public class Gap extends cicaprojekt.Tile
|
||||||
{
|
{
|
||||||
|
public Gap(){
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) {
|
public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) {
|
||||||
adjacentTile.get(direction).spawnStargate(stargate, direction);
|
adjacentTile.get(direction).spawnStargate(stargate, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEntry() {
|
public void onEntry(PlayerBase playerBase) {
|
||||||
this.removeItemFromTile().destroy();
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,29 @@
|
|||||||
package cicaprojekt;
|
package cicaprojekt;
|
||||||
|
|
||||||
public class Gate extends cicaprojekt.Tile
|
public class Gate extends Tile
|
||||||
{
|
{
|
||||||
private boolean open = false;
|
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);
|
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() {
|
public boolean isOpen() {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cicaprojekt;
|
package cicaprojekt;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Player extends PlayerBase{
|
public class Player extends PlayerBase{
|
||||||
@ -8,19 +9,26 @@ public class Player extends PlayerBase{
|
|||||||
|
|
||||||
|
|
||||||
public Player(Tile startTile, Direction startDirection){
|
public Player(Tile startTile, Direction startDirection){
|
||||||
|
zpmContainer = new ArrayList<>();
|
||||||
currentTile = startTile;
|
currentTile = startTile;
|
||||||
facingDirection = startDirection; /* Be lehetne állítani egy defaultot is, nem tudom, mennyire kéne */
|
facingDirection = startDirection; /* Be lehetne állítani egy defaultot is, nem tudom, mennyire kéne */
|
||||||
}
|
}
|
||||||
|
|
||||||
public void boxLift() {
|
public void boxLift() {
|
||||||
boxLifted = (Box) currentTile.getAdjacentTile(facingDirection).removeItemFromTile();
|
boxLifted = (Box) currentTile.getAdjacentTile(facingDirection).getABox();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void boxDrop() {
|
public void boxDrop() {
|
||||||
currentTile.getAdjacentTile(facingDirection).setItemOnTile(boxLifted);
|
currentTile.getAdjacentTile(facingDirection).putABox(boxLifted);
|
||||||
boxLifted = null;
|
boxLifted = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pickZPM(Tile tile)
|
||||||
|
{
|
||||||
|
zpmContainer.add(tile.getZPMFromTile());
|
||||||
|
}
|
||||||
|
|
||||||
public void shootStargate(Stargate stargate) {
|
public void shootStargate(Stargate stargate) {
|
||||||
this.currentTile.getAdjacentTile(facingDirection).spawnStargate(stargate, facingDirection);
|
this.currentTile.getAdjacentTile(facingDirection).spawnStargate(stargate, facingDirection);
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,7 @@ public class PlayerBase implements Destroyable{
|
|||||||
protected Direction facingDirection;
|
protected Direction facingDirection;
|
||||||
|
|
||||||
|
|
||||||
public void destroy() {
|
public void destroy() {}
|
||||||
}
|
|
||||||
|
|
||||||
public Tile getCurrentTile() {
|
public Tile getCurrentTile() {
|
||||||
return currentTile;
|
return currentTile;
|
||||||
@ -20,10 +19,12 @@ public class PlayerBase implements Destroyable{
|
|||||||
public void move(Direction direction) {
|
public void move(Direction direction) {
|
||||||
this.setFacingDirection(direction);
|
this.setFacingDirection(direction);
|
||||||
Tile tile = this.getCurrentTile().getAdjacentTile(direction);
|
Tile tile = this.getCurrentTile().getAdjacentTile(direction);
|
||||||
tile.onEntry();
|
tile.onEntry(this);
|
||||||
setCurrentTile(tile);
|
setCurrentTile(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void pickZPM(Tile tile) { /* PlayerBase does not collect ZPM modules */ }
|
||||||
|
|
||||||
public void rotateLeft() {
|
public void rotateLeft() {
|
||||||
switch (facingDirection) {
|
switch (facingDirection) {
|
||||||
case NORTH:
|
case NORTH:
|
||||||
|
@ -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,32 +11,38 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) {
|
public void spawnStargate(Stargate stargate, Direction direction) {
|
||||||
adjacentTile.get(direction).spawnStargate(stargate, direction);
|
adjacentTile.get(direction).spawnStargate(stargate, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,21 +5,29 @@ public class Stargate {
|
|||||||
|
|
||||||
public static final Stargate yellowStargate = new Stargate();
|
public static final Stargate yellowStargate = new Stargate();
|
||||||
public static final Stargate blueStargate = 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
|
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() {
|
public static void init() {
|
||||||
yellowStargate.other = blueStargate;
|
yellowStargate.other = blueStargate;
|
||||||
blueStargate.other = yellowStargate;
|
blueStargate.other = yellowStargate;
|
||||||
|
redStargate.other = greenStargate;
|
||||||
|
greenStargate.other = redStargate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public cicaprojekt.Wall getCurrentWall() {
|
public Wall getCurrentWall() {
|
||||||
return currentWall;
|
return currentWall;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCurrentWall(cicaprojekt.Wall wall) {
|
public void setCurrentWall(Wall wall) {
|
||||||
currentWall = wall;
|
currentWall = wall;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,20 +2,16 @@ package cicaprojekt;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
public abstract class Tile {
|
public abstract class Tile {
|
||||||
protected Map<Direction, Tile> adjacentTile;
|
protected Map<Direction, Tile> adjacentTile;
|
||||||
private Pickable itemOnTile;
|
protected ZPM zpmOnTile;
|
||||||
|
protected Stack<Box> boxStack;
|
||||||
|
|
||||||
|
|
||||||
public Tile(){
|
public Tile(){
|
||||||
adjacentTile = new HashMap<Direction, 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) {
|
public Tile getAdjacentTile(Direction direction) {
|
||||||
@ -23,20 +19,34 @@ public abstract class Tile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setAdajacentTile(Tile newTile, Direction direction) {
|
public void setAdajacentTile(Tile newTile, Direction direction) {
|
||||||
|
adjacentTile.put(direction, newTile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void spawnStargate(Stargate stargate, Direction direction);
|
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() {
|
public void setZPMOnTile(ZPM zpm) {
|
||||||
Pickable item = itemOnTile;
|
zpmOnTile = zpm;
|
||||||
return item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setItemOnTile(Pickable item) {
|
public ZPM getZPMFromTile() {
|
||||||
itemOnTile = item;
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@ package cicaprojekt;
|
|||||||
public class Wall extends Tile {
|
public class Wall extends Tile {
|
||||||
private Stargate sg;
|
private Stargate sg;
|
||||||
|
|
||||||
|
public Wall(){
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
public void spawnStargate(Stargate stargate, Direction direction) {
|
public void spawnStargate(Stargate stargate, Direction direction) {
|
||||||
if(sg == null)
|
if(sg == null)
|
||||||
@ -11,13 +14,20 @@ public class Wall extends Tile {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearStargate(){
|
public void clearStargate() {
|
||||||
sg = null;
|
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?");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,3 +5,5 @@ W O B S W
|
|||||||
W W G W W
|
W W G W W
|
||||||
W F Z F W
|
W F Z F W
|
||||||
W W W W W
|
W W W W W
|
||||||
|
|
||||||
|
1-3-2-2-5
|
||||||
|
Loading…
Reference in New Issue
Block a user