cicaprojekt/cicaprojekt/Stargate.java
2016-05-07 17:45:06 +02:00

85 lines
2.5 KiB
Java

package cicaprojekt;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;
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 static Map<Color, Stargate> stargates = new HashMap<>();
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;
stargates.put(Color.YELLOW, yellowStargate);
stargates.put(Color.BLUE, blueStargate);
stargates.put(Color.RED, redStargate);
stargates.put(Color.GREEN, greenStargate);
}
public static Stargate get(Color color) {
return stargates.get(color);
}
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);
}
public String getName() {
return name;
}
}