cicaprojekt/cicaprojekt/Stargate.java

90 lines
2.5 KiB
Java
Raw Normal View History

package cicaprojekt;
2016-05-07 15:40:30 +00:00
import java.awt.*;
import java.util.HashMap;
import java.util.Map;
public class Stargate {
2016-04-25 19:33:07 +00:00
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");
2016-05-13 15:13:01 +00:00
public Stargate other;
2016-04-24 21:01:34 +00:00
private boolean isSpawned;
private Wall currentWall;
private Direction exitDirection;
2016-04-25 19:33:07 +00:00
private String name;
2016-04-24 21:01:34 +00:00
2016-05-07 15:40:30 +00:00
private static Map<Color, Stargate> stargates = new HashMap<>();
2016-04-24 21:01:34 +00:00
2016-04-25 19:33:07 +00:00
private Stargate(String name) {
2016-04-24 21:01:34 +00:00
isSpawned = false;
2016-04-25 19:33:07 +00:00
this.name = name;
2016-04-24 21:01:34 +00:00
}
public static void init() {
yellowStargate.other = blueStargate;
blueStargate.other = yellowStargate;
redStargate.other = greenStargate;
greenStargate.other = redStargate;
2016-05-07 15:40:30 +00:00
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);
2016-04-24 21:01:34 +00:00
}
public Wall getCurrentWall() {
return currentWall;
}
public void setCurrentWall(Wall wall, Direction direction) {
2016-04-24 21:01:34 +00:00
currentWall = wall;
if(direction != null)
exitDirection = Direction.invert(direction);
if(wall != null) {
isSpawned = true;
}
else {
isSpawned = false;
}
2016-04-24 21:01:34 +00:00
}
2016-05-13 17:15:28 +00:00
public boolean isSpawned() {
return isSpawned;
}
2016-04-24 21:01:34 +00:00
public boolean isOpen() {
if(isSpawned & other.isSpawned)
return other.getCurrentWall().getAdjacentTile(other.getExitDirection()).isSteppable();
return false;
2016-04-24 21:01:34 +00:00
}
2016-04-25 20:16:18 +00:00
private Direction getExitDirection() {
return exitDirection;
2016-04-25 20:16:18 +00:00
}
public void teleport(PlayerBase player) {
if(isOpen())
player.setCurrentTile(other.getCurrentWall().getAdjacentTile(other.getExitDirection()));
else
player.setCurrentTile(this.getCurrentWall());
2016-04-24 21:01:34 +00:00
}
2016-04-25 19:33:07 +00:00
@Override
public String toString() {
if(isSpawned)
return String.format("%s: %s", name, currentWall);
else return String.format("%s: not spawned", name, currentWall);
2016-04-25 19:33:07 +00:00
}
public String getName() {
return name;
}
}