f6bef6fdde
Or at least attemted to
66 lines
2.0 KiB
Java
66 lines
2.0 KiB
Java
package cicaprojekt;
|
|
|
|
public class Stargate {
|
|
public static final Stargate yellowStargate = new Stargate("Yellow Stargate");
|
|
public static final Stargate blueStargate = new Stargate("Blue Stargate");
|
|
public static final Stargate redStargate = new Stargate("Red Stargate");
|
|
public static final Stargate greenStargate = new Stargate("Green Stargate");
|
|
public /*final*/ Stargate other; //TODO find better ways to do this
|
|
private boolean isSpawned;
|
|
private Wall currentWall;
|
|
private String name;
|
|
|
|
|
|
private Stargate(String name) {
|
|
isSpawned = false;
|
|
this.name = name;
|
|
}
|
|
|
|
public static void init() {
|
|
yellowStargate.other = blueStargate;
|
|
blueStargate.other = yellowStargate;
|
|
redStargate.other = greenStargate;
|
|
greenStargate.other = redStargate;
|
|
}
|
|
|
|
public Wall getCurrentWall() {
|
|
return currentWall;
|
|
}
|
|
|
|
public void setCurrentWall(Wall wall) {
|
|
currentWall = wall;
|
|
if(wall != null) {
|
|
isSpawned = true;
|
|
}
|
|
else {
|
|
isSpawned = false;
|
|
}
|
|
}
|
|
|
|
public boolean isOpen() {
|
|
return isSpawned & other.isSpawned;
|
|
}
|
|
|
|
private Direction getExitDirection() {
|
|
if(currentWall.getAdjacentTile(Direction.EAST) == null)
|
|
return Direction.WEST;
|
|
else if(currentWall.getAdjacentTile(Direction.WEST) == null)
|
|
return Direction.EAST;
|
|
else if(currentWall.getAdjacentTile(Direction.NORTH) == null)
|
|
return Direction.SOUTH;
|
|
else
|
|
return Direction.NORTH;
|
|
}
|
|
|
|
public void teleport(PlayerBase player) {
|
|
player.setCurrentTile(other.getCurrentWall().getAdjacentTile(getExitDirection()));
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
if(isSpawned)
|
|
return String.format("%s: %s", name, currentWall);
|
|
else return String.format("%s: not spawned", name, currentWall);
|
|
}
|
|
}
|