aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--report/progression.tex27
-rwxr-xr-xsrc/esieequest/Main.java13
-rw-r--r--src/esieequest/view/text/Console.java25
-rw-r--r--src/esieequest/view/text/FileReader.java45
-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.txt2
-rw-r--r--test/explore.txt0
-rw-r--r--test/win.txt0
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
233In the current version of the game, the outputs of commands such as help or quit
234might be easily tested. Furthermore, movement from rooms to rooms, and arising
235modifications on the model, can also be candidates for testing.
236
233\subsubsection{Automatic tests} 237\subsubsection{Automatic tests}
234 238
239Functionalities of the program can be tested automatically using unit testing
240for classes and methods, and interactive testing to simulate the user's
241interactions.
242
243Unit tests will later be implemented using the JUnit testing framework.
244
245User interactions like command input can be simulated by reading and
246interpreting commands from a text file.
247
235\subsection{test command} 248\subsection{test command}
236 249
250The test command was implemented by modifying the Console view with commit
251967f40d71. Instead of reading commands from the user's input from the console,
252the Scanner reads the commands from a text file.
253
254This functionnality was not implemented as a command inside the game, but as a
255command line flag that can be used by executing the program from a terminal with
256``--file <file path>''.
257
258\subsubsection{test files}
259
260Three test files were created. The first one tests simple commands such as help
261and quit, the second one explores all rooms, and the last one executes all actions
262to 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 @@
1package esieequest; 1package esieequest;
2 2
3import java.util.Arrays; 3import java.util.Arrays;
4import java.util.List;
4 5
5import javax.swing.JApplet; 6import javax.swing.JApplet;
6 7
@@ -9,7 +10,8 @@ import esieequest.model.Game;
9import esieequest.view.View; 10import esieequest.view.View;
10import esieequest.view.app.Applet; 11import esieequest.view.app.Applet;
11import esieequest.view.app.Window; 12import esieequest.view.app.Window;
12import esieequest.view.console.Console; 13import esieequest.view.text.Console;
14import 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 @@
1package esieequest.view.text;
2
3import java.util.Scanner;
4
5/**
6 * The textual console view.
7 *
8 * @author Pacien TRAN-GIRARD
9 */
10public 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 @@
1package esieequest.view.text;
2
3import java.io.File;
4import java.io.FileNotFoundException;
5import java.util.Scanner;
6
7/**
8 * The textual file reader view.
9 *
10 * @author Pacien TRAN-GIRARD
11 */
12public 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 @@
1package esieequest.view.console; 1package esieequest.view.text;
2 2
3import java.util.Scanner; 3import java.util.Scanner;
4 4
@@ -7,35 +7,25 @@ import esieequest.model.Game;
7import esieequest.view.View; 7import 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 */
14public class Console implements View { 14abstract 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