From 5e9b27294df22eb6a11bc981e2d1844802bb0730 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 15 Mar 2014 19:19:42 +0100 Subject: Update report --- report/progression.tex | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/report/progression.tex b/report/progression.tex index cf4f3d2..3756a92 100644 --- a/report/progression.tex +++ b/report/progression.tex @@ -230,10 +230,16 @@ player is at the starting point. \subsection{tests} +In the current version of the game, the outputs of commands such as help or quit +might be easily tested. Furthermore, movement from rooms to rooms, and arising +modifications on the model, can also be candidates for testing. + \subsubsection{Automatic tests} \subsection{test command} +\subsubsection{test files} + \section{Zuul with items v2} -- cgit v1.2.3 From 48b29ade0ae071401e3c4c69f70506088f28adaa Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 15 Mar 2014 19:25:10 +0100 Subject: Update report --- report/progression.tex | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/report/progression.tex b/report/progression.tex index 3756a92..46ccc38 100644 --- a/report/progression.tex +++ b/report/progression.tex @@ -236,6 +236,15 @@ modifications on the model, can also be candidates for testing. \subsubsection{Automatic tests} +Functionalities of the program can be tested automatically using unit testing +for classes and methods, and interactive testing to simulate the user's +interactions. + +Unit tests will later be implemented using the JUnit testing framework. + +User interactions like command input can be simulated by reading and +interpreting commands from a text file. + \subsection{test command} \subsubsection{test files} -- cgit v1.2.3 From 967f40d710eb07568b6753c6f02d6897f8728999 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 15 Mar 2014 20:04:47 +0100 Subject: Implement command input from file --- src/esieequest/Main.java | 13 ++++- src/esieequest/view/console/Console.java | 78 --------------------------- src/esieequest/view/console/package-info.java | 5 -- src/esieequest/view/text/Console.java | 25 +++++++++ src/esieequest/view/text/FileReader.java | 45 ++++++++++++++++ src/esieequest/view/text/TextInterface.java | 68 +++++++++++++++++++++++ src/esieequest/view/text/package-info.java | 5 ++ test/commands.txt | 2 + 8 files changed, 156 insertions(+), 85 deletions(-) delete mode 100644 src/esieequest/view/console/Console.java delete mode 100644 src/esieequest/view/console/package-info.java create mode 100644 src/esieequest/view/text/Console.java create mode 100644 src/esieequest/view/text/FileReader.java create mode 100644 src/esieequest/view/text/TextInterface.java create mode 100644 src/esieequest/view/text/package-info.java create mode 100644 test/commands.txt 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 @@ package esieequest; import java.util.Arrays; +import java.util.List; import javax.swing.JApplet; @@ -9,7 +10,8 @@ import esieequest.model.Game; import esieequest.view.View; import esieequest.view.app.Applet; import esieequest.view.app.Window; -import esieequest.view.console.Console; +import esieequest.view.text.Console; +import esieequest.view.text.FileReader; /** * The main class of the program. @@ -44,10 +46,17 @@ public class Main extends JApplet { * the command line arguments */ public static void main(final String[] args) { + final List arguments = Arrays.asList(args); final Game game = new Game(); View view; - if (Arrays.asList(args).contains("--nogui")) { + if (arguments.contains("--file")) { + if (arguments.size() < 2) { + System.out.println("Error: no input file specified."); + return; + } + view = new FileReader(arguments.get(1)); + } else if (arguments.contains("--console")) { view = new Console(); } else { view = new Window(); diff --git a/src/esieequest/view/console/Console.java b/src/esieequest/view/console/Console.java deleted file mode 100644 index 6faaced..0000000 --- a/src/esieequest/view/console/Console.java +++ /dev/null @@ -1,78 +0,0 @@ -package esieequest.view.console; - -import java.util.Scanner; - -import esieequest.controller.GameEngine; -import esieequest.model.Game; -import esieequest.view.View; - -/** - * The textual console view. - * - * @author Pacien TRAN-GIRARD - */ -public class Console implements View { - - private Game game; - private GameEngine gameEngine; - - private boolean running; - - /** - * The default constructor. - */ - public Console() { - this.running = false; - } - - /** - * Runs the input scanner. - */ - private void run() { - final Scanner scanner = new Scanner(System.in); - while (this.running) { - System.out.print("> "); - this.gameEngine.interpret(scanner.nextLine()); - } - scanner.close(); - } - - @Override - public void setModel(final Game game) { - this.game = game; - } - - @Override - public void setController(final GameEngine gameEngine) { - this.gameEngine = gameEngine; - } - - @Override - public void show() { - this.enable(); - } - - @Override - public void enable() { - if (!this.running) { - this.running = true; - this.run(); - } - } - - @Override - public void disable() { - this.running = false; - } - - @Override - public void refresh() { - this.echo(this.game.getLocationInfo()); - } - - @Override - public void echo(final String message) { - System.out.println(message); - } - -} diff --git a/src/esieequest/view/console/package-info.java b/src/esieequest/view/console/package-info.java deleted file mode 100644 index 24089ab..0000000 --- a/src/esieequest/view/console/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * The console view package. Contains the textual user interface and its associated input stream processor. - */ -package esieequest.view.console; - 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 @@ +package esieequest.view.text; + +import java.util.Scanner; + +/** + * The textual console view. + * + * @author Pacien TRAN-GIRARD + */ +public class Console extends TextInterface { + + /** + * Runs the console input scanner. + */ + @Override + protected void run() { + final Scanner scanner = new Scanner(System.in); + while (this.running) { + System.out.print("> "); + this.gameEngine.interpret(scanner.nextLine()); + } + scanner.close(); + } + +} 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 @@ +package esieequest.view.text; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +/** + * The textual file reader view. + * + * @author Pacien TRAN-GIRARD + */ +public class FileReader extends TextInterface { + + private File file; + + /** + * The FileReader initialiser. + * + * @param filePath + * the path of the file to read + */ + public FileReader(final String filePath) { + super(); + this.file = new File(filePath); + } + + /** + * Runs the text file input scanner. + */ + @Override + protected void run() { + try { + final Scanner scanner = new Scanner(file); + while (this.running && scanner.hasNextLine()) { + String line = scanner.nextLine(); + System.out.println("> " + line); + this.gameEngine.interpret(line); + } + scanner.close(); + } catch (FileNotFoundException exception) { + System.out.println("Error: file not found."); + } + } + +} diff --git a/src/esieequest/view/text/TextInterface.java b/src/esieequest/view/text/TextInterface.java new file mode 100644 index 0000000..e2de893 --- /dev/null +++ b/src/esieequest/view/text/TextInterface.java @@ -0,0 +1,68 @@ +package esieequest.view.text; + +import java.util.Scanner; + +import esieequest.controller.GameEngine; +import esieequest.model.Game; +import esieequest.view.View; + +/** + * The textual view. + * + * @author Pacien TRAN-GIRARD + */ +abstract class TextInterface implements View { + + protected Game game; + protected GameEngine gameEngine; + + protected boolean running; + + /** + * The default constructor. + */ + public TextInterface() { + this.running = false; + } + + protected abstract void run(); + + @Override + public void setModel(final Game game) { + this.game = game; + } + + @Override + public void setController(final GameEngine gameEngine) { + this.gameEngine = gameEngine; + } + + @Override + public void show() { + this.enable(); + } + + @Override + public void enable() { + if (!this.running) { + this.running = true; + this.run(); + } + } + + @Override + public void disable() { + this.running = false; + } + + @Override + public void refresh() { + this.echo(this.game.getLocationInfo()); + } + + @Override + public void echo(final String message) { + System.out.println(message); + } + +} diff --git a/src/esieequest/view/text/package-info.java b/src/esieequest/view/text/package-info.java new file mode 100644 index 0000000..614ff9f --- /dev/null +++ b/src/esieequest/view/text/package-info.java @@ -0,0 +1,5 @@ +/** + * The console view package. Contains the textual user interface and its associated input stream processor. + */ +package esieequest.view.text; + diff --git a/test/commands.txt b/test/commands.txt new file mode 100644 index 0000000..73d07ea --- /dev/null +++ b/test/commands.txt @@ -0,0 +1,2 @@ +help +quit \ No newline at end of file -- cgit v1.2.3 From 054449d96c9b9f5302d9a4ef41309e225d666b4e Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 15 Mar 2014 20:10:48 +0100 Subject: Update report --- report/progression.tex | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/report/progression.tex b/report/progression.tex index 46ccc38..135ba3e 100644 --- a/report/progression.tex +++ b/report/progression.tex @@ -247,6 +247,14 @@ interpreting commands from a text file. \subsection{test command} +The test command was implemented by modifying the Console view with commit +967f40d71. Instead of reading commands from the user's input from the console, +the Scanner reads the commands from a text file. + +This functionnality was not implemented as a command inside the game, but as a +command line flag that can be used by executing the program from a terminal with +``--file ''. + \subsubsection{test files} -- cgit v1.2.3 From 49010d96d45dc35714ea30f2d63181e5be99b9af Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 15 Mar 2014 20:11:26 +0100 Subject: Add more empty test files --- test/explore.txt | 0 test/win.txt | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/explore.txt create mode 100644 test/win.txt diff --git a/test/explore.txt b/test/explore.txt new file mode 100644 index 0000000..e69de29 diff --git a/test/win.txt b/test/win.txt new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From 800791da4b3b86b9fa341680734b36518574fba1 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 15 Mar 2014 20:13:41 +0100 Subject: Update report --- report/progression.tex | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/report/progression.tex b/report/progression.tex index 135ba3e..24c5d7a 100644 --- a/report/progression.tex +++ b/report/progression.tex @@ -257,6 +257,10 @@ command line flag that can be used by executing the program from a terminal with \subsubsection{test files} +Three test files were created. The first one tests simple commands such as help +and quit, the second one explores all rooms, and the last one executes all actions +to win the game. + \section{Zuul with items v2} -- cgit v1.2.3