X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavecraft%2Fgame%2FGameSaver.java;h=5f8743dc8710a3f054b597fea29a9be5a19e6538;hb=ad90ec91a8a5a0b4ad7ada5692fe427a57ecb062;hp=070b5c24009524548980c60dee82cb0a86328930;hpb=6ab2a53526f16de139d39a59c3d800e5f3013c68;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java b/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java index 070b5c2..5f8743d 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java @@ -3,136 +3,110 @@ package ru.deadsoftware.cavecraft.game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; import ru.deadsoftware.cavecraft.CaveGame; -import ru.deadsoftware.cavecraft.Items; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; +import java.io.*; import java.nio.ByteBuffer; public class GameSaver { private static final int VERSION = 0; - private static int[][] fMap, bMap; - private static int readIndex; - - private static int bytesInt(byte[] bytes) { - ByteBuffer wrapped = ByteBuffer.wrap(bytes); - int res = wrapped.getInt(readIndex); - readIndex+=4; - return res; + private static byte[] intToBytes(int i) { + return ByteBuffer.allocate(4).putInt(i).array(); } - private static void writeInt(FileHandle file, int i, boolean append) { - byte[] bytes = ByteBuffer.allocate(4).putInt(i).array(); - file.writeBytes(bytes, append); - } - - private static void saveMap(FileHandle file, int[][] map) { - int rl,bl; + private static void saveMap(FileHandle file, int[][] map) throws IOException { + int rl, bl; int width = map.length; int height = map[0].length; - writeInt(file, VERSION, false); - writeInt(file, width, true); - writeInt(file, height, true); - for (int y=0; y