refactored Game.getRandomDirection() to Direction.getRandom()

This commit is contained in:
Kjistóf 2016-05-13 22:00:06 +02:00
parent 5db401d2ab
commit 4aa307a254
2 changed files with 13 additions and 7 deletions

View File

@ -1,5 +1,7 @@
package cicaprojekt;
import java.util.Random;
public enum Direction {
NORTH, SOUTH, EAST, WEST;
@ -17,4 +19,8 @@ public enum Direction {
return NORTH;
}
}
public static Direction getRandom() {
return Direction.values()[new Random().nextInt(Direction.values().length)];
}
}

View File

@ -41,9 +41,9 @@ public class Game {
Stargate.init();
Map<String, Tile> players = dungeon.buildDungeon(dungeonFile, display);
oneill = new Player("O'Neill", players.get("oneill"), getRandomDirection());
jaffa = new Player("Jaffa", players.get("jaffa"), getRandomDirection());
replicator = new PlayerBase("Replicator", players.get("replicator"), getRandomDirection());
oneill = new Player("O'Neill", players.get("oneill"), Direction.getRandom());
jaffa = new Player("Jaffa", players.get("jaffa"), Direction.getRandom());
replicator = new PlayerBase("Replicator", players.get("replicator"), Direction.getRandom());
display.addVisual(new PlayerDrawer(oneill));
display.addVisual(new PlayerDrawer(jaffa));
@ -53,10 +53,6 @@ public class Game {
flowoftime.start(dungeon.getTimeLimit());
}
private Direction getRandomDirection() {
return Direction.values()[random.nextInt(Direction.values().length)];
}
public void stopGame(GameoverCause cause) {
switch (cause){
@ -92,6 +88,10 @@ public class Game {
checkZPMStatus();
}
public void moveReplicator(Direction direction) {
replicator.move(direction);
}
public void rotateOneillLeft() {
oneill.rotateLeft();
}