cf52cb6cba
startGame now adds Players and Replicator to Display.
94 lines
2.4 KiB
Java
94 lines
2.4 KiB
Java
package cicaprojekt;
|
|
|
|
import java.awt.*;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.util.Map;
|
|
import java.util.Random;
|
|
|
|
public class Game {
|
|
private Player oneill;
|
|
private Player jaffa;
|
|
|
|
private PlayerBase replicator;
|
|
|
|
private Dungeon dungeon;
|
|
private Random random;
|
|
private FlowOfTime flowoftime;
|
|
|
|
private Display display;
|
|
|
|
public static Game instance = new Game();
|
|
|
|
private Game() {
|
|
random = new Random();
|
|
flowoftime = new FlowOfTime();
|
|
}
|
|
|
|
public void setDungeon(Dungeon dungeon) {
|
|
this.dungeon = dungeon;
|
|
}
|
|
|
|
public void setDisplay(Display display) {
|
|
this.display = display;
|
|
}
|
|
|
|
public void allZPMsCollected(GameoverCause cause) {
|
|
this.stopGame(cause);
|
|
}
|
|
|
|
public void startGame(File dungeonFile) throws IOException {
|
|
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());
|
|
|
|
display.addVisual(new PlayerDrawer(oneill));
|
|
display.addVisual(new PlayerDrawer(jaffa));
|
|
display.addVisual(new PlayerBaseDrawer(replicator));
|
|
|
|
flowoftime.start(420*420);
|
|
}
|
|
|
|
private Direction getRandomDirection() {
|
|
return Direction.values()[random.nextInt(Direction.values().length)];
|
|
}
|
|
|
|
public void stopGame(GameoverCause cause) {
|
|
}
|
|
|
|
public void moveONeill(Direction direction) {
|
|
oneill.move(direction);
|
|
}
|
|
|
|
public void moveJaffa(Direction direction) {
|
|
jaffa.move(direction);
|
|
}
|
|
|
|
public void boxONeill() {
|
|
if(oneill.hasBox())
|
|
oneill.boxDrop();
|
|
else
|
|
oneill.boxLift();
|
|
}
|
|
|
|
public void boxJaffa() {
|
|
if(jaffa.hasBox())
|
|
jaffa.boxDrop();
|
|
else
|
|
jaffa.boxLift();
|
|
}
|
|
|
|
public void shootStargate(Color color) {
|
|
if(color == Color.YELLOW || color == Color.BLUE)
|
|
oneill.shootStargate(Stargate.get(color));
|
|
else
|
|
jaffa.shootStargate(Stargate.get(color));
|
|
}
|
|
|
|
public void updateDisplay() {
|
|
}
|
|
}
|