blob: 896d85be2707d411cfe0fc255f714b1f4a36fbf4 (
plain)
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
|
package esieequest.controller.commands;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException;
import esieequest.model.Game;
import esieequest.model.Text;
import esieequest.view.Viewable;
/**
* Loads a saved Game.
*
* @author Pacien TRAN-GIRARD
*/
public class LoadCommand implements Executable {
@Override
public void execute(final String argument, final Game game, final Viewable view) {
final String jsonString = argument;
JSONObject datas = new JSONObject();
try {
datas = (JSONObject) JSONValue.parseWithException(jsonString);
} catch (final ParseException e) {
view.echo(Text.PARSING_ERROR_PREFIX.toString() + e.getMessage()
+ Text.PARSING_ERROR_SUFFIX.toString());
return;
}
try {
game.newGame(false, false);
game.deserialise(datas);
} catch (final Exception e) {
view.echo(Text.DESERIALISING_ERROR_PREFIX.toString() + e.getMessage()
+ Text.DESERIALISING_ERROR_SUFFIX.toString());
e.printStackTrace();
return;
}
// view.updateQuest();
// view.updateInventory(game.getPlayer().getItems());
view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer()
.getCurrentDirection(), game.getPlayer().getCurrentSide(), game.getPlayer()
.canGoBack());
}
}
|