Package com.jcloisterzone.game

Examples of com.jcloisterzone.game.Snapshot


    }

    private void autosave() {
        DebugConfig debugConfig = game.getConfig().getDebug();
        if (debugConfig != null && debugConfig.getAutosave() != null && debugConfig.getAutosave().length() > 0) {
            Snapshot snapshot = new Snapshot(game);
            if ("plain".equals(debugConfig.getSave_format())) {
                snapshot.setGzipOutput(false);
            }
            try {
                snapshot.save(new FileOutputStream(debugConfig.getAutosave()));
            } catch (TransformerException | IOException e) {
                logger.error("Auto save before ranking failed.", e);
            }
        }
    }
View Full Code Here


        }
    }

    //TODO is there faster game copying without snapshot? or without re-creating board and tile instances
    protected Game copyGame(Object gameListener) {
        Snapshot snapshot = new Snapshot(game);
        Game copy = snapshot.asGame(game.getGameId());
        copy.setConfig(game.getConfig());
        copy.getEventBus().register(gameListener);
        LoadGamePhase phase = new LoadGamePhase(copy, snapshot, getConnection());
        phase.setSlots(new PlayerSlot[0]);
        copy.getPhases().put(phase.getClass(), phase);
View Full Code Here

        for (Capability cap : game.getCapabilities()) {
            backups[i++] = cap.backup();
        }
        SavePoint sp = new SavePoint(operations.peekLast(), game.getPhase(), backups);
        if (DEBUG_VERIFY_SAVE_POINT) {
            sp.setSnapshot(new Snapshot(game));
        }
        return sp;
    }
View Full Code Here

        phase.setEntered(true);
        game.getEventBus().register(operationRecorder);

        if (DEBUG_VERIFY_SAVE_POINT) {
            try {
                String sRestore = new Snapshot(game).saveToString();
                String sSave = sp.getSnapshot().saveToString();
                if (!sSave.equals(sRestore)) {
                    System.err.println("--- saved save point---");
                    System.err.println(sSave);
                    System.err.println("--- doesn't match restored saved point ---");
View Full Code Here

        }
        zos.closeEntry();

        ze = new ZipEntry("savegame.jcz");
        zos.putNextEntry(ze);
        Snapshot snapshot = new Snapshot(game);
        snapshot.save(zos, false, false);
        zos.closeEntry();

        if (container != null) {
            ze = new ZipEntry("board.png");
            zos.putNextEntry(ze);
View Full Code Here

        for (String s : events) {
            out.println(s);
        }

        out.println("---------- save ------------");
        Snapshot snapshot = new Snapshot(game);
        snapshot.setGzipOutput(false);
        out.println(snapshot.saveToString());

        out.println("---------- system env ------------");
        out.println(System.getProperty("java.version"));
    }
View Full Code Here

    }

    protected EventCatchingGame createGame(String save) {
        try {
            URI uri = getClass().getResource(save).toURI();
            Snapshot snapshot = new Snapshot(new File(uri));
            EventCatchingGame game = (EventCatchingGame) snapshot.asGame(new EventCatchingGame());
            game.setConfig(new Config());
            LoadGamePhase phase = new LoadGamePhase(game, snapshot, null);
            game.getPhases().put(phase.getClass(), phase);
            game.setPhase(phase);
            phase.setSlots(new PlayerSlot[0]);
View Full Code Here

    }

    protected String snapshotGame(Game game) {
        try {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            Snapshot snapshot = new Snapshot(game);
            snapshot.setGzipOutput(false);
            snapshot.save(os);
            return os.toString("utf-8");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

            CreateGamePhase phase = (CreateGamePhase)game.getPhase();
            phase.startGame();
            return;
        }
        CreateGamePhase phase;
        Snapshot snapshot = null;
        if (msg.getSnapshot() != null) {
            try {
                snapshot = new Snapshot(msg.getSnapshot());
            } catch (IOException e) {
                logger.error(e.getMessage(), e);
                return;
            }
        }

        if (snapshot == null) {
            game = new Game(msg.getGameId());
            phase = new CreateGamePhase(game, conn);
        } else {
            game = snapshot.asGame(msg.getGameId());
            phase = new LoadGamePhase(game, snapshot, conn);
        }
        game.setConfig(client.getConfig());

        final PlayerSlot[] slots = new PlayerSlot[PlayerSlot.COUNT];
View Full Code Here

            if (file != null) {
                if (!file.getName().endsWith(".jcz")) {
                    file = new File(file.getAbsolutePath() + ".jcz");
                }
                try {
                    Snapshot snapshot = new Snapshot(game);
                    DebugConfig debugConfig = getConfig().getDebug();
                    if (debugConfig != null && "plain".equals(debugConfig.getSave_format())) {
                        snapshot.setGzipOutput(false);
                    }
                    snapshot.save(new FileOutputStream(file));
                } catch (IOException | TransformerException ex) {
                    logger.error(ex.getMessage(), ex);
                    JOptionPane.showMessageDialog(this, ex.getLocalizedMessage(), _("Error"), JOptionPane.ERROR_MESSAGE);
                }
            }
View Full Code Here

TOP

Related Classes of com.jcloisterzone.game.Snapshot

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.