diff options
| author | ilotterytea <iltsu@alright.party> | 2022-08-31 03:10:51 +0600 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2022-08-31 03:10:51 +0600 |
| commit | a733599d283222fb5f335b28254e1f7ade2a7a4d (patch) | |
| tree | 31c611a99697dcfbe9838e8956fa5154182c7649 | |
| parent | 3acdc15753d6f64d3c758b95521b8e3ab7f5ee8c (diff) | |
save & load game system
| -rw-r--r-- | core/src/com/ilotterytea/maxoning/utils/serialization/GameDataSystem.java | 30 |
1 files changed, 30 insertions, 0 deletions
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; + } +} |
