Browse Source

Test

master
Edi 5 years ago
commit
a2f9f3404f

+ 71
- 0
build.xml View File

@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="WebAdventure" default="default" basedir=".">
<description>Builds, tests, and runs the project WebAdventure.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-dist: called before archive building
-post-dist: called after archive building
-post-clean: called after cleaning build products
-pre-run-deploy: called before deploying
-post-run-deploy: called after deploying
Example of pluging an obfuscator after the compilation could look like
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Other way how to customize the build is by overriding existing main targets.
The target of interest are:
init-macrodef-javac: defines macro for javac compilation
init-macrodef-junit: defines macro for junit execution
init-macrodef-debug: defines macro for class debugging
do-dist: archive building
run: execution of project
javadoc-build: javadoc generation
Example of overriding the target for project execution could look like
<target name="run" depends="<PROJNAME>-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that overridden target depends on jar target and not only on
compile target as regular run target does. Again, for list of available
properties which you can use check the target you are overriding in
nbproject/build-impl.xml file.
-->
</project>

+ 150
- 0
nbproject/ant-deploy.xml View File

@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

Copyright (c) 2008, 2016 Oracle and/or its affiliates. All rights reserved.

Oracle and Java are registered trademarks of Oracle and/or its affiliates.
Other names may be trademarks of their respective owners.

The contents of this file are subject to the terms of either the GNU
General Public License Version 2 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://www.netbeans.org/cddl-gplv2.html
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License file at
nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the GPL Version 2 section of the License file that
accompanied this code. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"

If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 2, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 2] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 2 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 2 code and therefore, elected the GPL
Version 2 license, then the option applies only if the new code is
made subject to such option by the copyright holder.

Contributor(s):
-->
<project default="-deploy-ant" basedir=".">
<target name="-init-cl-deployment-env" if="deploy.ant.enabled">
<property file="${deploy.ant.properties.file}" />
<available file="${deploy.ant.docbase.dir}/WEB-INF/sun-web.xml" property="sun.web.present"/>
<available file="${deploy.ant.docbase.dir}/WEB-INF/glassfish-web.xml" property="glassfish.web.present"/>
<available file="${deploy.ant.resource.dir}" property="has.setup"/>
<tempfile prefix="gfv3" property="gfv3.password.file" destdir="${java.io.tmpdir}"/> <!-- do not forget to delete this! -->
<echo message="AS_ADMIN_PASSWORD=${gfv3.password}" file="${gfv3.password.file}"/>
</target>

<target name="-parse-sun-web" depends="-init-cl-deployment-env" if="sun.web.present">
<tempfile prefix="gfv3" property="temp.sun.web" destdir="${java.io.tmpdir}"/>
<copy file="${deploy.ant.docbase.dir}/WEB-INF/sun-web.xml" tofile="${temp.sun.web}"/>
<!-- The doctype triggers resolution which can fail -->
<replace file="${temp.sun.web}">
<replacetoken><![CDATA[<!DOCTYPE]]></replacetoken>
<replacevalue><![CDATA[<!-- <!DOCTYPE]]></replacevalue>
</replace>
<replace file="${temp.sun.web}">
<replacetoken><![CDATA[<sun-web-app]]></replacetoken>
<replacevalue><![CDATA[--> <sun-web-app]]></replacevalue>
</replace>
<xmlproperty file="${temp.sun.web}" validate="false">
</xmlproperty>
<delete file="${temp.sun.web}"/>
<condition property="deploy.ant.client.url" value="${gfv3.url}${sun-web-app.context-root}" else="${gfv3.url}/${ant.project.name}">
<isset property="sun-web-app.context-root"/>
</condition>
<condition property="deploy.context.root.argument" value="&amp;contextroot=${sun-web-app.context-root}" else="/${ant.project.name}">
<isset property="sun-web-app.context-root"/>
</condition>
</target>
<target name="-parse-glassfish-web" depends="-init-cl-deployment-env" if="glassfish.web.present">
<tempfile prefix="gfv3" property="temp.gf.web" destdir="${java.io.tmpdir}"/>
<copy file="${deploy.ant.docbase.dir}/WEB-INF/glassfish-web.xml" tofile="${temp.gf.web}"/>
<!-- The doctype triggers resolution which can fail -->
<replace file="${temp.gf.web}">
<replacetoken><![CDATA[<!DOCTYPE]]></replacetoken>
<replacevalue><![CDATA[<!-- <!DOCTYPE]]></replacevalue>
</replace>
<replace file="${temp.gf.web}">
<replacetoken><![CDATA[<glassfish-web-app]]></replacetoken>
<replacevalue><![CDATA[--> <glassfish-web-app]]></replacevalue>
</replace>
<xmlproperty file="${temp.gf.web}" validate="false">
</xmlproperty>
<delete file="${temp.gf.web}"/>
<condition property="deploy.ant.client.url" value="${gfv3.url}${glassfish-web-app.context-root}" else="${gfv3.url}/${ant.project.name}">
<isset property="glassfish-web-app.context-root"/>
</condition>
<condition property="deploy.context.root.argument" value="&amp;contextroot=${glassfish-web-app.context-root}" else="/${ant.project.name}">
<isset property="glassfish-web-app.context-root"/>
</condition>
</target>
<target name="-no-parse-sun-web" depends="-init-cl-deployment-env" unless="sun.web.present">
<property name="deploy.context.root.argument" value=""/>
</target>
<target name="-add-resources" depends="-init-cl-deployment-env" if="has.setup">
<tempfile prefix="gfv3" property="gfv3.resources.dir" destdir="${java.io.tmpdir}"/>
<mkdir dir="${gfv3.resources.dir}"/>
<mkdir dir="${gfv3.resources.dir}/META-INF"/>
<copy todir="${gfv3.resources.dir}/META-INF">
<fileset dir="${deploy.ant.resource.dir}"/>
</copy>
<jar destfile="${deploy.ant.archive}" update="true">
<fileset dir="${gfv3.resources.dir}"/>
</jar>
<delete dir="${gfv3.resources.dir}"/>
</target>
<target name="-deploy-ant" depends="-parse-glassfish-web, -parse-sun-web, -no-parse-sun-web,-add-resources" if="deploy.ant.enabled">
<antcall target="-deploy-without-pw"/>
<antcall target="-deploy-with-pw"/>
</target>

<target name="-deploy-without-pw" unless="gfv3.password">
<echo message="Deploying ${deploy.ant.archive}"/>
<tempfile prefix="gfv3" property="gfv3.results.file" destdir="${java.io.tmpdir}"/> <!-- do not forget to delete this! -->
<property name="full.deploy.ant.archive" location="${deploy.ant.archive}"/>
<get src="${gfv3.admin.url}/__asadmin/deploy?path=${full.deploy.ant.archive}${deploy.context.root.argument}&amp;force=true&amp;name=${ant.project.name}"
dest="${gfv3.results.file}"/>
<delete file="${gfv3.results.file}"/>
</target>
<target name="-deploy-with-pw" if="gfv3.password">
<echo message="Deploying ${deploy.ant.archive}"/>
<tempfile prefix="gfv3" property="gfv3.results.file" destdir="${java.io.tmpdir}"/> <!-- do not forget to delete this! -->
<property name="full.deploy.ant.archive" location="${deploy.ant.archive}"/>
<get username="${gfv3.username}" password="${gfv3.password}" src="${gfv3.admin.url}/__asadmin/deploy?path=${full.deploy.ant.archive}${deploy.context.root.argument}&amp;force=true&amp;name=${ant.project.name}"
dest="${gfv3.results.file}"/>
<delete file="${gfv3.results.file}"/>
</target>
<target name="-undeploy-ant" depends="-init-cl-deployment-env" if="deploy.ant.enabled">
<antcall target="-undeploy-without-pw"/>
<antcall target="-undeploy-with-pw"/>
</target>

<target name="-undeploy-without-pw" unless="gfv3.password">
<echo message="Undeploying ${deploy.ant.archive}"/>
<tempfile prefix="gfv3" property="gfv3.results.file" destdir="${java.io.tmpdir}"/> <!-- do not forget to delete this! -->
<get src="${gfv3.admin.url}/__asadmin/undeploy?name=${ant.project.name}"
dest="${gfv3.results.file}"/>
<delete file="${gfv3.results.file}"/>
</target>
<target name="-undeploy-with-pw" if="gfv3.password">
<echo message="Undeploying ${deploy.ant.archive}"/>
<tempfile prefix="gfv3" property="gfv3.results.file" destdir="${java.io.tmpdir}"/> <!-- do not forget to delete this! -->
<get username="${gfv3.username}" password="${gfv3.password}" src="${gfv3.admin.url}/__asadmin/undeploy?name=${ant.project.name}"
dest="${gfv3.results.file}"/>
<delete file="${gfv3.results.file}"/>
</target>
</project>

+ 1444
- 0
nbproject/build-impl.xml
File diff suppressed because it is too large
View File


+ 8
- 0
nbproject/genfiles.properties View File

@@ -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

+ 89
- 0
nbproject/project.properties View File

@@ -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

+ 23
- 0
nbproject/project.xml View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.web.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/web-project/3">
<name>WebAdventure</name>
<minimum-ant-version>1.6.5</minimum-ant-version>
<web-module-libraries>
<library dirs="200">
<file>${libs.javaee-web-api-7.0.classpath}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
</web-module-libraries>
<web-module-additional-libraries/>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

+ 2
- 0
src/conf/MANIFEST.MF View File

@@ -0,0 +1,2 @@
Manifest-Version: 1.0

+ 330
- 0
src/java/Game.java View File

@@ -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<Room> rooms = new ArrayList<Room>();
private static ArrayList<Item> inventory = new ArrayList<Item>();
private static ArrayList<String> story = new ArrayList<String>();
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<Item> 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<Room> getRooms() {
return rooms;
}
public ArrayList<Item> getInventory() {
return inventory;
}
public ArrayList<String> getStory() {
return story;
}
}

+ 55
- 0
src/java/Item.java View File

@@ -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;
}
}

+ 119
- 0
src/java/Logic.java View File

@@ -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 <code>GET</code> and <code>POST</code>
* 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("<html><body><p>" + context + "</p></body></html>");
if (request.getParameter("alexaText") != null) {
context = context + "<br><br>" + 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();
}
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> 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 <code>POST</code> 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";
}// </editor-fold>
}

+ 120
- 0
src/java/Puzzle.java View File

@@ -0,0 +1,120 @@
import java.util.ArrayList;
public class Puzzle
{
private int id;
private String name;
private ArrayList<Item> items = new ArrayList<Item>();
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<Item> getItems() {
return items;
}
public void setItems(ArrayList<Item> 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;
}
}

+ 69
- 0
src/java/Room.java View File

@@ -0,0 +1,69 @@
import java.util.ArrayList;
public class Room
{
private int id;
private String name;
private String description;
private boolean gameoverFlag;
ArrayList<Item> items = new ArrayList<>();
ArrayList<Puzzle> 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<Item> getItems() {
return items;
}
public ArrayList<Puzzle> getPuzzles() {
return puzzles;
}
}

+ 66
- 0
web/index.html View File

@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html>
<head>
<title>Kidnappd Test</title>
<meta charset=utf-8>
<link rel="stylesheet" type="text/css" href="style.css">


</head>
<body>
<h1>Kidnapp'd</h1>
<div id=btns>

<div><button>inspectintent</button>
</div>
<div><button id=um>lookaroundintent</button>
</div>
<div><button>examineintent</button>
</div>
<div><button>takeintent</button>
</div>
<div><button>openintent</button>
</div>
<select id="itemList">
<option>Tür</option>
<option>Schloss</option>
<option>Schlüssel</option>
</select>
</div>
<div id="output">
<ol id="logList"></ol>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>

$("button").click(function(){
if ($(this).text()==="lookaroundintent")
{
$.post("https://medinf.efi.th-nuernberg.de/tomcat/WebAdventure/Logic?intent=lookaroundintent");
}
else if ($(this).text()==="examineintent")
{
$.post("https://medinf.efi.th-nuernberg.de/tomcat/WebAdventure/Logic?intent=examineintent");
}
else
{
$.post("https://medinf.efi.th-nuernberg.de/tomcat/WebAdventure/Logic?intent="+$(this).text()+"&slot="+replaceUml($("#itemList :selected").text()));
}
});

function printOutput(data) {
$("#output").animate({opacity:1},1000)
$("#logList").append(("<li><span>" + data + "</span></li>"));
}

function replaceUml(value) {
value = value.replace(/ä/g, 'ae');
value = value.replace(/ö/g, 'oe');
value = value.replace(/ü/g, 'ue');
return value;
}
</script>

</body>
</html>

Loading…
Cancel
Save