Browse Source

Merge origin/master

master
Edi 5 years ago
parent
commit
5996c744a2

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

@@ -998,11 +998,17 @@ exists or setup the property manually. For example like this:
<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">
<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"/>
<manifest file="${build.web.dir}/META-INF/MANIFEST.MF" mode="update"/>
</target>
<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="${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 depends="init" if="dist.ear.dir" name="-clean-webinf-lib">
<delete dir="${build.web.dir}/WEB-INF/lib"/>

+ 3
- 3
nbproject/genfiles.properties View File

@@ -1,8 +1,8 @@
build.xml.data.CRC32=b50c735c
build.xml.data.CRC32=20a1ec55
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.data.CRC32=20a1ec55
nbproject/build-impl.xml.script.CRC32=b4f5594b
nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.77.1.1

+ 7
- 1
nbproject/project.properties View File

@@ -28,6 +28,9 @@ dist.war=${dist.dir}/${war.name}
endorsed.classpath=\
${libs.javaee-endorsed-api-7.0.classpath}
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=**
j2ee.compile.on.save=true
j2ee.copy.static.files.on.save=true
@@ -42,7 +45,10 @@ j2ee.platform.wsit.classpath=
j2ee.server.type=gfv3ee6
jar.compress=false
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
javac.compilerargs=
javac.debug=true

+ 12
- 0
nbproject/project.xml View File

@@ -10,6 +10,18 @@
<file>${libs.javaee-web-api-7.0.classpath}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</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-additional-libraries/>
<source-roots>

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

@@ -1,34 +1,50 @@
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.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
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;
import java.util.Map;
import javax.json.stream.JsonGenerationException;
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 static ArrayList<Item> items = new ArrayList<Item>();
private static ArrayList<Puzzle> puzzles = new ArrayList<Puzzle>();
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() {
try {
@@ -38,7 +54,83 @@ public class Game {
}
}
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 = new Room("Intro");
@@ -58,7 +150,7 @@ public class Game {
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. ");
puzzles.add(schloss);
keller.puzzles.add(schloss);
//Ausgang
@@ -67,6 +159,7 @@ public class Game {
door.setGameOverFlag(true);
door.setSolvedText("Geschafft! Die Tuer ist offen. Das Intro ist nun beendet");
keller.puzzles.add(door);
puzzles.add(door);
//Item Object
schluessel = new Item("Schluessel");
@@ -75,6 +168,7 @@ public class Game {
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);
items.add(schluessel);
door.setDependency(schloss);
door.setDependencyText("Du musst erst das Schloss der Kette knacken um die Tür öffnen zu können");
@@ -85,6 +179,7 @@ public class Game {
stahlschluessel.setPortableFlag(false);
stahlschluessel.setDescription("Ein Stahlschlüssel");
intro.items.add(stahlschluessel);
items.add(stahlschluessel);
rooms.add(intro);
rooms.add(keller);
@@ -99,18 +194,82 @@ public class Game {
currentRoom = intro;
stoppFlag = false;
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 {
log("play()");
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("ü", "ue");
input = input.replace("ö", "oe");
input = input.replace("ß", "ss");
if (input.contains(" ")) {
inputArray = input.split(" ");
@@ -134,22 +293,22 @@ public class Game {
switch (intentName.toLowerCase()) {
//intent
case "lookaroundintent":
log("Switch: lookAroundIntent");
log("Switch: LookAroundIntent");
if (itemName == null && puzzleName == null) {
lookaround();
}
break;
//intent
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":
log("Switch: ExamineIntent");
if (itemName == null && puzzleName == null) {
@@ -160,14 +319,14 @@ public class Game {
//intent
case "takeintent":
log("Switch: TakeIntent");
if (itemName != null) {
if (currentRoom.getItem(itemName) != null) {
take(currentRoom.getItem(itemName));
}
break;
//intent
case "openintent":
log("Switch: OpenIntent");
if (puzzleName != null) {
if (currentRoom.getPuzzle(puzzleName) != null) {
open(currentRoom.getPuzzle(puzzleName));
}
break;
@@ -190,7 +349,6 @@ public class Game {
}
}
}
break;
}
@@ -198,16 +356,15 @@ public class Game {
itemName = null;
intentName = null;
puzzleName = null;
log("stoppFlag: " + stoppFlag);
if (stoppFlag == true) {
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";
URL obj = new URL(url);
HttpURLConnection httpConn = (HttpURLConnection) obj.openConnection();
@@ -237,43 +394,44 @@ public class Game {
}
public void lookaround() throws Exception {
log("lookaround() ");
log("lookaround()");
say(currentRoom.getDescription());
}
public void startGame() throws Exception {
log("startGame() ");
log("startGame()");
for (int i = 0; i < story.size(); i++) {
say(story.get(i));
}
}
public void resetGame() throws Exception {
log("resetGame() ");
log("resetGame()");
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 {
log("endGame() ");
log("endGame()");
say("Glückwunsch das Spiel ist beendet!");
setVariables();
}
@@ -309,7 +467,7 @@ public class Game {
}
public void say(String s) throws Exception {
log("say(" + s + ") ");
log("say(" + s + ")");
try {
sendPost(s);
} catch (Exception ex) {
@@ -318,12 +476,12 @@ public class Game {
}
public void setInput(String s) throws Exception {
log("setInput(" + s + ") ");
log("setInput(" + s + ")");
input = s;
}
public void setRoom(Room nextRoom) throws Exception {
log("setRoom(" + nextRoom.getName() + ") " );
log("setRoom(" + nextRoom.getName() + ")");
currentRoom = nextRoom;
say(currentRoom.getDescription());
}
@@ -348,7 +506,7 @@ public class Game {
}
public void open(Puzzle currentPuzzle) throws Exception {
log("open(" + currentPuzzle.getName() + ") ");
log("open(" + currentPuzzle.getName() + ") ");
if (currentPuzzle.isSolved()) // bereits gelöst
{
say("ist bereits geöffnet");

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

@@ -5,6 +5,20 @@ public class Item
private boolean portableFlag;
private boolean hiddenFlag;
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)
{
this.name = name;

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

@@ -35,8 +35,14 @@ public class Logic extends HttpServlet {
String context = "";
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)
throws ServletException, IOException, Exception {

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

@@ -17,6 +17,24 @@ public class Puzzle
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()
{
return dependency != null;

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

@@ -12,7 +12,21 @@ public class Room
{
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)
{
for(Item i: items)

Loading…
Cancel
Save