diff options
Diffstat (limited to 'src')
22 files changed, 427 insertions, 505 deletions
diff --git a/src/esieequest/Main.java b/src/esieequest/Main.java index add0fb1..5a08f1d 100755 --- a/src/esieequest/Main.java +++ b/src/esieequest/Main.java | |||
@@ -1,13 +1,15 @@ | |||
1 | package esieequest; | 1 | package esieequest; |
2 | 2 | ||
3 | import java.util.Arrays; | ||
4 | |||
3 | import javax.swing.JApplet; | 5 | import javax.swing.JApplet; |
4 | 6 | ||
5 | import esieequest.controller.GameEngine; | 7 | import esieequest.controller.GameEngine; |
6 | import esieequest.model.Game; | 8 | import esieequest.model.Game; |
7 | import esieequest.view.Applet; | ||
8 | import esieequest.view.Console; | ||
9 | import esieequest.view.View; | 9 | import esieequest.view.View; |
10 | import esieequest.view.Window; | 10 | import esieequest.view.app.Applet; |
11 | import esieequest.view.app.Window; | ||
12 | import esieequest.view.console.Console; | ||
11 | 13 | ||
12 | /** | 14 | /** |
13 | * This class instantiates the game and makes it possible to run it via the | 15 | * This class instantiates the game and makes it possible to run it via the |
@@ -28,9 +30,8 @@ public class Main extends JApplet { | |||
28 | public void init() { | 30 | public void init() { |
29 | // applet | 31 | // applet |
30 | Game vGame = new Game(); | 32 | Game vGame = new Game(); |
31 | Applet vApplet = new Applet(vGame, this); | 33 | Applet vApplet = new Applet(this); |
32 | vGame.addObserver(vApplet); | 34 | new GameEngine(vGame, vApplet); |
33 | GameEngine vGameEngine = new GameEngine(vGame, vApplet); | ||
34 | } | 35 | } |
35 | 36 | ||
36 | public static void main(final String[] pArgs) { | 37 | public static void main(final String[] pArgs) { |
@@ -38,15 +39,14 @@ public class Main extends JApplet { | |||
38 | Game vGame = new Game(); | 39 | Game vGame = new Game(); |
39 | View vView; | 40 | View vView; |
40 | 41 | ||
41 | if (pArgs.length != 0) { | 42 | if (Arrays.asList(pArgs).contains("--nogui")) { |
42 | vView = new Console(vGame); | 43 | vView = new Console(); |
43 | 44 | ||
44 | } else { | 45 | } else { |
45 | vView = new Window(vGame); | 46 | vView = new Window(); |
46 | } | 47 | } |
47 | 48 | ||
48 | vGame.addObserver(vView); | 49 | new GameEngine(vGame, vView); |
49 | GameEngine vGameEngine = new GameEngine(vGame, vView); | ||
50 | } | 50 | } |
51 | 51 | ||
52 | } | 52 | } |
diff --git a/src/esieequest/controller/GameEngine.java b/src/esieequest/controller/GameEngine.java index 72de63a..3999cd0 100644 --- a/src/esieequest/controller/GameEngine.java +++ b/src/esieequest/controller/GameEngine.java | |||
@@ -1,8 +1,5 @@ | |||
1 | package esieequest.controller; | 1 | package esieequest.controller; |
2 | 2 | ||
3 | import java.awt.event.ActionEvent; | ||
4 | import java.awt.event.ActionListener; | ||
5 | |||
6 | import esieequest.model.Game; | 3 | import esieequest.model.Game; |
7 | import esieequest.view.View; | 4 | import esieequest.view.View; |
8 | 5 | ||
@@ -15,7 +12,7 @@ import esieequest.view.View; | |||
15 | * | 12 | * |
16 | * @version February 2014 | 13 | * @version February 2014 |
17 | */ | 14 | */ |
18 | public class GameEngine implements ActionListener { | 15 | public class GameEngine { |
19 | 16 | ||
20 | private Game aGame; | 17 | private Game aGame; |
21 | private View aView; | 18 | private View aView; |
@@ -26,9 +23,10 @@ public class GameEngine implements ActionListener { | |||
26 | this.aGame = pGame; | 23 | this.aGame = pGame; |
27 | this.aView = pView; | 24 | this.aView = pView; |
28 | 25 | ||
29 | this.aInterpreter = new Interpreter(this.aGame, this.aView); | 26 | this.aView.setModel(pGame); |
27 | this.aView.setController(this); | ||
30 | 28 | ||
31 | this.aView.setActionListener(this); | 29 | this.aInterpreter = new Interpreter(this.aGame, this.aView); |
32 | 30 | ||
33 | this.startGame(); | 31 | this.startGame(); |
34 | this.startView(); | 32 | this.startView(); |
@@ -40,12 +38,11 @@ public class GameEngine implements ActionListener { | |||
40 | } | 38 | } |
41 | 39 | ||
42 | private void startView() { | 40 | private void startView() { |
43 | this.aView.start(); | 41 | this.aView.enable(); |
44 | } | 42 | } |
45 | 43 | ||
46 | @Override | 44 | public void interpret(final String pCommandString) { |
47 | public void actionPerformed(final ActionEvent pActionEvent) { | 45 | this.aInterpreter.interpret(pCommandString); |
48 | this.aInterpreter.interpret(pActionEvent.getActionCommand()); | ||
49 | } | 46 | } |
50 | 47 | ||
51 | } | 48 | } |
diff --git a/src/esieequest/controller/Interpreter.java b/src/esieequest/controller/Interpreter.java index 1e2937b..b4fbb3e 100644 --- a/src/esieequest/controller/Interpreter.java +++ b/src/esieequest/controller/Interpreter.java | |||
@@ -3,10 +3,6 @@ | |||
3 | */ | 3 | */ |
4 | package esieequest.controller; | 4 | package esieequest.controller; |
5 | 5 | ||
6 | import java.awt.event.ActionEvent; | ||
7 | import java.awt.event.ActionListener; | ||
8 | import java.util.StringTokenizer; | ||
9 | |||
10 | import esieequest.model.Game; | 6 | import esieequest.model.Game; |
11 | import esieequest.model.command.Command; | 7 | import esieequest.model.command.Command; |
12 | import esieequest.view.View; | 8 | import esieequest.view.View; |
@@ -62,7 +58,7 @@ public class Interpreter { | |||
62 | return; | 58 | return; |
63 | } | 59 | } |
64 | } | 60 | } |
65 | this.aPerformer.showMessage("Unknown command."); | 61 | this.aPerformer.echo("Unknown command."); |
66 | return; | 62 | return; |
67 | } | 63 | } |
68 | } | 64 | } |
diff --git a/src/esieequest/controller/Parser.java b/src/esieequest/controller/Parser.java index bd36041..c9095fe 100644 --- a/src/esieequest/controller/Parser.java +++ b/src/esieequest/controller/Parser.java | |||
@@ -1,7 +1,5 @@ | |||
1 | package esieequest.controller; | 1 | package esieequest.controller; |
2 | 2 | ||
3 | import java.util.StringTokenizer; | ||
4 | |||
5 | import esieequest.model.command.Command; | 3 | import esieequest.model.command.Command; |
6 | 4 | ||
7 | public class Parser { | 5 | public class Parser { |
@@ -10,22 +8,23 @@ public class Parser { | |||
10 | } | 8 | } |
11 | 9 | ||
12 | public Command getCommand(final String pCommandString) { | 10 | public Command getCommand(final String pCommandString) { |
13 | StringTokenizer vTokenizer = new StringTokenizer(pCommandString); | 11 | String[] vElements = pCommandString.split(" "); |
14 | 12 | ||
15 | String vAction = null; | 13 | String vAction = null; |
16 | String vOption = null; | 14 | String vOption = null; |
17 | 15 | ||
18 | if (vTokenizer.hasMoreTokens()) { | 16 | if (vElements.length > 0) { |
19 | vAction = vTokenizer.nextToken(); | 17 | vAction = vElements[0]; |
20 | if (vTokenizer.hasMoreTokens()) { | 18 | } |
21 | vOption = vTokenizer.nextToken(); | 19 | if (vElements.length > 1) { |
22 | } | 20 | vOption = vElements[1]; |
23 | } | 21 | } |
22 | |||
24 | return new Command(vAction, vOption); | 23 | return new Command(vAction, vOption); |
25 | } | 24 | } |
26 | 25 | ||
27 | private void validateCommand() { | 26 | private void validateCommand() { |
28 | 27 | // TODO | |
29 | } | 28 | } |
30 | 29 | ||
31 | } | 30 | } |
diff --git a/src/esieequest/controller/Performer.java b/src/esieequest/controller/Performer.java index db52c4f..c56ef39 100644 --- a/src/esieequest/controller/Performer.java +++ b/src/esieequest/controller/Performer.java | |||
@@ -21,53 +21,52 @@ public class Performer { | |||
21 | this.aView = pView; |