|
|
|
|
|
|
|
|
Puzzle schloss;
|
|
|
Puzzle schloss;
|
|
|
Puzzle door;
|
|
|
Puzzle door;
|
|
|
Item schluessel;
|
|
|
Item schluessel;
|
|
|
Item tonne;
|
|
|
|
|
|
|
|
|
Item stahlschluessel;
|
|
|
|
|
|
|
|
|
public Game() {
|
|
|
public Game() {
|
|
|
try {
|
|
|
|
|
|
|
|
|
try {
|
|
|
startGame();
|
|
|
startGame();
|
|
|
} catch (Exception ex) {
|
|
|
} catch (Exception ex) {
|
|
|
Logger.getLogger(Game.class.getName()).log(Level.SEVERE, null, ex);
|
|
|
Logger.getLogger(Game.class.getName()).log(Level.SEVERE, null, ex);
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public void setVariables() {
|
|
|
public void setVariables() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Intro Raum
|
|
|
// Intro Raum
|
|
|
intro = new Room("Intro");
|
|
|
intro = new Room("Intro");
|
|
|
intro.setDescription("Hier ist das Intro von Kidnappd");
|
|
|
intro.setDescription("Hier ist das Intro von Kidnappd");
|
|
|
durchgang = new Puzzle("Durchgang");
|
|
|
durchgang = new Puzzle("Durchgang");
|
|
|
durchgang.setSolvedText("Hurra, du hast das Intro Level beendet");
|
|
|
durchgang.setSolvedText("Hurra, du hast das Intro Level beendet");
|
|
|
intro.puzzles.add(durchgang);
|
|
|
intro.puzzles.add(durchgang);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Raum Object
|
|
|
//Raum Object
|
|
|
keller = new Room("Keller");
|
|
|
keller = new Room("Keller");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
durchgang.setNextRoom(keller);
|
|
|
durchgang.setNextRoom(keller);
|
|
|
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. "
|
|
|
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");
|
|
|
+ "überall h�ngen Spinnennetze und Staub sammelt sich am Betonboden. Du erkennst am anderen Ende des Raumes eine T�r");
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
//Item Object
|
|
|
//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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stahlschluessel = new Item("Stahlschluessel");
|
|
|
|
|
|
stahlschluessel.setHiddenFlag(false);
|
|
|
|
|
|
stahlschluessel.setPortableFlag(false);
|
|
|
|
|
|
stahlschluessel.setDescription("Ein Stahlschlüssel");
|
|
|
|
|
|
intro.items.add(stahlschluessel);
|
|
|
|
|
|
|
|
|
rooms.add(intro);
|
|
|
rooms.add(intro);
|
|
|
rooms.add(keller);
|
|
|
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, "
|
|
|
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, "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public void play() {
|
|
|
|
|
|
|
|
|
public void play() throws Exception {
|
|
|
|
|
|
log("play()");
|
|
|
|
|
|
log("Input: " + input);
|
|
|
|
|
|
|
|
|
|
|
|
input = input.replace("ä", "ae");
|
|
|
|
|
|
input = input.replace("ü", "ue");
|
|
|
|
|
|
input = input.replace("ö", "oe");
|
|
|
|
|
|
input = input.replace("ß", "ss");
|
|
|
|
|
|
|
|
|
if (input.contains(" ")) {
|
|
|
if (input.contains(" ")) {
|
|
|
inputArray = input.split(" ");
|
|
|
inputArray = input.split(" ");
|
|
|
|
|
|
|
|
|
for (String s : inputArray) {
|
|
|
for (String s : inputArray) {
|
|
|
if (currentRoom.getItem(s) != null) {
|
|
|
if (currentRoom.getItem(s) != null) {
|
|
|
itemName = s;
|
|
|
|
|
|
|
|
|
itemName = currentRoom.getItem(s).getName();
|
|
|
|
|
|
log("itemName: " + itemName);
|
|
|
} else if (currentRoom.getPuzzle(s) != null) {
|
|
|
} else if (currentRoom.getPuzzle(s) != null) {
|
|
|
puzzleName = s;
|
|
|
|
|
|
|
|
|
puzzleName = currentRoom.getPuzzle(s).getName();
|
|
|
|
|
|
log("PuzzleName: " + puzzleName);
|
|
|
} else {
|
|
|
} else {
|
|
|
intentName = s;
|
|
|
intentName = s;
|
|
|
|
|
|
log("intentName: " + intentName);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
} else {
|
|
|
intentName = input;
|
|
|
intentName = input;
|
|
|
|
|
|
log("intentName: " + intentName);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
switch (intentName.toLowerCase()) {
|
|
|
switch (intentName.toLowerCase()) {
|
|
|
//intent
|
|
|
//intent
|
|
|
case "lookaroundintent":
|
|
|
case "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) {
|
|
|
if (itemName != null) {
|
|
|
inspect(itemName);
|
|
|
inspect(itemName);
|
|
|
} else if (puzzleName != null) {
|
|
|
} else if (puzzleName != null) {
|
|
|
inspect(puzzleName);
|
|
|
inspect(puzzleName);
|
|
|
} else {
|
|
|
|
|
|
say("Das kann nicht untersucht werden");
|
|
|
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
//intent
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
//intent
|
|
|
|
|
|
|
|
|
case "examineintent":
|
|
|
case "examineintent":
|
|
|
|
|
|
log("Switch: ExamineIntent");
|
|
|
if (itemName == null && puzzleName == null) {
|
|
|
if (itemName == null && puzzleName == null) {
|
|
|
examine();
|
|
|
examine();
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
break;
|
|
|
|
|
|
|
|
|
//intent
|
|
|
//intent
|
|
|
case "takeintent":
|
|
|
case "takeintent":
|
|
|
|
|
|
log("Switch: TakeIntent");
|
|
|
if (itemName != null) {
|
|
|
if (itemName != null) {
|
|
|
take(currentRoom.getItem(itemName));
|
|
|
take(currentRoom.getItem(itemName));
|
|
|
} else {
|
|
|
|
|
|
say("das kann nicht mitgenommen werden");
|
|
|
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
break;
|
|
|
//intent
|
|
|
//intent
|
|
|
case "openintent":
|
|
|
case "openintent":
|
|
|
|
|
|
log("Switch: OpenIntent");
|
|
|
if (puzzleName != null) {
|
|
|
if (puzzleName != null) {
|
|
|
open(currentRoom.getPuzzle(puzzleName));
|
|
|
open(currentRoom.getPuzzle(puzzleName));
|
|
|
} else {
|
|
|
|
|
|
say("das kann nicht geöffnet werden");
|
|
|
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
break;
|
|
|
//intent
|
|
|
//intent
|
|
|
case "resetintent":
|
|
|
case "resetintent":
|
|
|
{
|
|
|
|
|
|
|
|
|
log("Switch: ResetIntent");
|
|
|
if (itemName == null && puzzleName == null) {
|
|
|
if (itemName == null && puzzleName == null) {
|
|
|
say("Das Spiel wird nun neu gestartet");
|
|
|
|
|
|
resetGame();
|
|
|
resetGame();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
//intent
|
|
|
//intent
|
|
|
case "skipintent":
|
|
|
case "skipintent":
|
|
|
{
|
|
|
|
|
|
|
|
|
log("Switch: SkipIntent");
|
|
|
if (itemName == null && puzzleName == null) {
|
|
|
if (itemName == null && puzzleName == null) {
|
|
|
resetGame();
|
|
|
resetGame();
|
|
|
for(int i = 0; i < currentRoom.puzzles.size(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(currentRoom.puzzles.get(i).getNextRoom() != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
for (int i = 0; i < currentRoom.puzzles.size(); i++) {
|
|
|
|
|
|
if (currentRoom.puzzles.get(i).getNextRoom() != null) {
|
|
|
setRoom(currentRoom.puzzles.get(i).getNextRoom());
|
|
|
setRoom(currentRoom.puzzles.get(i).getNextRoom());
|
|
|
say(currentRoom.puzzles.get(i).getNextRoom().getDescription());
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
itemName = null;
|
|
|
itemName = null;
|
|
|
intentName = null;
|
|
|
intentName = null;
|
|
|
puzzleName = null;
|
|
|
puzzleName = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log("stoppFlag: " + stoppFlag);
|
|
|
|
|
|
|
|
|
if (stoppFlag == true) {
|
|
|
if (stoppFlag == true) {
|
|
|
endGame();
|
|
|
endGame();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
//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 = "log=" + s;
|
|
|
|
|
|
wr.writeBytes(urlParameters);
|
|
|
|
|
|
wr.flush();
|
|
|
|
|
|
wr.close();
|
|
|
|
|
|
|
|
|
|
|
|
BufferedReader in = new BufferedReader(
|
|
|
|
|
|
new InputStreamReader(httpConn.getInputStream()));
|
|
|
|
|
|
String inputLine;
|
|
|
|
|
|
StringBuffer response = new StringBuffer();
|
|
|
|
|
|
|
|
|
|
|
|
while ((inputLine = in.readLine()) != null) {
|
|
|
|
|
|
response.append(inputLine);
|
|
|
|
|
|
}
|
|
|
|
|
|
in.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
public void lookaround() {
|
|
|
|
|
|
|
|
|
public void lookaround() throws Exception {
|
|
|
|
|
|
log("lookaround() ");
|
|
|
say(currentRoom.getDescription());
|
|
|
say(currentRoom.getDescription());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public void startGame() {
|
|
|
|
|
|
|
|
|
public void startGame() throws Exception {
|
|
|
|
|
|
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(){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void resetGame() throws Exception {
|
|
|
|
|
|
log("resetGame() ");
|
|
|
startGame();
|
|
|
startGame();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
|
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());
|
|
|
say(currentItem.getDescription());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Puzzle currentPuzzle=null;
|
|
|
|
|
|
|
|
|
|
|
|
if(currentRoom.getPuzzle(s) != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
currentPuzzle = currentRoom.getPuzzle(s);
|
|
|
|
|
|
log("currentPuzzle " + currentPuzzle.getName());
|
|
|
|
|
|
say(currentPuzzle.getDescription());
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public void endGame() {
|
|
|
|
|
|
|
|
|
public void endGame() throws Exception {
|
|
|
|
|
|
log("endGame() ");
|
|
|
say("Glückwunsch das Spiel ist beendet!");
|
|
|
say("Glückwunsch das Spiel ist beendet!");
|
|
|
setVariables();
|
|
|
setVariables();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
in.close();
|
|
|
in.close();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public void say(String s) {
|
|
|
|
|
|
|
|
|
public void say(String s) throws Exception {
|
|
|
|
|
|
log("say(" + s + ") ");
|
|
|
try {
|
|
|
try {
|
|
|
sendPost(s);
|
|
|
sendPost(s);
|
|
|
} catch (Exception ex) {
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public void setInput(String s) {
|
|
|
|
|
|
|
|
|
public void setInput(String s) throws Exception {
|
|
|
|
|
|
log("setInput(" + s + ") ");
|
|
|
input = s;
|
|
|
input = s;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public void setRoom(Room nextRoom) {
|
|
|
|
|
|
|
|
|
public void setRoom(Room nextRoom) throws Exception {
|
|
|
|
|
|
log("setRoom(" + nextRoom.getName() + ") " );
|
|
|
currentRoom = nextRoom;
|
|
|
currentRoom = nextRoom;
|
|
|
say(currentRoom.getDescription());
|
|
|
say(currentRoom.getDescription());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public void examine() {
|
|
|
|
|
|
|
|
|
public void examine() throws Exception {
|
|
|
|
|
|
log("examine() : " + getInventory());
|
|
|
|
|
|
|
|
|
if (getInventory().isEmpty()) {
|
|
|
if (getInventory().isEmpty()) {
|
|
|
say("Deine Taschen sind leer");
|
|
|
say("Deine Taschen sind leer");
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
inventory.forEach((bag) -> {
|
|
|
inventory.forEach((bag) -> {
|
|
|
say(bag.getName());
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
say(bag.getName());
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
Logger.getLogger(Game.class.getName()).log(Level.SEVERE, null, ex);
|
|
|
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public void open(Puzzle currentPuzzle) {
|
|
|
|
|
|
|
|
|
public void open(Puzzle currentPuzzle) throws Exception {
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public void take(Item currentItem) {
|
|
|
|
|
|
|
|
|
public void take(Item currentItem) throws Exception {
|
|
|
|
|
|
log("take(" + currentItem.getName() + ") ");
|
|
|
if ((!inventory.contains(currentItem)) && (currentItem.isPortableFlag() == true)) {
|
|
|
if ((!inventory.contains(currentItem)) && (currentItem.isPortableFlag() == true)) {
|
|
|
inventory.add(currentItem);
|
|
|
inventory.add(currentItem);
|
|
|
currentRoom.items.remove(currentItem);
|
|
|
currentRoom.items.remove(currentItem);
|