Merge branch 'master' of https://github.com/bokrosbalint/cicaprojekt
This commit is contained in:
commit
d731db022f
@ -1,21 +1,20 @@
|
||||
package cicaprojekt;
|
||||
|
||||
public class Box implements Pickable, Destroyable
|
||||
{
|
||||
public class Box implements Pickable, Destroyable {
|
||||
private int weight = 5;
|
||||
|
||||
|
||||
public Box(){
|
||||
public Box() {
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
public void pick() {
|
||||
}
|
||||
public void pick() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int weight() {
|
||||
@Override
|
||||
public int weight() {
|
||||
return this.weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
package cicaprojekt;
|
||||
|
||||
public interface Destroyable {
|
||||
public void destroy();
|
||||
public void destroy();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
package cicaprojekt;
|
||||
|
||||
public enum Direction {
|
||||
NORTH, SOUTH, EAST, WEST;
|
||||
NORTH, SOUTH, EAST, WEST;
|
||||
}
|
||||
|
@ -1,9 +1,35 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Dungeon {
|
||||
cicaprojekt.Tile buildDungeon(File input) throws IOException
|
||||
/* NOTE: this function assumes that the parameter input is a well-formatted dungeon file.
|
||||
* Such file looks like as follows:
|
||||
*
|
||||
* <map width>x<map height>
|
||||
* <empty line>
|
||||
* <map matrix line 1>
|
||||
* ...
|
||||
* ...
|
||||
* <map matrix line <map height>>
|
||||
* <empty line>
|
||||
* <scale y>-<scale x>-<gate y>-<gate x>-<scale trigger weight>
|
||||
* ...
|
||||
* ...
|
||||
* <scale y>-<scale x>-<gate y>-<gate x>-<scale trigger weight>
|
||||
*
|
||||
* where the map matrix is a matrix of the following chars:
|
||||
* W: Wall
|
||||
* F: Field
|
||||
* Z: Field with a ZMP
|
||||
* B: Field with a Box
|
||||
* O: Field with ONeill
|
||||
* J: Field with Jaffa
|
||||
* G: Gate
|
||||
* S: Scale */
|
||||
Map<String, Tile> buildDungeon(File input) throws IOException
|
||||
{
|
||||
Tile oneilllocation = null;
|
||||
Tile jaffalocation = null;
|
||||
@ -17,8 +43,9 @@ public class Dungeon {
|
||||
Tile[][] dungeon = new Tile[width][height];
|
||||
|
||||
String line = null;
|
||||
Gate gate = new Gate();
|
||||
Gate lastgate = gate;
|
||||
Gate tempgate = new Gate();
|
||||
Scale tempscale = new Scale(tempgate, Integer.MAX_VALUE);
|
||||
int scalecount = 0;
|
||||
for (int y = 0; y < height; ++y)
|
||||
{
|
||||
line = reader.readLine().replaceAll("\\s",""); // read line and remove whitespaces
|
||||
@ -59,19 +86,27 @@ public class Dungeon {
|
||||
break;
|
||||
|
||||
case 'G':
|
||||
dungeon[y][x] = gate;
|
||||
lastgate = gate;
|
||||
gate = new Gate();
|
||||
dungeon[y][x] = tempgate;
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
dungeon[y][x] = new Scale(lastgate, 5);
|
||||
dungeon[y][x] = tempscale;
|
||||
scalecount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: code seems to be correct till this point based on a debugger run-through
|
||||
reader.readLine(); // throw empty line away
|
||||
|
||||
for (int i = 0; i < scalecount; ++i) // set up scale-gate connections
|
||||
{
|
||||
String[] scaledata = reader.readLine().split("-");
|
||||
|
||||
dungeon[Integer.parseInt(scaledata[0])][Integer.parseInt(scaledata[1])] =
|
||||
new Scale((Gate)dungeon[Integer.parseInt(scaledata[2])][Integer.parseInt(scaledata[3])],
|
||||
Integer.parseInt(scaledata[4]));
|
||||
}
|
||||
|
||||
/* setting up Tile cross references */
|
||||
for (int y = 0; y < height; ++y)
|
||||
@ -100,6 +135,11 @@ public class Dungeon {
|
||||
}
|
||||
}
|
||||
}
|
||||
return oneilllocation;
|
||||
|
||||
Map<String, Tile> playermap = new HashMap<>();
|
||||
playermap.put("oneill", oneilllocation);
|
||||
playermap.put("jaffa", jaffalocation);
|
||||
|
||||
return playermap;
|
||||
}
|
||||
}
|
@ -3,32 +3,31 @@ package cicaprojekt;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Field extends cicaprojekt.Tile
|
||||
{
|
||||
private static int recursionLimit = 0;
|
||||
public class Field extends cicaprojekt.Tile {
|
||||
private static int recursionLimit = 0;
|
||||
|
||||
|
||||
public Field() {
|
||||
super();
|
||||
}
|
||||
public Field() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) {
|
||||
if (recursionLimit++ >= 10)
|
||||
this.adjacentTile.put(direction, new Wall());
|
||||
adjacentTile.get(direction).spawnStargate(stargate, direction);
|
||||
}
|
||||
@Override
|
||||
public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) {
|
||||
if (recursionLimit++ >= 10)
|
||||
this.adjacentTile.put(direction, new Wall());
|
||||
adjacentTile.get(direction).spawnStargate(stargate, direction);
|
||||
}
|
||||
|
||||
public void onEntry(PlayerBase playerBase) {
|
||||
if(boxStack.size() > 0)
|
||||
return;
|
||||
playerBase.setCurrentTile(this);
|
||||
if(zpmOnTile != null)
|
||||
playerBase.pickZPM(this);
|
||||
}
|
||||
public void onEntry(PlayerBase playerBase) {
|
||||
if (boxStack.size() > 0)
|
||||
return;
|
||||
playerBase.setCurrentTile(this);
|
||||
if (zpmOnTile != null)
|
||||
playerBase.pickZPM(this);
|
||||
}
|
||||
|
||||
public void onExit(PlayerBase playerBase) {
|
||||
return;
|
||||
}
|
||||
public void onExit(PlayerBase playerBase) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,11 @@ package cicaprojekt;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class FlowOfTime extends Timer{
|
||||
private TimerTask timeup;
|
||||
private long gametime;
|
||||
public class FlowOfTime extends Timer {
|
||||
private TimerTask timeup;
|
||||
private long gametime;
|
||||
|
||||
|
||||
public void start()
|
||||
{
|
||||
}
|
||||
public void start() {
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,21 @@
|
||||
package cicaprojekt;
|
||||
|
||||
public class Game {
|
||||
private Player oneill;
|
||||
private Dungeon dungeon;
|
||||
private FlowOfTime flowoftime;
|
||||
private Player oneill;
|
||||
|
||||
private Dungeon dungeon;
|
||||
private FlowOfTime flowoftime;
|
||||
|
||||
public void allZPMsCollected() {
|
||||
this.stopGame();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
|
||||
public void startGame() {
|
||||
}
|
||||
public void allZPMsCollected() {
|
||||
this.stopGame();
|
||||
}
|
||||
|
||||
public void stopGame() {
|
||||
}
|
||||
public void startGame() {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {}
|
||||
public void stopGame() {
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,25 @@
|
||||
package cicaprojekt;
|
||||
|
||||
public class Gap extends cicaprojekt.Tile
|
||||
{
|
||||
public Gap(){
|
||||
super();
|
||||
}
|
||||
public class Gap extends cicaprojekt.Tile {
|
||||
public Gap() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) {
|
||||
adjacentTile.get(direction).spawnStargate(stargate, direction);
|
||||
}
|
||||
@Override
|
||||
public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) {
|
||||
adjacentTile.get(direction).spawnStargate(stargate, direction);
|
||||
}
|
||||
|
||||
public void onEntry(PlayerBase playerBase) {
|
||||
playerBase.destroy();
|
||||
}
|
||||
public void onEntry(PlayerBase playerBase) {
|
||||
playerBase.destroy();
|
||||
}
|
||||
|
||||
public void onExit(PlayerBase playerBase) throws IllegalStateException {
|
||||
throw new IllegalStateException("Hiba! A szakadékból nem jut ki semmi!");
|
||||
}
|
||||
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();
|
||||
}
|
||||
@Override
|
||||
public void putABox(Box box) {
|
||||
box.destroy();
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +1,34 @@
|
||||
package cicaprojekt;
|
||||
|
||||
public class Gate extends Tile
|
||||
{
|
||||
private boolean open = false;
|
||||
public class Gate extends Tile {
|
||||
private boolean open = false;
|
||||
|
||||
public Gate(){
|
||||
super();
|
||||
}
|
||||
public Gate() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void spawnStargate(Stargate stargate, Direction direction) {
|
||||
if(this.open) adjacentTile.get(direction).spawnStargate(stargate, direction);
|
||||
}
|
||||
public void spawnStargate(Stargate stargate, Direction direction) {
|
||||
if (this.open) adjacentTile.get(direction).spawnStargate(stargate, direction);
|
||||
}
|
||||
|
||||
public void onEntry(PlayerBase playerBase) {
|
||||
if(open){
|
||||
playerBase.setCurrentTile(this);
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
public void onEntry(PlayerBase playerBase) {
|
||||
if (open) {
|
||||
playerBase.setCurrentTile(this);
|
||||
} else
|
||||
return;
|
||||
}
|
||||
|
||||
public void onExit(PlayerBase playerBase) throws IllegalStateException {
|
||||
if(!open){
|
||||
throw new IllegalStateException("Hiba! Te hogy kerültél a csukott ajtóba?");
|
||||
}
|
||||
}
|
||||
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() {
|
||||
return open;
|
||||
}
|
||||
}
|
||||
|
||||
public void setOpen(boolean gateState) {
|
||||
public void setOpen(boolean gateState) {
|
||||
this.open = gateState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
package cicaprojekt;
|
||||
|
||||
public interface Measurable {
|
||||
public int weight();
|
||||
public int weight();
|
||||
}
|
||||
|
@ -7,22 +7,20 @@ public class Menu {
|
||||
public static String tabulator = "\t";
|
||||
|
||||
|
||||
public static void addTab()
|
||||
{
|
||||
public static void addTab() {
|
||||
tabulator += '\t';
|
||||
}
|
||||
|
||||
public static void removeTab()
|
||||
{
|
||||
tabulator = tabulator.substring(0, tabulator.length()-1);
|
||||
public static void removeTab() {
|
||||
tabulator = tabulator.substring(0, tabulator.length() - 1);
|
||||
}
|
||||
|
||||
public static void main (String[] args) throws IOException{
|
||||
public static void main(String[] args) throws IOException {
|
||||
System.out.println("Continuously Integrated Cica Projekt - Skeleton");
|
||||
System.out.println("Üdvözöllek a Babylon Simulator 2000 játékban! Kérlek válassz egy menüpontot!");
|
||||
|
||||
boolean isExiting = false;
|
||||
while(!isExiting) {
|
||||
while (!isExiting) {
|
||||
System.out.println("1. Lépés");
|
||||
System.out.println("2. Doboz felvétele");
|
||||
System.out.println("3. Doboz lerakása");
|
||||
@ -36,90 +34,90 @@ public class Menu {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
switch (sc.nextLine().charAt(0)) {
|
||||
case '1' :
|
||||
case '1':
|
||||
System.out.println("O’Neill [északi|nyugati|déli|keleti] irányba lép egyet,");
|
||||
System.out.println("Elfogadott bemenet: W, A, S, D");
|
||||
switch (sc.nextLine().charAt(0)) {
|
||||
case 'W' :
|
||||
case 'W':
|
||||
oNeill.move(Direction.NORTH);
|
||||
break;
|
||||
case 'A' :
|
||||
case 'A':
|
||||
oNeill.move(Direction.WEST);
|
||||
break;
|
||||
case 'S' :
|
||||
case 'S':
|
||||
oNeill.move(Direction.SOUTH);
|
||||
break;
|
||||
case 'D' :
|
||||
case 'D':
|
||||
oNeill.move(Direction.EAST);
|
||||
break;
|
||||
case 'X' :
|
||||
case 'X':
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '2' :
|
||||
case '2':
|
||||
System.out.println("Doboz felvétele");
|
||||
System.out.println("Elfogadott bemenet: L");
|
||||
switch (sc.nextLine().charAt(0)) {
|
||||
case 'L' :
|
||||
case 'L':
|
||||
oNeill.boxLift();
|
||||
break;
|
||||
case 'X' :
|
||||
case 'X':
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '3' :
|
||||
case '3':
|
||||
System.out.println("Doboz lerakása");
|
||||
System.out.println("Elfogadott bemenet: D");
|
||||
switch (sc.nextLine().charAt(0)) {
|
||||
case 'D':
|
||||
oNeill.boxDrop();
|
||||
break;
|
||||
case 'X' :
|
||||
case 'X':
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '4' :
|
||||
case '4':
|
||||
System.out.println("Elforgás");
|
||||
System.out.println("Elfogadott bemenet: L, R");
|
||||
switch (sc.nextLine().charAt(0)) {
|
||||
case 'L' :
|
||||
case 'L':
|
||||
oNeill.rotateLeft();
|
||||
break;
|
||||
case 'D' :
|
||||
case 'D':
|
||||
oNeill.rotateRight();
|
||||
break;
|
||||
case 'X' :
|
||||
case 'X':
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '5' :
|
||||
case '5':
|
||||
System.out.println("Nézés");
|
||||
System.out.println("Elfogadott bemenet: W");
|
||||
switch (sc.nextLine().charAt(0)) {
|
||||
case 'W' :
|
||||
case 'W':
|
||||
Tile t = oNeill.getCurrentTile().getAdjacentTile(oNeill.getFacingDirection());
|
||||
System.out.println("O'Neill előtt egy " + t.toString() + "mező található");
|
||||
break;
|
||||
case 'X' :
|
||||
case 'X':
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '6' :
|
||||
case '6':
|
||||
System.out.println("Csillagkapu lövés");
|
||||
System.out.println("Elfogadott bemenet: Y, B");
|
||||
Tile t = oNeill.getCurrentTile();
|
||||
switch (sc.nextLine().charAt(0)) {
|
||||
case 'Y' :
|
||||
case 'Y':
|
||||
t.spawnStargate(Stargate.yellowStargate, oNeill.getFacingDirection());
|
||||
break;
|
||||
case 'B' :
|
||||
case 'B':
|
||||
t.spawnStargate(Stargate.blueStargate, oNeill.getFacingDirection());
|
||||
break;
|
||||
case 'X' :
|
||||
case 'X':
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'X' :
|
||||
case 'X':
|
||||
System.out.println("Kilépés");
|
||||
isExiting = true;
|
||||
break;
|
||||
|
@ -1,5 +1,5 @@
|
||||
package cicaprojekt;
|
||||
|
||||
public interface Pickable extends Destroyable, Measurable {
|
||||
public void pick();
|
||||
public void pick();
|
||||
}
|
||||
|
@ -3,33 +3,32 @@ package cicaprojekt;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Player extends PlayerBase{
|
||||
private List<ZPM> zpmContainer;
|
||||
private Box boxLifted;
|
||||
public class Player extends PlayerBase {
|
||||
private List<ZPM> zpmContainer;
|
||||
private Box boxLifted;
|
||||
|
||||
|
||||
public Player(Tile startTile, Direction startDirection){
|
||||
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 */
|
||||
}
|
||||
currentTile = startTile;
|
||||
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).getABox();
|
||||
}
|
||||
}
|
||||
|
||||
public void boxDrop() {
|
||||
currentTile.getAdjacentTile(facingDirection).putABox(boxLifted);
|
||||
boxLifted = null;
|
||||
}
|
||||
public void boxDrop() {
|
||||
currentTile.getAdjacentTile(facingDirection).putABox(boxLifted);
|
||||
boxLifted = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pickZPM(Tile tile)
|
||||
{
|
||||
public void pickZPM(Tile tile) {
|
||||
zpmContainer.add(tile.getZPMFromTile());
|
||||
}
|
||||
|
||||
public void shootStargate(Stargate stargate) {
|
||||
this.currentTile.getAdjacentTile(facingDirection).spawnStargate(stargate, facingDirection);
|
||||
}
|
||||
this.currentTile.getAdjacentTile(facingDirection).spawnStargate(stargate, facingDirection);
|
||||
}
|
||||
}
|
||||
|
@ -1,69 +1,70 @@
|
||||
package cicaprojekt;
|
||||
|
||||
public class PlayerBase implements Destroyable{
|
||||
protected Game game;
|
||||
protected Tile currentTile;
|
||||
protected Direction facingDirection;
|
||||
public class PlayerBase implements Destroyable {
|
||||
protected Game game;
|
||||
protected Tile currentTile;
|
||||
protected Direction facingDirection;
|
||||
|
||||
|
||||
public void destroy() {}
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
public Tile getCurrentTile() {
|
||||
return currentTile;
|
||||
}
|
||||
public Tile getCurrentTile() {
|
||||
return currentTile;
|
||||
}
|
||||
|
||||
public void setCurrentTile(Tile newCurrentTile) {
|
||||
currentTile = newCurrentTile;
|
||||
}
|
||||
public void setCurrentTile(Tile newCurrentTile) {
|
||||
currentTile = newCurrentTile;
|
||||
}
|
||||
|
||||
public void move(Direction direction) {
|
||||
this.setFacingDirection(direction);
|
||||
Tile tile = this.getCurrentTile().getAdjacentTile(direction);
|
||||
tile.onEntry(this);
|
||||
setCurrentTile(tile);
|
||||
}
|
||||
public void move(Direction direction) {
|
||||
this.setFacingDirection(direction);
|
||||
Tile tile = this.getCurrentTile().getAdjacentTile(direction);
|
||||
tile.onEntry(this);
|
||||
setCurrentTile(tile);
|
||||
}
|
||||
|
||||
public void pickZPM(Tile tile) { /* PlayerBase does not collect ZPM modules */ }
|
||||
|
||||
public void rotateLeft() {
|
||||
switch (facingDirection) {
|
||||
case NORTH:
|
||||
facingDirection = Direction.WEST;
|
||||
break;
|
||||
case WEST:
|
||||
facingDirection = Direction.SOUTH;
|
||||
break;
|
||||
case SOUTH:
|
||||
facingDirection = Direction.EAST;
|
||||
break;
|
||||
case EAST:
|
||||
facingDirection = Direction.NORTH;
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void rotateLeft() {
|
||||
switch (facingDirection) {
|
||||
case NORTH:
|
||||
facingDirection = Direction.WEST;
|
||||
break;
|
||||
case WEST:
|
||||
facingDirection = Direction.SOUTH;
|
||||
break;
|
||||
case SOUTH:
|
||||
facingDirection = Direction.EAST;
|
||||
break;
|
||||
case EAST:
|
||||
facingDirection = Direction.NORTH;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void rotateRight() {
|
||||
switch (facingDirection) {
|
||||
case NORTH:
|
||||
facingDirection = Direction.EAST;
|
||||
break;
|
||||
case EAST:
|
||||
facingDirection = Direction.SOUTH;
|
||||
break;
|
||||
case SOUTH:
|
||||
facingDirection = Direction.WEST;
|
||||
break;
|
||||
case WEST:
|
||||
facingDirection = Direction.NORTH;
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void rotateRight() {
|
||||
switch (facingDirection) {
|
||||
case NORTH:
|
||||
facingDirection = Direction.EAST;
|
||||
break;
|
||||
case EAST:
|
||||
facingDirection = Direction.SOUTH;
|
||||
break;
|
||||
case SOUTH:
|
||||
facingDirection = Direction.WEST;
|
||||
break;
|
||||
case WEST:
|
||||
facingDirection = Direction.NORTH;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Direction getFacingDirection() {
|
||||
return facingDirection;
|
||||
}
|
||||
public Direction getFacingDirection() {
|
||||
return facingDirection;
|
||||
}
|
||||
|
||||
public void setFacingDirection(Direction direction) {
|
||||
facingDirection = direction;
|
||||
}
|
||||
public void setFacingDirection(Direction direction) {
|
||||
facingDirection = direction;
|
||||
}
|
||||
}
|
||||
|
@ -3,53 +3,53 @@ package cicaprojekt;
|
||||
import java.util.Stack;
|
||||
|
||||
public class Scale extends Field {
|
||||
private Gate gateConnected;
|
||||
private int threshold;
|
||||
private int weight;
|
||||
private Gate gateConnected;
|
||||
private int threshold;
|
||||
private int weight;
|
||||
|
||||
|
||||
public Scale(Gate gate, int threshold){
|
||||
gateConnected = gate;
|
||||
this.threshold = threshold;
|
||||
boxStack = new Stack<Box>();
|
||||
}
|
||||
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 onEntry(PlayerBase playerBase) {
|
||||
gateConnected.setOpen(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(PlayerBase playerBase) {
|
||||
gateConnected.setOpen(false);
|
||||
}
|
||||
@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 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();
|
||||
}
|
||||
@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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
private void stackChanged() {
|
||||
if (weight > threshold)
|
||||
gateConnected.setOpen(true);
|
||||
else
|
||||
gateConnected.setOpen(false);
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,38 @@
|
||||
package cicaprojekt;
|
||||
|
||||
public class Stargate {
|
||||
private boolean isSpawned;
|
||||
|
||||
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 Wall currentWall;
|
||||
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 boolean isSpawned;
|
||||
private Wall currentWall;
|
||||
|
||||
|
||||
private Stargate() {
|
||||
isSpawned = false;
|
||||
}
|
||||
private Stargate() {
|
||||
isSpawned = false;
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
yellowStargate.other = blueStargate;
|
||||
blueStargate.other = yellowStargate;
|
||||
redStargate.other = greenStargate;
|
||||
greenStargate.other = redStargate;
|
||||
}
|
||||
public static void init() {
|
||||
yellowStargate.other = blueStargate;
|
||||
blueStargate.other = yellowStargate;
|
||||
redStargate.other = greenStargate;
|
||||
greenStargate.other = redStargate;
|
||||
}
|
||||
|
||||
public Wall getCurrentWall() {
|
||||
return currentWall;
|
||||
}
|
||||
public Wall getCurrentWall() {
|
||||
return currentWall;
|
||||
}
|
||||
|
||||
public void setCurrentWall(Wall wall) {
|
||||
currentWall = wall;
|
||||
}
|
||||
public void setCurrentWall(Wall wall) {
|
||||
currentWall = wall;
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return isSpawned;
|
||||
}
|
||||
public boolean isOpen() {
|
||||
return isSpawned;
|
||||
}
|
||||
|
||||
public void teleport(Direction incomingDirection) {
|
||||
}
|
||||
public void teleport(Direction incomingDirection) {
|
||||
}
|
||||
}
|
||||
|
@ -5,48 +5,48 @@ import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
public abstract class Tile {
|
||||
protected Map<Direction, Tile> adjacentTile;
|
||||
protected ZPM zpmOnTile;
|
||||
protected Stack<Box> boxStack;
|
||||
protected Map<Direction, Tile> adjacentTile;
|
||||
protected ZPM zpmOnTile;
|
||||
protected Stack<Box> boxStack;
|
||||
|
||||
|
||||
public Tile(){
|
||||
adjacentTile = new HashMap<Direction, Tile>();
|
||||
}
|
||||
public Tile() {
|
||||
adjacentTile = new HashMap<Direction, Tile>();
|
||||
}
|
||||
|
||||
public Tile getAdjacentTile(Direction direction) {
|
||||
return adjacentTile.get(direction);
|
||||
}
|
||||
public Tile getAdjacentTile(Direction direction) {
|
||||
return adjacentTile.get(direction);
|
||||
}
|
||||
|
||||
public void setAdajacentTile(Tile newTile, Direction direction) {
|
||||
adjacentTile.put(direction, newTile);
|
||||
}
|
||||
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(PlayerBase playerBase);
|
||||
public abstract void onEntry(PlayerBase playerBase);
|
||||
|
||||
public abstract void onExit(PlayerBase playerBase);
|
||||
public abstract void onExit(PlayerBase playerBase);
|
||||
|
||||
public void setZPMOnTile(ZPM zpm) {
|
||||
zpmOnTile = zpm;
|
||||
}
|
||||
public void setZPMOnTile(ZPM zpm) {
|
||||
zpmOnTile = zpm;
|
||||
}
|
||||
|
||||
public ZPM getZPMFromTile() {
|
||||
ZPM zpm = zpmOnTile;
|
||||
zpmOnTile = null;
|
||||
return zpm;
|
||||
}
|
||||
public ZPM getZPMFromTile() {
|
||||
ZPM zpm = zpmOnTile;
|
||||
zpmOnTile = null;
|
||||
return zpm;
|
||||
}
|
||||
|
||||
public void putABox(Box box) {
|
||||
if(box == null)
|
||||
return;
|
||||
boxStack.push(box);
|
||||
}
|
||||
public void putABox(Box box) {
|
||||
if (box == null)
|
||||
return;
|
||||
boxStack.push(box);
|
||||
}
|
||||
|
||||
public Box getABox(){
|
||||
if(boxStack.isEmpty())
|
||||
return null;
|
||||
return boxStack.pop();
|
||||
}
|
||||
public Box getABox() {
|
||||
if (boxStack.isEmpty())
|
||||
return null;
|
||||
return boxStack.pop();
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +1,32 @@
|
||||
package cicaprojekt;
|
||||
|
||||
public class Wall extends Tile {
|
||||
private Stargate sg;
|
||||
private Stargate sg;
|
||||
|
||||
public Wall(){
|
||||
super();
|
||||
}
|
||||
public Wall() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void spawnStargate(Stargate stargate, Direction direction) {
|
||||
if(sg == null)
|
||||
sg = stargate;
|
||||
else
|
||||
return;
|
||||
}
|
||||
public void spawnStargate(Stargate stargate, Direction direction) {
|
||||
if (sg == null)
|
||||
sg = stargate;
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
public void clearStargate() {
|
||||
sg = null;
|
||||
}
|
||||
public void clearStargate() {
|
||||
sg = null;
|
||||
}
|
||||
|
||||
public void onEntry(PlayerBase playerBase) {
|
||||
if(sg == null) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
sg.teleport(playerBase.facingDirection);
|
||||
}
|
||||
}
|
||||
public void onEntry(PlayerBase playerBase) {
|
||||
if (sg == null) {
|
||||
return;
|
||||
} else {
|
||||
sg.teleport(playerBase.facingDirection);
|
||||
}
|
||||
}
|
||||
|
||||
public void onExit(PlayerBase playerBase) throws IllegalStateException {
|
||||
throw new IllegalStateException("Hiba! Te hogy kerültél a falba?");
|
||||
}
|
||||
public void onExit(PlayerBase playerBase) throws IllegalStateException {
|
||||
throw new IllegalStateException("Hiba! Te hogy kerültél a falba?");
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,15 @@
|
||||
package cicaprojekt;
|
||||
|
||||
public class ZPM implements Pickable
|
||||
{
|
||||
public void pick(){
|
||||
}
|
||||
public class ZPM implements Pickable {
|
||||
public void pick() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy(){
|
||||
}
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int weight() {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int weight() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user