69 lines
1.6 KiB
Java
69 lines
1.6 KiB
Java
package letzplay.ganttproject;
|
|
|
|
import letzplay.core.GameLoop;
|
|
import letzplay.core.Output;
|
|
|
|
import java.io.*;
|
|
import java.util.ArrayList;
|
|
|
|
public class GanttGameLoop implements GameLoop {
|
|
|
|
private static GanttGameLoop instance = null;
|
|
|
|
private GanttGameLoop() {
|
|
}
|
|
|
|
public static GanttGameLoop getGameLoop() {
|
|
if (instance == null) {
|
|
instance = new GanttGameLoop();
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
@Override
|
|
public void init() {
|
|
game.initQuests(GanttProject.init());
|
|
}
|
|
|
|
@Override
|
|
public void input(String trigger) {
|
|
System.out.println("Trigger: "+trigger);
|
|
game.trigger(trigger);
|
|
}
|
|
|
|
@Override
|
|
public void update() {
|
|
game.update();
|
|
}
|
|
|
|
@Override
|
|
public Output output() {
|
|
//System.out.println(game.toString());
|
|
return new Output(game.availableQuests(), game.currentLvl(),
|
|
game.currentExp());
|
|
}
|
|
|
|
@Override
|
|
public void save() throws IOException {
|
|
FileOutputStream writeData = new FileOutputStream("gamedata.ser");
|
|
ObjectOutputStream writeStream = new ObjectOutputStream(writeData);
|
|
|
|
writeStream.writeObject(game.getState());
|
|
writeStream.flush();
|
|
writeStream.close();
|
|
}
|
|
|
|
@Override
|
|
public void load() throws IOException, ClassNotFoundException {
|
|
FileInputStream readData = new FileInputStream("gamedata.ser");
|
|
ObjectInputStream readStream = new ObjectInputStream(readData);
|
|
|
|
ArrayList<String> data = (ArrayList<String >) readStream.readObject();
|
|
readStream.close();
|
|
|
|
for (String s:data) {
|
|
input(s);
|
|
}
|
|
}
|
|
}
|