diff options
-rw-r--r-- | report/progression.tex | 27 | ||||
-rwxr-xr-x | src/esieequest/Main.java | 13 | ||||
-rw-r--r-- | src/esieequest/view/text/Console.java | 25 | ||||
-rw-r--r-- | src/esieequest/view/text/FileReader.java | 45 | ||||
-rw-r--r-- | src/esieequest/view/text/TextInterface.java (renamed from src/esieequest/view/console/Console.java) | 28 | ||||
-rw-r--r-- | src/esieequest/view/text/package-info.java (renamed from src/esieequest/view/console/package-info.java) | 2 | ||||
-rw-r--r-- | test/commands.txt | 2 | ||||
-rw-r--r-- | test/explore.txt | 0 | ||||
-rw-r--r-- | test/win.txt | 0 |
9 files changed, 120 insertions, 22 deletions
diff --git a/report/progression.tex b/report/progression.tex index cf4f3d2..24c5d7a 100644 --- a/report/progression.tex +++ b/report/progression.tex | |||
@@ -230,10 +230,37 @@ player is at the starting point. | |||
230 | 230 | ||
231 | \subsection{tests} | 231 | \subsection{tests} |
232 | 232 | ||
233 | In the current version of the game, the outputs of commands such as help or quit | ||
234 | might be easily tested. Furthermore, movement from rooms to rooms, and arising | ||
235 | modifications on the model, can also be candidates for testing. | ||
236 | |||
233 | \subsubsection{Automatic tests} | 237 | \subsubsection{Automatic tests} |
234 | 238 | ||
239 | Functionalities of the program can be tested automatically using unit testing | ||
240 | for classes and methods, and interactive testing to simulate the user's | ||
241 | interactions. | ||
242 | |||
243 | Unit tests will later be implemented using the JUnit testing framework. | ||
244 | |||
245 | User interactions like command input can be simulated by reading and | ||
246 | interpreting commands from a text file. | ||
247 | |||
235 | \subsection{test command} | 248 | \subsection{test command} |
236 | 249 | ||
250 | The test command was implemented by modifying the Console view with commit | ||
251 | 967f40d71. Instead of reading commands from the user's input from the console, | ||
252 | the Scanner reads the commands from a text file. | ||
253 | |||
254 | This functionnality was not implemented as a command inside the game, but as a | ||
255 | command line flag that can be used by executing the program from a terminal with | ||
256 | ``--file <file path>''. | ||
257 | |||
258 | \subsubsection{test files} | ||
259 | |||
260 | Three test files were created. The first one tests simple commands such as help | ||
261 | and quit, the second one explores all rooms, and the last one executes all actions | ||
262 | to win the game. | ||
263 | |||
237 | 264 | ||
238 | \section{Zuul with items v2} | 265 | \section{Zuul with items v2} |
239 | 266 | ||
diff --git a/src/esieequest/Main.java b/src/esieequest/Main.java index 2ad11b1..59ac568 100755 --- a/src/esieequest/Main.java +++ b/src/esieequest/Main.java | |||
@@ -1,6 +1,7 @@ | |||
1 | package esieequest; | 1 | package esieequest; |
2 | 2 | ||
3 | import java.util.Arrays; | 3 | import java.util.Arrays; |
4 | import java.util.List; | ||
4 | 5 | ||
5 | import javax.swing.JApplet; | 6 | import javax.swing.JApplet; |
6 | 7 | ||
@@ -9,7 +10,8 @@ import esieequest.model.Game; | |||
9 | import esieequest.view.View; | 10 | import esieequest.view.View; |
10 | import esieequest.view.app.Applet; | 11 | import esieequest.view.app.Applet; |
11 | import esieequest.view.app.Window; | 12 | import esieequest.view.app.Window; |
12 | import esieequest.view.console.Console; | 13 | import esieequest.view.text.Console; |
14 | import esieequest.view.text.FileReader; | ||
13 | 15 | ||
14 | /** | 16 | /** |
15 | * The main class of the program. | 17 | * The main class of the program. |
@@ -44,10 +46,17 @@ public class Main extends JApplet { | |||
44 | * the command line arguments | 46 | * the command line arguments |
45 | */ | 47 | */ |
46 | public static void main(final String[] args) { | 48 | public static void main(final String[] args) { |
49 | final List<String> arguments = Arrays.asList(args); | ||
47 | final Game game = new Game(); | 50 | final Game game = new Game(); |
48 | View view; | 51 | View view; |
49 | 52 | ||
50 | if (Arrays.asList(args).contains("--nogui")) { | 53 | if (arguments.contains("--file")) { |
54 | if (arguments.size() < 2) { | ||
55 | System.out.println("Error: no input file specified."); | ||
56 | return; | ||
57 | } | ||
58 | view = new FileReader(arguments.get(1)); | ||
59 | } else if (arguments.contains("--console")) { | ||
51 | view = new Console(); | 60 | view = new Console(); |
52 | } else { | 61 | } else { |
53 | view = new Window(); | 62 | view = new Window(); |
diff --git a/src/esieequest/view/text/Console.java b/src/esieequest/view/text/Console.java new file mode 100644 index 0000000..e7a71dd --- /dev/null +++ b/src/esieequest/view/text/Console.java | |||
@@ -0,0 +1,25 @@ | |||
1 | package esieequest.view.text; | ||
2 | |||
3 | import java.util.Scanner; | ||
4 | |||
5 | /** | ||
6 | * The textual console view. | ||
7 | * | ||
8 | * @author Pacien TRAN-GIRARD | ||
9 | */ | ||
10 | public class Console extends TextInterface { | ||
11 | |||
12 | /** | ||
13 | * Runs the console input scanner. | ||
14 | */ | ||
15 | @Override | ||
16 | protected void run() { | ||
17 | final Scanner scanner = new Scanner(System.in); | ||
18 | while (this.running) { | ||
19 | System.out.print("> "); | ||
20 | this.gameEngine.interpret(scanner.nextLine()); | ||
21 | } | ||
22 | scanner.close(); | ||
23 | } | ||
24 | |||
25 | } | ||
diff --git a/src/esieequest/view/text/FileReader.java b/src/esieequest/view/text/FileReader.java new file mode 100644 index 0000000..0bf3d3d --- /dev/null +++ b/src/esieequest/view/text/FileReader.java | |||
@@ -0,0 +1,45 @@ | |||
1 | package esieequest.view.text; | ||
2 | |||
3 | import java.io.File; | ||
4 | import java.io.FileNotFoundException; | ||
5 | import java.util.Scanner; | ||
6 | |||
7 | /** | ||
8 | * The textual file reader view. | ||
9 | * | ||
10 | * @author Pacien TRAN-GIRARD | ||
11 | */ | ||
12 | public class FileReader extends TextInterface { | ||
13 | |||
14 | private File file; | ||
15 | |||
16 | /** | ||
17 | * The FileReader initialiser. | ||
18 | * | ||
19 | * @param filePath | ||
20 | * the path of the file to read | ||
21 | */ | ||
22 | public FileReader(final String filePath) { | ||
23 | super(); | ||
24 | this.file = new File(filePath); | ||
25 | } | ||
26 | |||
27 | /** | ||
28 | * Runs the text file input scanner. | ||
29 | */ | ||
30 | @Override | ||
31 | protected void run() { | ||
32 | try { | ||
33 | final Scanner scanner = new Scanner(file); | ||
34 | while (this.running && scanner.hasNextLine()) { | ||
35 | String line = scanner.nextLine(); | ||
36 | System.out.println("> " + line); | ||
37 | this.gameEngine.interpret(line); | ||
38 | } | ||
39 | scanner.close(); | ||
40 | } catch (FileNotFoundException exception) { | ||
41 | System.out.println("Error: file not found."); | ||
42 | } | ||
43 | } | ||
44 | |||
45 | } | ||
diff --git a/src/esieequest/view/console/Console.java b/src/esieequest/view/text/TextInterface.java index 6faaced..e2de893 100644 --- a/src/esieequest/view/console/Console.java +++ b/src/esieequest/view/text/TextInterface.java | |||
@@ -1,4 +1,4 @@ | |||
1 | package esieequest.view.console; | 1 | package esieequest.view.text; |
2 | 2 | ||
3 | import java.util.Scanner; | 3 | import java.util.Scanner; |
4 | 4 | ||
@@ -7,35 +7,25 @@ import esieequest.model.Game; | |||
7 | import esieequest.view.View; | 7 | import esieequest.view.View; |
8 | 8 | ||
9 | /** | 9 | /** |
10 | * The textual console view. | 10 | * The textual view. |
11 | * | 11 | * |
12 | * @author Pacien TRAN-GIRARD | 12 | * @author Pacien TRAN-GIRARD |
13 | */ | 13 | */ |
14 | public class Console implements View { | 14 | abstract class TextInterface implements View { |
15 | 15 | ||
16 | private Game game; | 16 | protected Game game; |
17 | private GameEngine gameEngine; | 17 | protected GameEngine gameEngine; |
18 | 18 | ||
19 | private boolean running; | 19 | protected boolean running; |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * The default constructor. | 22 | * The default constructor. |
23 | */ | 23 | */ |
24 | public Console() { | 24 | public TextInterface() { |
25 | this.running = false; | 25 | this.running = false; |
26 | } | 26 | } |
27 | 27 | ||
28 | /** | 28 | protected abstract void run(); |
29 | * Runs the input scanner. | ||
30 | */ | ||
31 | private void run() { | ||
32 | final Scanner scanner = new Scanner(System.in); | ||
33 | while (this.running) { | ||
34 | System.out.print("> "); | ||
35 | this.gameEngine.interpret(scanner.nextLine()); | ||
36 | } | ||
37 | scanner.close(); | ||
38 | } | ||
39 | 29 | ||
40 | @Override | 30 | @Override |
41 | public void setModel(final Game game) { | 31 | public void setModel(final Game game) { |
diff --git a/src/esieequest/view/console/package-info.java b/src/esieequest/view/text/package-info.java index 24089ab..614ff9f 100644 --- a/src/esieequest/view/console/package-info.java +++ b/src/esieequest/view/text/package-info.java | |||
@@ -1,5 +1,5 @@ | |||
1 | /** | 1 | /** |
2 | * The console view package. Contains the textua |