Browse Source

Merge origin/master

master
Edi 4 years ago
parent
commit
5996c744a2

+ 6
- 0
nbproject/build-impl.xml View File

<target depends="init,compile,compile-jsps,-pre-dist,-do-dist-with-manifest,-do-dist-without-manifest" name="do-dist"/> <target depends="init,compile,compile-jsps,-pre-dist,-do-dist-with-manifest,-do-dist-without-manifest" name="do-dist"/>
<target depends="init" if="dist.ear.dir" name="library-inclusion-in-manifest"> <target depends="init" if="dist.ear.dir" name="library-inclusion-in-manifest">
<copyfiles files="${libs.javaee-web-api-7.0.classpath}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/> <copyfiles files="${libs.javaee-web-api-7.0.classpath}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.jackson-annotations-2.9.0.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.jackson-core-2.9.9.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.jackson-databind-2.9.9.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<mkdir dir="${build.web.dir}/META-INF"/> <mkdir dir="${build.web.dir}/META-INF"/>
<manifest file="${build.web.dir}/META-INF/MANIFEST.MF" mode="update"/> <manifest file="${build.web.dir}/META-INF/MANIFEST.MF" mode="update"/>
</target> </target>
<target depends="init" name="library-inclusion-in-archive" unless="dist.ear.dir"> <target depends="init" name="library-inclusion-in-archive" unless="dist.ear.dir">
<copyfiles files="${libs.javaee-web-api-7.0.classpath}" todir="${build.web.dir}/WEB-INF/lib"/> <copyfiles files="${libs.javaee-web-api-7.0.classpath}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.jackson-annotations-2.9.0.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.jackson-core-2.9.9.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.jackson-databind-2.9.9.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
</target> </target>
<target depends="init" if="dist.ear.dir" name="-clean-webinf-lib"> <target depends="init" if="dist.ear.dir" name="-clean-webinf-lib">
<delete dir="${build.web.dir}/WEB-INF/lib"/> <delete dir="${build.web.dir}/WEB-INF/lib"/>

+ 3
- 3
nbproject/genfiles.properties View File

build.xml.data.CRC32=b50c735c
build.xml.data.CRC32=20a1ec55
build.xml.script.CRC32=2d64e8d1 build.xml.script.CRC32=2d64e8d1
build.xml.stylesheet.CRC32=651128d4@1.77.1.1 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. # 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. # 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.data.CRC32=20a1ec55
nbproject/build-impl.xml.script.CRC32=b4f5594b
nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.77.1.1 nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.77.1.1

+ 7
- 1
nbproject/project.properties View File

endorsed.classpath=\ endorsed.classpath=\
${libs.javaee-endorsed-api-7.0.classpath} ${libs.javaee-endorsed-api-7.0.classpath}
excludes= excludes=
file.reference.jackson-annotations-2.9.0.jar=C:\\Users\\Edi\\Desktop\\jackson-annotations-2.9.0.jar
file.reference.jackson-core-2.9.9.jar=C:\\Users\\Edi\\Desktop\\jackson-core-2.9.9.jar
file.reference.jackson-databind-2.9.9.jar=C:\\Users\\Edi\\Desktop\\jackson-databind-2.9.9.jar
includes=** includes=**
j2ee.compile.on.save=true j2ee.compile.on.save=true
j2ee.copy.static.files.on.save=true j2ee.copy.static.files.on.save=true
j2ee.server.type=gfv3ee6 j2ee.server.type=gfv3ee6
jar.compress=false jar.compress=false
javac.classpath=\ javac.classpath=\
${libs.javaee-web-api-7.0.classpath}
${libs.javaee-web-api-7.0.classpath}:\
${file.reference.jackson-annotations-2.9.0.jar}:\
${file.reference.jackson-core-2.9.9.jar}:\
${file.reference.jackson-databind-2.9.9.jar}
# Space-separated list of extra javac options # Space-separated list of extra javac options
javac.compilerargs= javac.compilerargs=
javac.debug=true javac.debug=true

+ 12
- 0
nbproject/project.xml View File

<file>${libs.javaee-web-api-7.0.classpath}</file> <file>${libs.javaee-web-api-7.0.classpath}</file>
<path-in-war>WEB-INF/lib</path-in-war> <path-in-war>WEB-INF/lib</path-in-war>
</library> </library>
<library dirs="200">
<file>${file.reference.jackson-annotations-2.9.0.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library dirs="200">
<file>${file.reference.jackson-core-2.9.9.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library dirs="200">
<file>${file.reference.jackson-databind-2.9.9.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
</web-module-libraries> </web-module-libraries>
<web-module-additional-libraries/> <web-module-additional-libraries/>
<source-roots> <source-roots>

+ 217
- 59
src/java/Game.java View File

import com.fasterxml.jackson.core.JsonEncoding;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.util.Map;
import javax.json.stream.JsonGenerationException;
public class Game { public class Game {
private static ArrayList<Room> rooms = new ArrayList<Room>(); private static ArrayList<Room> rooms = new ArrayList<Room>();
private static ArrayList<Item> inventory = new ArrayList<Item>(); private static ArrayList<Item> inventory = new ArrayList<Item>();
private static ArrayList<String> story = new ArrayList<String>(); private static ArrayList<String> story = new ArrayList<String>();
private static ArrayList<Item> items = new ArrayList<Item>();
private static ArrayList<Puzzle> puzzles = new ArrayList<Puzzle>();
private boolean stoppFlag = false; private boolean stoppFlag = false;
String[] inputArray = null;
String itemName = null;
String intentName = null;
String puzzleName = null;
String input = null;
Room currentRoom = null;
Room intro;
Room keller;
Puzzle durchgang;
Puzzle schloss;
Puzzle door;
Item schluessel;
Item stahlschluessel;
private Map<String, Object> jsonMap = null;
private String[] inputArray = null;
private String itemName = null;
private String intentName = null;
private String puzzleName = null;
private String input = null;
private Room currentRoom = null;
private Room intro;
private Room keller;
private Puzzle durchgang;
private Puzzle schloss;
private Puzzle door;
private Item schluessel;
private Item stahlschluessel;
public Game() { public Game() {
try { try {
} }
} }
public void setVariables() {
public Map<String, Object> readJSON() throws IOException, Exception {
//TODO: Define path!
File file = new File("game.JSON");
try {
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String jsonObject = br.readLine();
ObjectMapper objectMapper = new ObjectMapper();
try {
jsonMap = objectMapper.readValue(jsonObject,
new TypeReference<Map<String, Object>>() {
});
} catch (JsonParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonMap;
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return null;
}
public static String generateJSON() throws IOException {
ObjectMapper mapper = new ObjectMapper();
String s = "";
try (
JsonGenerator jGenerator
= mapper.getFactory().createGenerator(
new File("game.JSON"),
JsonEncoding.UTF8)) {
jGenerator.writeStartObject();
jGenerator.writeObjectField("room", rooms);
jGenerator.writeObjectField("puzzle", puzzles);
jGenerator.writeObjectField("item", items);
jGenerator.writeObjectField("story", story);
jGenerator.writeEndObject();
jGenerator.close();
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader("game.JSON"));
} catch (FileNotFoundException ex) {
Logger.getLogger(Game.class.getName()).log(Level.SEVERE, null, ex);
}
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
s = s + (line + "\n");
}
return s;
}
public void setVariables() throws Exception {
// Intro Raum // Intro Raum
intro = new Room("Intro"); intro = new Room("Intro");
schloss = new Puzzle("Schloss"); schloss = new Puzzle("Schloss");
schloss.setDescription("Es ist ein altes Schloss aus Metall, dass eine Einkerbung f�r einen Schl�ssel hat"); 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. "); schloss.setSolvedText("Ja, es hat funktioniert! Mit einem Knacksen geht das Schloss auf und du kannst dich von deiner Beinfessel befreien. ");
puzzles.add(schloss);
keller.puzzles.add(schloss); keller.puzzles.add(schloss);
//Ausgang //Ausgang
door.setGameOverFlag(true); door.setGameOverFlag(true);
door.setSolvedText("Geschafft! Die Tuer ist offen. Das Intro ist nun beendet"); door.setSolvedText("Geschafft! Die Tuer ist offen. Das Intro ist nun beendet");
keller.puzzles.add(door); keller.puzzles.add(door);
puzzles.add(door);
//Item Object //Item Object
schluessel = new Item("Schluessel"); schluessel = new Item("Schluessel");
schluessel.setDescription("Der Schl�ssel ist kalt und klein. Vielleicht hast du Gl�ck und er passt ins Schloss. Versuche es zu �ffnen!"); 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); schloss.addItem(schluessel);
keller.items.add(schluessel); keller.items.add(schluessel);
items.add(schluessel);
door.setDependency(schloss); door.setDependency(schloss);
door.setDependencyText("Du musst erst das Schloss der Kette knacken um die Tür öffnen zu können"); door.setDependencyText("Du musst erst das Schloss der Kette knacken um die Tür öffnen zu können");
stahlschluessel.setPortableFlag(false); stahlschluessel.setPortableFlag(false);
stahlschluessel.setDescription("Ein Stahlschlüssel"); stahlschluessel.setDescription("Ein Stahlschlüssel");
intro.items.add(stahlschluessel); intro.items.add(stahlschluessel);
items.add(stahlschluessel);
rooms.add(intro); rooms.add(intro);
rooms.add(keller); rooms.add(keller);
currentRoom = intro; currentRoom = intro;
stoppFlag = false; stoppFlag = false;
inventory = new ArrayList<Item>(); inventory = new ArrayList<Item>();
log("JSON: " + generateJSON());
readJSON();
log("Readjson fertig");
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
String jsonStringRoom = objectMapper.writeValueAsString(jsonMap.get("room"));
String jsonStringItem = objectMapper.writeValueAsString(jsonMap.get("item"));
String jsonStringPuzzle = objectMapper.writeValueAsString(jsonMap.get("puzzle"));
String jsonStringStory = objectMapper.writeValueAsString(jsonMap.get("story"));
log("Item: " + jsonStringItem);
log("Room: " + jsonStringRoom);
log("Story: " + jsonStringStory);
log("Puzzle: " + jsonStringPuzzle);
String[] st = objectMapper.readValue(jsonStringStory, String[].class);
log("Story Array OK");
Item[] it = objectMapper.readValue(jsonStringItem, Item[].class);
log("Item Array OK");
Puzzle[] pu = objectMapper.readValue(jsonStringPuzzle, Puzzle[].class);
log("Puzzle Array OK");
Room[] ro = objectMapper.readValue(jsonStringRoom, Room[].class);
log("Room Array OK");
for(int i=0; i < ro.length; i++)
{
log("Room: " + ro[i].getName());
log("Description: " + ro[i].getDescription());
}
for(int i=0; i < it.length; i++)
{
log("Item: " + it[i].getName());
log("Description: " + it[i].getDescription());
}
for(int i=0; i < pu.length; i++)
{
log("Puzzle: " + pu[i].getName());
log("Description: " + pu[i].getDescription());
log("DependencyText: " + pu[i].getDependencyText());
}
for(int i=0; i < st.length; i++)
{
log("Story: " + st[i]);
}
} }
public void play() throws Exception { public void play() throws Exception {
log("play()"); log("play()");
log("Input: " + input); log("Input: " + input);
log("currentRoom: " + currentRoom.getName());
for (int i = 0; i < currentRoom.getPuzzles().size(); i++) {
log("Puzzle im Raum: " + currentRoom.getPuzzles().get(i).getName());
}
for (int i = 0; i < currentRoom.getItems().size(); i++) {
log("Item im Raum: " + currentRoom.getItems().get(i).getName());
}
input = input.replace("ä", "ae"); input = input.replace("ä", "ae");
input = input.replace("ü", "ue"); input = input.replace("ü", "ue");
input = input.replace("ö", "oe"); input = input.replace("ö", "oe");
input = input.replace("ß", "ss"); input = input.replace("ß", "ss");
if (input.contains(" ")) { if (input.contains(" ")) {
inputArray = input.split(" "); inputArray = input.split(" ");
switch (intentName.toLowerCase()) { switch (intentName.toLowerCase()) {
//intent //intent
case "lookaroundintent": case "lookaroundintent":
log("Switch: lookAroundIntent");
log("Switch: LookAroundIntent");
if (itemName == null && puzzleName == null) { if (itemName == null && puzzleName == null) {
lookaround(); lookaround();
} }
break; break;
//intent //intent
case "inspectintent": case "inspectintent":
log("Switch: inspectintent");
if (itemName != null) {
inspect(itemName);
} else if (puzzleName != null) {
inspect(puzzleName);
log("Switch: InspectIntent");
if (currentRoom.getItem(itemName) != null) {
inspect(currentRoom.getItem(itemName));
} else if (currentRoom.getPuzzle(puzzleName) != null) {
inspect(currentRoom.getPuzzle(puzzleName));
} }
break;
//intent
break;
//intent
case "examineintent": case "examineintent":
log("Switch: ExamineIntent"); log("Switch: ExamineIntent");
if (itemName == null && puzzleName == null) { if (itemName == null && puzzleName == null) {
//intent //intent
case "takeintent": case "takeintent":
log("Switch: TakeIntent"); log("Switch: TakeIntent");
if (itemName != null) {
if (currentRoom.getItem(itemName) != null) {
take(currentRoom.getItem(itemName)); take(currentRoom.getItem(itemName));
} }
break; break;
//intent //intent
case "openintent": case "openintent":
log("Switch: OpenIntent"); log("Switch: OpenIntent");
if (puzzleName != null) {
if (currentRoom.getPuzzle(puzzleName) != null) {
open(currentRoom.getPuzzle(puzzleName)); open(currentRoom.getPuzzle(puzzleName));
} }
break; break;
} }
} }
} }
break; break;
} }
itemName = null; itemName = null;
intentName = null; intentName = null;
puzzleName = null; puzzleName = null;
log("stoppFlag: " + stoppFlag); log("stoppFlag: " + stoppFlag);
if (stoppFlag == true) { if (stoppFlag == true) {
endGame(); endGame();
} }
} }
public void log(String s) throws Exception
{
public void log(String s) throws Exception {
String url = "https://medinf.efi.th-nuernberg.de/tomcat/WebAdventure/Log"; String url = "https://medinf.efi.th-nuernberg.de/tomcat/WebAdventure/Log";
URL obj = new URL(url); URL obj = new URL(url);
HttpURLConnection httpConn = (HttpURLConnection) obj.openConnection(); HttpURLConnection httpConn = (HttpURLConnection) obj.openConnection();
} }
public void lookaround() throws Exception { public void lookaround() throws Exception {
log("lookaround() ");
log("lookaround()");
say(currentRoom.getDescription()); say(currentRoom.getDescription());
} }
public void startGame() throws Exception { public void startGame() throws Exception {
log("startGame() ");
log("startGame()");
for (int i = 0; i < story.size(); i++) { for (int i = 0; i < story.size(); i++) {
say(story.get(i)); say(story.get(i));
} }
} }
public void resetGame() throws Exception { public void resetGame() throws Exception {
log("resetGame() ");
log("resetGame()");
startGame(); startGame();
} }
public void inspect(String s) throws Exception {
log("inspect(" + s + ") ");
Item currentItem=null;
if(currentRoom.getItem(s) != null)
{
currentItem= currentRoom.getItem(s);
log("currentItem: " + currentItem.getName());
say(currentItem.getDescription());
public void inspect(Puzzle currentPuzzle) throws Exception {
log("inspect(" + currentPuzzle.getName() + ")");
for (int i = 0; i < currentRoom.getItems().size(); i++) {
if (currentRoom.getPuzzles().get(i) == currentPuzzle) {
say(currentPuzzle.getDescription());
}
} }
Puzzle currentPuzzle=null;
if(currentRoom.getPuzzle(s) != null)
{
currentPuzzle = currentRoom.getPuzzle(s);
log("currentPuzzle " + currentPuzzle.getName());
say(currentPuzzle.getDescription());
}
public void inspect(Item currentItem) throws Exception {
log("inspect(" + currentItem.getName() + ")");
for (int i = 0; i < currentRoom.getItems().size(); i++) {
if (currentRoom.getItems().get(i) == currentItem) {
say(currentItem.getDescription());
}
} }
} }
public void endGame() throws Exception { public void endGame() throws Exception {
log("endGame() ");
log("endGame()");
say("Glückwunsch das Spiel ist beendet!"); say("Glückwunsch das Spiel ist beendet!");
setVariables(); setVariables();
} }
} }
public void say(String s) throws Exception { public void say(String s) throws Exception {
log("say(" + s + ") ");
log("say(" + s + ")");
try { try {
sendPost(s); sendPost(s);
} catch (Exception ex) { } catch (Exception ex) {
} }
public void setInput(String s) throws Exception { public void setInput(String s) throws Exception {
log("setInput(" + s + ") ");
log("setInput(" + s + ")");
input = s; input = s;
} }
public void setRoom(Room nextRoom) throws Exception { public void setRoom(Room nextRoom) throws Exception {
log("setRoom(" + nextRoom.getName() + ") " );
log("setRoom(" + nextRoom.getName() + ")");
currentRoom = nextRoom; currentRoom = nextRoom;
say(currentRoom.getDescription()); say(currentRoom.getDescription());
} }
} }
public void open(Puzzle currentPuzzle) throws Exception { public void open(Puzzle currentPuzzle) throws Exception {
log("open(" + currentPuzzle.getName() + ") ");
log("open(" + currentPuzzle.getName() + ") ");
if (currentPuzzle.isSolved()) // bereits gelöst if (currentPuzzle.isSolved()) // bereits gelöst
{ {
say("ist bereits geöffnet"); say("ist bereits geöffnet");

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

private boolean portableFlag; private boolean portableFlag;
private boolean hiddenFlag; private boolean hiddenFlag;
private String description; private String description;
public Item(String n, boolean p, boolean h, String d)
{
name = n;
portableFlag = p;
hiddenFlag = h;
description = d;
}
public Item()
{
}
public Item(String name) public Item(String name)
{ {
this.name = name; this.name = name;

+ 7
- 1
src/java/Logic.java View File

String context = ""; String context = "";
public void init() { public void init() {
g.setVariables();
try {
g.setVariables();
} catch (Exception ex) {
Logger.getLogger(Logic.class.getName()).log(Level.SEVERE, null, ex);
}
} }
protected void processRequest(HttpServletRequest request, HttpServletResponse response) protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, Exception { throws ServletException, IOException, Exception {

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

this.name = name; this.name = name;
} }
public Puzzle()
{
}
public Puzzle(String n, ArrayList<Item> i, String d, boolean s, String st, boolean g, Room nx, String dt, Puzzle p)
{
name = n;
items = i;
description = d;
solved = s;
solvedText = st;
gameOverFlag = g;
nextRoom = nx;
dependencyText = dt;
dependency = p;
}
public boolean hasDependency() public boolean hasDependency()
{ {
return dependency != null; return dependency != null;

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

{ {
this.name = name; this.name = name;
} }
public Room()
{
}
public Room(String n, String d, boolean g, ArrayList<Item> i, ArrayList<Puzzle> p)
{
name = n;
description = d;
gameoverFlag = g;
items = i;
puzzles = p;
}
public Item getItem(String s) public Item getItem(String s)
{ {
for(Item i: items) for(Item i: items)

Loading…
Cancel
Save