cicaprojekt/cicaprojekt/Game.java

118 lines
2.9 KiB
Java

package cicaprojekt;
import javax.swing.*;
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 rotateOneillLeft() {
oneill.rotateLeft();
}
public void rotateOneillRight() {
oneill.rotateRight();
}
public void rotateJaffaLeft() {
jaffa.rotateLeft();
}
public void rotateJaffaRight() {
jaffa.rotateRight();
}
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() {
try {
display.drawVisuals();
display.repaint();
}
catch (IOException e) {
Control.ioErrorMessage();
}
}
}