fixed replay + some other fixes

This commit is contained in:
BetaSteward 2011-03-18 18:27:01 -04:00
parent ff3e0108cd
commit 35f0767f1b
24 changed files with 218 additions and 187 deletions

View file

@ -28,7 +28,17 @@
package mage.server.game;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInput;
import java.util.UUID;
import java.util.zip.GZIPInputStream;
import mage.game.*;
import mage.server.Main;
import mage.util.CopierObjectInputStream;
import org.apache.log4j.Logger;
/**
*
@ -36,13 +46,15 @@ import mage.game.*;
*/
public class GameReplay {
private final static Logger logger = Logger.getLogger(GameReplay.class);
private GameStates savedGame;
private Game game;
private int stateIndex;
public GameReplay(Game game) {
public GameReplay(UUID gameId) {
this.game = loadGame(gameId);
this.savedGame = game.getGameStates();
this.game = game;
}
public void start() {
@ -66,4 +78,29 @@ public class GameReplay {
public Game getGame() {
return this.game;
}
private Game loadGame(UUID gameId) {
try{
InputStream file = new FileInputStream("saved/" + gameId.toString() + ".game");
InputStream buffer = new BufferedInputStream(file);
ObjectInput input = new CopierObjectInputStream(Main.classLoader, new GZIPInputStream(buffer));
try {
Game loadGame = (Game)input.readObject();
GameStates states = (GameStates)input.readObject();
loadGame.loadGameStates(states);
return loadGame;
}
finally {
input.close();
}
}
catch(ClassNotFoundException ex) {
logger.fatal("Cannot load game. Class not found.", ex);
}
catch(IOException ex) {
logger.fatal("Cannot load game:" + gameId, ex);
}
return null;
}
}