blob: b4f2d681e6b17234ea2cd58d3683fb09d57e3d87 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.fourisland.fourpuzzle;
import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.HashMap;
/**
*
* @author hatkirby
*/
public class SaveFile implements Serializable {
/**
* Creates a new SaveFile
* @throws java.lang.CloneNotSupportedException
*/
public SaveFile() throws CloneNotSupportedException
{
switches = new HashMap<String, Boolean>();
party = GameCharacters.INSTANCE.newInstance();
variables = new HashMap<String, Integer>();
currentMap = new String();
hero = new HeroEvent();
}
/**
* Loads a SaveFile
* @param file The ID of the SaveFile to load
* @throws java.io.IOException
* @throws java.lang.ClassNotFoundException
*/
public SaveFile(int file) throws IOException, ClassNotFoundException
{
InputStream is = PuzzleApplication.INSTANCE.getContext().getLocalStorage().openInputFile("Save" + file + ".sav");
ObjectInputStream ois = new ObjectInputStream(is);
SaveFile temp = (SaveFile) ois.readObject();
switches = temp.getSwitches();
variables = temp.getVariables();
party = temp.getParty();
currentMap = temp.getCurrentMap();
ois.close();
}
public void saveGame(int file) throws IOException
{
OutputStream os = PuzzleApplication.INSTANCE.getContext().getLocalStorage().openOutputFile("Save" + file + ".sav");
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(this);
oos.close();
}
private HashMap<String, Boolean> switches;
public HashMap<String, Boolean> getSwitches() {
return switches;
}
private GameCharacters party;
public GameCharacters getParty() {
return party;
}
private HashMap<String, Integer> variables;
public HashMap<String, Integer> getVariables() {
return variables;
}
private String currentMap;
public String getCurrentMap()
{
return currentMap;
}
public void setCurrentMap(String currentMap)
{
this.currentMap = currentMap;
}
private HeroEvent hero;
public HeroEvent getHero()
{
return hero;
}
public void setHero(HeroEvent hero)
{
this.hero = hero;
}
}
|