summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/SaveControl.java
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-06-07 21:51:20 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-06-07 21:51:20 +0200
commit8b763a817b21aff45d704940ad2e17799dc7bb43 (patch)
treedc797106eff544419b3be18df01e7335f3a1ffb0 /src/jrummikub/control/SaveControl.java
parent244abb7e7320355d0c4aad4a7ba267f11d358563 (diff)
downloadJRummikub-8b763a817b21aff45d704940ad2e17799dc7bb43.tar
JRummikub-8b763a817b21aff45d704940ad2e17799dc7bb43.zip
Saving is working
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@382 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/control/SaveControl.java')
-rw-r--r--src/jrummikub/control/SaveControl.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/jrummikub/control/SaveControl.java b/src/jrummikub/control/SaveControl.java
new file mode 100644
index 0000000..458c0dc
--- /dev/null
+++ b/src/jrummikub/control/SaveControl.java
@@ -0,0 +1,81 @@
+package jrummikub.control;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.ObjectOutputStream;
+
+import jrummikub.model.GameSettings;
+import jrummikub.model.GameState;
+import jrummikub.model.IRoundState;
+import jrummikub.util.IListener1;
+import jrummikub.view.IView;
+
+/**
+ * The save control is responsible for loading and saving game and round states
+ */
+public class SaveControl {
+ private GameSettings gameSettings;
+ private GameState gameState;
+ private IRoundState roundState;
+
+ /**
+ * Creates a new SaveControl
+ *
+ * @param view
+ * the view to use
+ */
+ public SaveControl(IView view) {
+ view.getSaveEvent().add(new IListener1<File>() {
+ @Override
+ public void handle(File file) {
+ save(file);
+ }
+ });
+ }
+
+ /**
+ * Sets the current game settings
+ *
+ * @param gameSettings
+ * the game settings
+ */
+ public void setGameSettings(GameSettings gameSettings) {
+ this.gameSettings = gameSettings;
+ }
+
+ /**
+ * Sets the current game state
+ *
+ * @param gameState
+ * the game state
+ */
+ public void setGameState(GameState gameState) {
+ this.gameState = gameState;
+ }
+
+ /**
+ * Sets the current round state
+ *
+ * @param roundState
+ * the round state
+ */
+ public void setRoundState(IRoundState roundState) {
+ this.roundState = roundState;
+ }
+
+ private void save(File file) {
+ try {
+ ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(
+ file));
+
+ stream.writeObject(gameSettings);
+ stream.writeObject(gameState);
+ stream.writeObject(roundState);
+ stream.flush();
+
+ stream.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}