From a2f9f3404f2d400af5391811afc544a717c02571 Mon Sep 17 00:00:00 2001 From: Edi Date: Wed, 5 Jun 2019 22:18:59 +0200 Subject: [PATCH] Test --- build.xml | 71 ++ nbproject/ant-deploy.xml | 150 ++++ nbproject/build-impl.xml | 1444 +++++++++++++++++++++++++++++++++ nbproject/genfiles.properties | 8 + nbproject/project.properties | 89 ++ nbproject/project.xml | 23 + src/conf/MANIFEST.MF | 2 + src/java/Game.java | 330 ++++++++ src/java/Item.java | 55 ++ src/java/Logic.java | 119 +++ src/java/Puzzle.java | 120 +++ src/java/Room.java | 69 ++ web/index.html | 66 ++ 13 files changed, 2546 insertions(+) create mode 100644 build.xml create mode 100644 nbproject/ant-deploy.xml create mode 100644 nbproject/build-impl.xml create mode 100644 nbproject/genfiles.properties create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 src/conf/MANIFEST.MF create mode 100644 src/java/Game.java create mode 100644 src/java/Item.java create mode 100644 src/java/Logic.java create mode 100644 src/java/Puzzle.java create mode 100644 src/java/Room.java create mode 100644 web/index.html diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..a3e0bca --- /dev/null +++ b/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + Builds, tests, and runs the project WebAdventure. + + + diff --git a/nbproject/ant-deploy.xml b/nbproject/ant-deploy.xml new file mode 100644 index 0000000..5d33e0d --- /dev/null +++ b/nbproject/ant-deploy.xml @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..7f23e52 --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1444 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set build.web.dir + Must set build.generated.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.war + + + + + + + + + +The Java EE server classpath is not correctly set up - server home directory is missing. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Dj2ee.server.home=<app_server_installation_directory> + + +The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Duser.properties.file=<path_to_property_file> (where you put the property "j2ee.platform.classpath" in a .properties file) +or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +The libs.CopyLibs.classpath property is not set up. +This property must point to +org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part +of NetBeans IDE installation and is usually located at +<netbeans_installation>/java<version>/ant/extra folder. +Either open the project in the IDE and make sure CopyLibs library +exists or setup the property manually. For example like this: + ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + Must select a file in the IDE or set jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable. + + + Launching ${browse.url} + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..33a372f --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=b50c735c +build.xml.script.CRC32=2d64e8d1 +build.xml.stylesheet.CRC32=651128d4@1.77.1.1 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=b50c735c +nbproject/build-impl.xml.script.CRC32=74e621b3 +nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.77.1.1 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..f81702a --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,89 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=true +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.web.dir}/WEB-INF/classes +build.classes.excludes=**/*.java,**/*.form +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +build.web.dir=${build.dir}/web +build.web.excludes=${build.classes.excludes} +client.urlPart= +compile.jsps=false +conf.dir=${source.root}/conf +debug.classpath=${build.classes.dir}:${javac.classpath} +debug.test.classpath=\ + ${run.test.classpath} +display.browser=true +# Files to be excluded from distribution war +dist.archive.excludes= +dist.dir=dist +dist.ear.war=${dist.dir}/${war.ear.name} +dist.javadoc.dir=${dist.dir}/javadoc +dist.war=${dist.dir}/${war.name} +endorsed.classpath=\ + ${libs.javaee-endorsed-api-7.0.classpath} +excludes= +includes=** +j2ee.compile.on.save=true +j2ee.copy.static.files.on.save=true +j2ee.deploy.on.save=true +j2ee.platform=1.7-web +j2ee.platform.classpath=${j2ee.server.home}/modules/endorsed/grizzly-npn-bootstrap.jar:${j2ee.server.home}/modules/endorsed/jakarta.annotation-api.jar:${j2ee.server.home}/modules/endorsed/jakarta.xml.bind-api.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/cdi-api.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/weld-osgi-bundle.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar +j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar +j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar +j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar +j2ee.platform.wsimport.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar +j2ee.platform.wsit.classpath= +j2ee.server.type=gfv3ee6 +jar.compress=false +javac.classpath=\ + ${libs.javaee-web-api-7.0.classpath} +# Space-separated list of extra javac options +javac.compilerargs= +javac.debug=true +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.preview=true +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +lib.dir=${web.docbase.dir}/WEB-INF/lib +persistence.xml.dir=${conf.dir} +platform.active=default_platform +resource.dir=setup +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +# Space-separated list of JVM arguments used when running a class with a main method or a unit test +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value): +runmain.jvmargs= +source.encoding=UTF-8 +source.root=src +src.dir=${source.root}/java +test.src.dir=test +war.content.additional= +war.ear.name=${war.name} +war.name=WebAdventure.war +web.docbase.dir=web +webinf.dir=web/WEB-INF diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..dc2a753 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,23 @@ + + + org.netbeans.modules.web.project + + + WebAdventure + 1.6.5 + + + ${libs.javaee-web-api-7.0.classpath} + WEB-INF/lib + + + + + + + + + + + + diff --git a/src/conf/MANIFEST.MF b/src/conf/MANIFEST.MF new file mode 100644 index 0000000..58630c0 --- /dev/null +++ b/src/conf/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/src/java/Game.java b/src/java/Game.java new file mode 100644 index 0000000..2277c8a --- /dev/null +++ b/src/java/Game.java @@ -0,0 +1,330 @@ + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.net.HttpURLConnection; + + +public class Game { + + private static ArrayList rooms = new ArrayList(); + private static ArrayList inventory = new ArrayList(); + private static ArrayList story = new ArrayList(); + private boolean stoppFlag = false; + + String[] inputArray = null; + String itemName = null; + String intentName = null; + String puzzleName = null; + String input = null; + Room currentRoom=null; + + Room keller; + Puzzle schloss; + Puzzle door; + Item schluessel; + Item tonne; + + public Game() { + try { + startGame(); + } catch (Exception ex) { + Logger.getLogger(Game.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public void setVariables() { + //Room Object + keller = new Room("Keller"); + keller.setDescription("Es ist totenstill, nichts und niemand bewegt sich. Man kann fast nichts erkennen au�er einem kleinen quadratischen Fenster �ber dir, durch dessen Gitterst�be der Mond sehr leicht scheint. " + + "Trotz der Schmerzen in deinen Knochen versuchst du aufzustehen und zu fliehen, doch pl�tzlich merkst du, dass du nicht kannst!"); + + //Puzzle Object + schloss = new Puzzle("Schloss"); + schloss.setDescription("Es ist ein altes Schloss aus Metall, dass eine Einkerbung f�r einen Schl�ssel hat"); + schloss.setSolvedText("Ja, es hat funktioniert! Mit einem Knacksen geht das Schloss auf und du kannst dich von deiner Beinfessel befreien. "); + + keller.puzzles.add(schloss); + + //Ausgang + door = new Puzzle("Tuer"); + door.setDescription("Ausgang aus dem Keller"); + door.setGameOverFlag(true); + door.setSolvedText("Geschafft! Die Tuer ist offen. Das Intro ist nun beendet"); + keller.puzzles.add(door); + + //Item Object + schluessel = new Item("Schluessel"); + schluessel.setHiddenFlag(false); + schluessel.setPortableFlag(true); + schluessel.setDescription("Der Schl�ssel ist kalt und klein. Vielleicht hast du Gl�ck und er passt ins Schloss. Versuche es zu �ffnen!"); + schloss.addItem(schluessel); + keller.items.add(schluessel); + + door.setDependency(schloss); + door.setDependencyText("Du musst erst das Schloss der Kette knacken um die Tür öffnen zu können"); + + //Item Object + tonne = new Item("Muelltonne"); + tonne.setHiddenFlag(false); + tonne.setPortableFlag(false); + tonne.setDescription("Eine schwarze M�lltonne. Sie stinkt f�rchterlich"); + keller.items.add(tonne); + + rooms.add(keller); + story.add("Dein ganzer K�rper schmerzt, du liegst auf Betonboden. Du f�ngst laut an zu husten und Staubklumpen fliegen aus deinem Mund. Du �ffnest langsam und nur schwer die Augen, " + + "doch es ist fast gar nichts zu sehen. Die einzige Lichtquelle ist ein kleines Fenster �ber dir, durch die ein schwacher Mondschein f�llt. Es ist also Nachts... " + + "Langsam versuchst du dich an die fast komplette Dunkelheit zu gew�hnen und erkennst, dass du dich in einem kleinen dir unbekannten Raum befindest. Dich packt die Angst! " + + "Was ist passiert, wo bist du und wie bist du hier gelandet?" + + "Du nimmst die Stahlkette in die Hand. Sie ist schwer und verrostet. Mit den H�nden tastest du dich voran bis an die Heizung, wo du ein Schloss an der Kette entdeckst." + + "Das Mondlicht ist nur sehr schwach, um den Raum zu begutachten. Du gehst in die Knie und tastest mit deinem H�nden wild und in Panik am Betonboden. " + + "Pl�tzlich st��t du auf einen kleinen Gegenstand, der sich tats�chlich anf�hlt wie ein Schl�ssel. Du solltest ihn aufheben"); + + keller.setDescription("der kleine Mondschein, der zuvor den unbekannten Raum schwach beleuchtet hat, leuchtet viel gr��er und viel heller und du erkennst nun den gesamten Raum. Er ist klein und d�ster. " + + "überall h�ngen Spinnennetze und Staub sammelt sich am Betonboden. Du erkennst am anderen Ende des Raumes eine T�r"); + + currentRoom = keller; + } + + public void play() { + if (input.contains(" ")) { + inputArray = input.split(" "); + + for (String s : inputArray) { + if (currentRoom.getItem(s) != null) { + itemName = s; + } else if (currentRoom.getPuzzle(s) != null) { + puzzleName = s; + } else { + intentName = s; + } + } + } else { + intentName = input; + } + + switch (intentName.toLowerCase()) { + //intent + case "lookaroundintent": + if (itemName == null && puzzleName == null) { + lookaround(); + } + break; + //intent + case "inspectintent": + if (itemName != null) { + inspect(itemName); + } else if (puzzleName != null) { + inspect(puzzleName); + } else { + say("Das kann nicht untersucht werden"); + } + break; + //intent + case "examineintent": + if (itemName == null && puzzleName == null) { + examine(); + } + break; + //intent + case "takeintent": + if (itemName != null) { + take(currentRoom.getItem(itemName)); + } else { + say("das kann nicht mitgenommen werden"); + } + break; + //intent + case "openintent": + if (puzzleName != null) { + open(currentRoom.getPuzzle(puzzleName)); + } else { + say("das kann nicht geöffnet werden"); + } + + break; + + } + itemName = null; + intentName = null; + puzzleName = null; + + if (stoppFlag == true) { + endGame(); + } + } + + public void lookaround() { + say(currentRoom.getDescription()); + } + + public void startGame() { + for (int i = 0; i < story.size(); i++) { + say(story.get(i)); + } + } + + public void inspect(String s) { + Item currentItem = currentRoom.getItem(s); + Puzzle currentPuzzle = currentRoom.getPuzzle(s); + + if (currentPuzzle != null) { + say(currentPuzzle.getDescription()); + + } else if (currentItem != null) { + say(currentItem.getDescription()); + } + + } + + public void endGame() { + say("Glückwunsch das Spiel ist beendet!"); + setVariables(); + } + + public void sendPost(String s) throws Exception { + s = s.replace(" ", "%20"); + String url = "https://medinf.efi.th-nuernberg.de/tomcat/WebAdventure/Logic"; + URL obj = new URL(url); + HttpURLConnection httpConn = (HttpURLConnection) obj.openConnection(); + + //add reuqest header + httpConn.setRequestMethod("POST"); + httpConn.setRequestProperty("User-Agent", "Mozilla/5.0"); + httpConn.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); + + // Send post request + httpConn.setDoOutput(true); + DataOutputStream wr = new DataOutputStream(httpConn.getOutputStream()); + String urlParameters = "alexaText=" + s; + wr.writeBytes(urlParameters); + wr.flush(); + wr.close(); + + //int responseCode = httpConn.getResponseCode(); + //System.out.println("\nSending 'POST' request to URL : " + url); + + //System.out.println("Response Code : " + responseCode); + + BufferedReader in = new BufferedReader( + new InputStreamReader(httpConn.getInputStream())); + String inputLine; + StringBuffer response = new StringBuffer(); + + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + + //print result + //System.out.println(response.toString()); + } + + public void say(String s) { + try { + sendPost(s); + } catch (Exception ex) { + Logger.getLogger(Game.class.getName()).log(Level.SEVERE, null, ex); + } + + } + + public void setInput(String s) { + input = s; + } + + public void setRoom(Room nextRoom) { + currentRoom = nextRoom; + say(currentRoom.getDescription()); + } + + public void examine() { + for (Item bag : inventory) { + say(bag.getName()); + } + + if (getInventory().isEmpty()) { + say("Deine Taschen sind leer"); + } + } + + public void open(Puzzle currentPuzzle) { + boolean isSolved = currentPuzzle.isSolved(); // sagt ob das Rätsel gelöst ist oder nicht + ArrayList solveItems = currentPuzzle.getItems(); // Items die zum lösen des Rätsels benötigt werden + + if((currentPuzzle.hasDependency() && currentPuzzle.getDependency().isSolved()) || currentPuzzle.hasDependency() == false) + { + if (isSolved == false) { // ist ungelöst + if (solveItems.isEmpty()) // kein Item zum lösen benötigt + { + currentPuzzle.setSolved(true); // auf gelöst setzen + say(currentPuzzle.getSolvedText()); + + if (currentPuzzle.getNextRoom() != null) // falls es eine Tür ist wird in den nächsten Raum gewechselt + { + setRoom(currentPuzzle.getNextRoom()); + } + + if (currentRoom.getGameoverFlag() == true || currentPuzzle.getGameOverFlag() == true) { // letzter Raum/Puzzle + stoppFlag = true; + } + + } else // Items werden zum lösen benötigt + { + if (getInventory().containsAll(solveItems)) { // alle benötigten Items befinden sich in deinem Inventar + + inventory.removeAll(currentRoom.getItems()); // entfernt all Items aus dem Inventar die für das lösen benötigt werden + currentPuzzle.setSolved(true); // setze Rätsel auf gelöst + say(currentPuzzle.getSolvedText()); + + if (currentRoom.getGameoverFlag() == true || currentPuzzle.getGameOverFlag() == true) { // letzter Raum + stoppFlag = true; // Spielende + } + + if (currentPuzzle.getNextRoom() != null) { // falls es eine Tür ist wird in den nächsten Raum gewechselt + setRoom(currentPuzzle.getNextRoom()); + } + + } else { + say("dir fehlt noch etwas um das zu öffnen ..."); + } + } + } else { // ist gelöst + say(" ist bereits geöffnet"); + } + }else + { + say(currentPuzzle.getDependencyText()); + } + + } + + public void take(Item i) { + if ((!inventory.contains(i)) && (i.isPortableFlag() == true)) { + inventory.add(i); + currentRoom.items.remove(i); + say(i.getName() + " wurde deiner Tasche hinzugefuegt"); + } else if (i.isPortableFlag() == false) { + say("Das Item kann nicht mitgenommen werden"); + } else { + say("Das Item befindet sich bereits in deiner Tasche!"); + } + } + + public ArrayList getRooms() { + return rooms; + } + + public ArrayList getInventory() { + return inventory; + } + + public ArrayList getStory() { + return story; + } + +} diff --git a/src/java/Item.java b/src/java/Item.java new file mode 100644 index 0000000..f4869cb --- /dev/null +++ b/src/java/Item.java @@ -0,0 +1,55 @@ + +public class Item +{ + private int id; + private String name; + private boolean portableFlag; + private boolean hiddenFlag; + private String description; + public Item(String name) + { + this.name = name; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isPortableFlag() { + return portableFlag; + } + + public void setPortableFlag(boolean portableFlag) { + this.portableFlag = portableFlag; + } + + public boolean isHiddenFlag() { + return hiddenFlag; + } + + public void setHiddenFlag(boolean hiddenFlag) { + this.hiddenFlag = hiddenFlag; + } +} diff --git a/src/java/Logic.java b/src/java/Logic.java new file mode 100644 index 0000000..421c48c --- /dev/null +++ b/src/java/Logic.java @@ -0,0 +1,119 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Edi + */ +@WebServlet(urlPatterns = {"/Logic"}) +public class Logic extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + Game g = new Game(); + String context = ""; + + public void init() { + g.setVariables(); + + } + + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException, Exception { + response.setContentType("text/html;charset=UTF-8"); + + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + + out.println("

" + context + "

"); + + if (request.getParameter("alexaText") != null) { + context = context + "

" + request.getParameter("alexaText"); + } + + String input = request.getParameter("intent"); + if (request.getParameter("slot") != null) { + input = input + " " + request.getParameter("slot"); + } + + if(input != null) + { + g.setInput(input); + g.play(); + } + + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setIntHeader("Refresh", 5); + try { + processRequest(request, response); + + } catch (Exception ex) { + Logger.getLogger(Logic.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setIntHeader("Refresh", 5); + try { + processRequest(request, response); + } catch (Exception ex) { + Logger.getLogger(Logic.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/src/java/Puzzle.java b/src/java/Puzzle.java new file mode 100644 index 0000000..b44967b --- /dev/null +++ b/src/java/Puzzle.java @@ -0,0 +1,120 @@ +import java.util.ArrayList; + +public class Puzzle +{ + private int id; + private String name; + private ArrayList items = new ArrayList(); + private String description=""; + private boolean solved = false; + private String solvedText = ""; + private boolean gameOverFlag=false; + private Room nextRoom = null; + private String dependencyText = null; + private Puzzle dependency=null; + + public Puzzle(String name) + { + this.name = name; + } + + public boolean hasDependency() + { + return dependency != null; + + } + + public void setDependency(Puzzle p) + { + dependency = p; + } + + public void setDependencyText(String s) + { + dependencyText = s; + } + + public Puzzle getDependency() + { + return dependency; + } + + public String getDependencyText() + { + return dependencyText; + } + + public int getId() { + return id; + } + + public Room getNextRoom() + { + return nextRoom; + } + + public void setId(int id) { + this.id = id; + } + + public void addItem(Item i) + { + items.add(i); + } + + public ArrayList getItems() { + return items; + } + + public void setItems(ArrayList items) { + this.items = items; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getSolvedText() { + return solvedText; + } + + public void setSolvedText(String solvedText) { + this.solvedText = solvedText; + } + + public boolean isSolved() { + return solved; + } + + public void setSolved(boolean solved) { + this.solved = solved; + } + + public void setGameOverFlag(boolean b) { + // TODO Auto-generated method stub + gameOverFlag = b; + + } + + public boolean getGameOverFlag() { + // TODO Auto-generated method stub + return gameOverFlag; + } + + public void setNextRoom(Room r) + { + nextRoom = r; + } +} diff --git a/src/java/Room.java b/src/java/Room.java new file mode 100644 index 0000000..639d2f4 --- /dev/null +++ b/src/java/Room.java @@ -0,0 +1,69 @@ +import java.util.ArrayList; + + +public class Room +{ + private int id; + private String name; + private String description; + private boolean gameoverFlag; + ArrayList items = new ArrayList<>(); + ArrayList puzzles = new ArrayList<>(); + public Room(String name) + { + this.name = name; + } + + public Item getItem(String s) + { + for(Item i: items) + { + if(i.getName().equals(s)) + return i; + } + return null; + } + + public Puzzle getPuzzle(String s) + { + for(Puzzle p: puzzles) + { + if(p.getName().equals(s)) + return p; + } + return null; + } + + public int getId() { + return id; + } + public void setId(int id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + public boolean getGameoverFlag() { + return gameoverFlag; + } + public void setGameoverFlag(boolean gameOverFlag) { + gameoverFlag = gameOverFlag; + } + public ArrayList getItems() { + return items; + } + + public ArrayList getPuzzles() { + return puzzles; + } + +} diff --git a/web/index.html b/web/index.html new file mode 100644 index 0000000..53f682b --- /dev/null +++ b/web/index.html @@ -0,0 +1,66 @@ + + + + Kidnappd Test + + + + + + +

Kidnapp'd

+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
    +
    + + + + + \ No newline at end of file