diff options
-rw-r--r-- | src/esieequest/controller/commands/Command.java | 1 | ||||
-rw-r--r-- | src/esieequest/controller/commands/LoadCommand.java | 17 | ||||
-rw-r--r-- | src/esieequest/controller/commands/SaveCommand.java | 11 | ||||
-rw-r--r-- | src/esieequest/view/Viewable.java | 25 | ||||
-rw-r--r-- | src/esieequest/view/app/UserInterface.java | 63 | ||||
-rw-r--r-- | src/esieequest/view/text/TextInterface.java | 34 | ||||
-rw-r--r-- | src/esieequest/view/web/WebInterface.java | 41 |
7 files changed, 180 insertions, 12 deletions
diff --git a/src/esieequest/controller/commands/Command.java b/src/esieequest/controller/commands/Command.java index a29b79b..906a312 100644 --- a/src/esieequest/controller/commands/Command.java +++ b/src/esieequest/controller/commands/Command.java | |||
@@ -24,6 +24,7 @@ public enum Command { | |||
24 | QUIT(new QuitCommand()), | 24 | QUIT(new QuitCommand()), |
25 | HELP(new HelpCommand()), | 25 | HELP(new HelpCommand()), |
26 | ALEA(new AleaCommand()), | 26 | ALEA(new AleaCommand()), |
27 | SOUND(new NewCommand()), | ||
27 | 28 | ||
28 | // map related | 29 | // map related |
29 | GO(new GoCommand()), | 30 | GO(new GoCommand()), |
diff --git a/src/esieequest/controller/commands/LoadCommand.java b/src/esieequest/controller/commands/LoadCommand.java index 896d85b..26e18e2 100644 --- a/src/esieequest/controller/commands/LoadCommand.java +++ b/src/esieequest/controller/commands/LoadCommand.java | |||
@@ -18,7 +18,16 @@ public class LoadCommand implements Executable { | |||
18 | @Override | 18 | @Override |
19 | public void execute(final String argument, final Game game, final Viewable view) { | 19 | public void execute(final String argument, final Game game, final Viewable view) { |
20 | 20 | ||
21 | final String jsonString = argument; | 21 | if (argument == null) { |
22 | return; | ||
23 | } | ||
24 | |||
25 | final String jsonString; | ||
26 | if (argument.startsWith("{")) { | ||
27 | jsonString = argument; | ||
28 | } else { | ||
29 | jsonString = view.load(argument); | ||
30 | } | ||
22 | 31 | ||
23 | JSONObject datas = new JSONObject(); | 32 | JSONObject datas = new JSONObject(); |
24 | try { | 33 | try { |
@@ -39,12 +48,12 @@ public class LoadCommand implements Executable { | |||
39 | return; | 48 | return; |
40 | } | 49 | } |
41 | 50 | ||
42 | // view.updateQuest(); | 51 | view.enableInput(); |
43 | // view.updateInventory(game.getPlayer().getItems()); | 52 | view.updateQuest(game.getPlayer().getCurrentQuest()); |
53 | view.updateInventory(game.getPlayer().getInventory()); | ||
44 | view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer() | 54 | view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer() |
45 | .getCurrentDirection(), game.getPlayer().getCurrentSide(), game.getPlayer() | 55 | .getCurrentDirection(), game.getPlayer().getCurrentSide(), game.getPlayer() |
46 | .canGoBack()); | 56 | .canGoBack()); |
47 | 57 | ||
48 | } | 58 | } |
49 | |||
50 | } | 59 | } |
diff --git a/src/esieequest/controller/commands/SaveCommand.java b/src/esieequest/controller/commands/SaveCommand.java index 9e32762..3332059 100644 --- a/src/esieequest/controller/commands/SaveCommand.java +++ b/src/esieequest/controller/commands/SaveCommand.java | |||
@@ -13,7 +13,16 @@ public class SaveCommand implements Executable { | |||
13 | @Override | 13 | @Override |
14 | public void execute(final String argument, final Game game, final Viewable view) { | 14 | public void execute(final String argument, final Game game, final Viewable view) { |
15 | 15 | ||
16 | view.echo(game.serialise().toJSONString()); | 16 | if (argument == null) { |
17 | return; | ||
18 | } | ||
19 | |||
20 | if (argument.isEmpty()) { | ||
21 | return; | ||
22 | } | ||
23 | |||
24 | final String serialisedGame = game.serialise().toJSONString(); | ||
25 | view.save(argument, serialisedGame); | ||
17 | 26 | ||
18 | } | 27 | } |
19 | 28 | ||
diff --git a/src/esieequest/view/Viewable.java b/src/esieequest/view/Viewable.java index fa53e1a..c650759 100644 --- a/src/esieequest/view/Viewable.java +++ b/src/esieequest/view/Viewable.java | |||
@@ -88,4 +88,29 @@ public interface Viewable { | |||
88 | */ | 88 | */ |
89 | public void stopMusic(); | 89 | public void stopMusic(); |
90 | 90 | ||
91 | /** | ||
92 | * Toggles the sound. | ||
93 | */ | ||
94 | public void toggleSound(); | ||
95 | |||
96 | /** | ||
97 | * Loads a saved game file. | ||
98 | * | ||
99 | * @param path | ||
100 | * the path of the file | ||
101 | * | ||
102 | * @return the serialised Game | ||
103 | */ | ||
104 | public String load(final String path); | ||
105 | |||
106 | /** | ||
107 | * Saves a game as a file. | ||
108 | * | ||
109 | * @param path | ||
110 | * the path of the file | ||
111 | * @param serialisedGame | ||
112 | * the serialised Game | ||
113 | */ | ||
114 | public void save(final String path, final String serialisedGame); | ||
115 | |||
91 | } | 116 | } |
diff --git a/src/esieequest/view/app/UserInterface.java b/src/esieequest/view/app/UserInterface.java index 0f426bd..b00673c 100644 --- a/src/esieequest/view/app/UserInterface.java +++ b/src/esieequest/view/app/UserInterface.java | |||
@@ -12,8 +12,12 @@ import java.awt.event.FocusEvent; | |||
12 | import java.awt.event.FocusListener; | 12 | import java.awt.event.FocusListener; |
13 | import java.awt.event.KeyEvent; | 13 | import java.awt.event.KeyEvent; |
14 | import java.awt.image.BufferedImage; | 14 | import java.awt.image.BufferedImage; |
15 | import java.io.FileWriter; | ||
15 | import java.io.IOException; | 16 | import java.io.IOException; |
16 | import java.net.URL; | 17 | import java.net.URL; |
18 | import java.nio.file.Files; | ||
19 | import java.nio.file.Path; | ||
20 | import java.nio.file.Paths; | ||
17 | import java.util.HashMap; | 21 | import java.util.HashMap; |
18 | import java.util.Map.Entry; | 22 | import java.util.Map.Entry; |
19 | import java.util.Timer; | 23 | import java.util.Timer; |
@@ -22,12 +26,14 @@ import java.util.TimerTask; | |||
22 | import javax.swing.AbstractAction; | 26 | import javax.swing.AbstractAction; |
23 | import javax.swing.JButton; | 27 | import javax.swing.JButton; |
24 | import javax.swing.JComponent; | 28 | import javax.swing.JComponent; |
29 | import javax.swing.JFileChooser; | ||
25 | import javax.swing.JLabel; | 30 | import javax.swing.JLabel; |
26 | import javax.swing.JPanel; | 31 | import javax.swing.JPanel; |
27 | import javax.swing.JTextField; | 32 | import javax.swing.JTextField; |
28 | import javax.swing.JTextPane; | 33 | import javax.swing.JTextPane; |
29 | import javax.swing.KeyStroke; | 34 | import javax.swing.KeyStroke; |
30 | import javax.swing.border.EmptyBorder; | 35 | import javax.swing.border.EmptyBorder; |
36 | import javax.swing.filechooser.FileNameExtensionFilter; | ||
31 | 37 | ||
32 | import lombok.Getter; | 38 | import lombok.Getter; |
33 | 39 | ||
@@ -62,6 +68,9 @@ abstract class UserInterface implements Viewable, ActionListener { | |||
62 | private static final String SOUND_DIR = "res/snd/"; | 68 | private static final String SOUND_DIR = "res/snd/"; |
63 | private static final String SOUND_EXT = ".ogg"; | 69 | private static final String SOUND_EXT = ".ogg"; |
64 | 70 | ||
71 | private static final String SAVE_LABEL = "ESIEEquest Game"; | ||
72 | private static final String SAVE_EXT = ".eqg"; | ||
73 | |||
65 | private GameEngine gameEngine; | 74 | private GameEngine gameEngine; |
66 | 75 | ||
67 | @Getter | 76 | @Getter |
@@ -154,6 +163,7 @@ abstract class UserInterface implements Viewable, ActionListener { | |||
154 | 163 | ||
155 | this.soundButton = new JButton(Text.TOGGLE_SOUND_BUTTON.toString()); | 164 | this.soundButton = new JButton(Text.TOGGLE_SOUND_BUTTON.toString()); |
156 | this.soundButton.setToolTipText(Text.TOGGLE_SOUND_TOOLTIP.toString()); | 165 | this.soundButton.setToolTipText(Text.TOGGLE_SOUND_TOOLTIP.toString()); |
166 | this.newButton.setActionCommand(Command.SOUND.name()); | ||
157 | this.gamePanel.add(this.soundButton); | 167 | this.gamePanel.add(this.soundButton); |
158 | 168 | ||
159 | this.filePanel = new JPanel(); | 169 | this.filePanel = new JPanel(); |
@@ -232,6 +242,7 @@ abstract class UserInterface implements Viewable, ActionListener { | |||
232 | 242 | ||
233 | this.inventoryButton = new JButton(Text.INVENTORY_BUTTON.toString()); | 243 | this.inventoryButton = new JButton(Text.INVENTORY_BUTTON.toString()); |
234 | this.inventoryButton.setToolTipText(Text.INVENTORY_TOOLTIP.toString()); | 244 | this.inventoryButton.setToolTipText(Text.INVENTORY_TOOLTIP.toString()); |
245 | this.inventoryButton.setActionCommand(Command.INVENTORY.name()); | ||
235 | this.inventoryButton.setFont(font); | 246 | this.inventoryButton.setFont(font); |
236 | this.inventoryButton.setPreferredSize(squareButton); | 247 | this.inventoryButton.setPreferredSize(squareButton); |
237 | this.topControlPanel.add(this.inventoryButton, BorderLayout.WEST); | 248 | this.topControlPanel.add(this.inventoryButton, BorderLayout.WEST); |
@@ -283,6 +294,7 @@ abstract class UserInterface implements Viewable, ActionListener { | |||
283 | this.newButton.addActionListener(actionListener); | 294 | this.newButton.addActionListener(actionListener); |
284 | this.soundButton.addActionListener(actionListener); | 295 | this.soundButton.addActionListener(actionListener); |
285 | this.loadButton.addActionListener(actionListener); | 296 | this.loadButton.addActionListener(actionListener); |
297 | this.saveButton.addActionListener(actionListener); | ||
286 | this.forwardButton.addActionListener(actionListener); | 298 | this.forwardButton.addActionListener(actionListener); |
287 | this.inventoryButton.addActionListener(actionListener); | 299 | this.inventoryButton.addActionListener(actionListener); |
288 | this.actionButton.addActionListener(actionListener); | 300 | this.actionButton.addActionListener(actionListener); |
@@ -535,10 +547,31 @@ abstract class UserInterface implements Viewable, ActionListener { | |||
535 | */ | 547 | */ |
536 | @Override | 548 | @Override |
537 | public void actionPerformed(final ActionEvent actionEvent) { | 549 | public void actionPerformed(final ActionEvent actionEvent) { |
538 | if (actionEvent.getActionCommand() == Text.INVENTORY_BUTTON.toString()) { | 550 | if (actionEvent.getActionCommand() == Command.INVENTORY.name()) { |
539 | this.toggleInventory(); | 551 | this.toggleInventory(); |
540 | } else if (actionEvent.getActionCommand() == Text.TOGGLE_SOUND_BUTTON.toString()) { | 552 | } else if (actionEvent.getActionCommand() == Text.TOGGLE_SOUND_BUTTON.toString()) { |
541 | this.toggleAudio(); | 553 | this.toggleAudio(); |
554 | } else if (actionEvent.getActionCommand() == Command.LOAD.name()) { | ||
555 | final JFileChooser fileChooser = new JFileChooser(); | ||
556 | fileChooser.setFileFilter(new FileNameExtensionFilter(UserInterface.SAVE_LABEL, | ||
557 | UserInterface.SAVE_EXT)); | ||
558 | final int option = fileChooser.showOpenDialog(this.layout); | ||