From a733599d283222fb5f335b28254e1f7ade2a7a4d Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 31 Aug 2022 03:10:51 +0600 Subject: save & load game system --- .../utils/serialization/GameDataSystem.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 core/src/com/ilotterytea/maxoning/utils/serialization/GameDataSystem.java (limited to 'core/src/com/ilotterytea') diff --git a/core/src/com/ilotterytea/maxoning/utils/serialization/GameDataSystem.java b/core/src/com/ilotterytea/maxoning/utils/serialization/GameDataSystem.java new file mode 100644 index 0000000..c2282cf --- /dev/null +++ b/core/src/com/ilotterytea/maxoning/utils/serialization/GameDataSystem.java @@ -0,0 +1,30 @@ +package com.ilotterytea.maxoning.utils.serialization; + +import com.ilotterytea.maxoning.player.MaxonPlayer; + +import java.io.*; + +public class GameDataSystem { + private static final File file = new File(System.getProperty("user.home") + "/MaxoningSavegame.sav"); + + public static boolean exists() { return file.exists(); } + + public static void SaveData(MaxonPlayer player) throws IOException { + FileOutputStream fo = new FileOutputStream(file); + ObjectOutputStream out = new ObjectOutputStream(fo); + + out.writeObject(player); + out.close(); + } + + public static MaxonPlayer LoadData() throws IOException, ClassNotFoundException { + FileInputStream fi = new FileInputStream(file); + ObjectInputStream oi = new ObjectInputStream(fi); + + MaxonPlayer pl = (MaxonPlayer) oi.readObject(); + + oi.close(); + fi.close(); + return pl; + } +} -- cgit v1.2.3