Merge origin/master
This commit is contained in:
commit
d4db36c418
@ -28,7 +28,7 @@ public class Game {
|
||||
Puzzle schloss;
|
||||
Puzzle door;
|
||||
Item schluessel;
|
||||
Item tonne;
|
||||
Item stahlschluessel;
|
||||
|
||||
public Game() {
|
||||
try {
|
||||
@ -80,11 +80,11 @@ public class Game {
|
||||
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);
|
||||
stahlschluessel = new Item("Stahlschluessel");
|
||||
stahlschluessel.setHiddenFlag(false);
|
||||
stahlschluessel.setPortableFlag(false);
|
||||
stahlschluessel.setDescription("Ein Stahlschlüssel");
|
||||
intro.items.add(stahlschluessel);
|
||||
|
||||
rooms.add(intro);
|
||||
rooms.add(keller);
|
||||
@ -102,124 +102,178 @@ public class Game {
|
||||
|
||||
}
|
||||
|
||||
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(" ")) {
|
||||
inputArray = input.split(" ");
|
||||
|
||||
for (String s : inputArray) {
|
||||
if (currentRoom.getItem(s) != null) {
|
||||
itemName = s;
|
||||
itemName = currentRoom.getItem(s).getName();
|
||||
log("itemName: " + itemName);
|
||||
} else if (currentRoom.getPuzzle(s) != null) {
|
||||
puzzleName = s;
|
||||
puzzleName = currentRoom.getPuzzle(s).getName();
|
||||
log("PuzzleName: " + puzzleName);
|
||||
} else {
|
||||
intentName = s;
|
||||
log("intentName: " + intentName);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
intentName = input;
|
||||
log("intentName: " + intentName);
|
||||
}
|
||||
|
||||
switch (intentName.toLowerCase()) {
|
||||
//intent
|
||||
case "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);
|
||||
} else {
|
||||
say("Das kann nicht untersucht werden");
|
||||
}
|
||||
break;
|
||||
//intent
|
||||
break;
|
||||
//intent
|
||||
|
||||
case "examineintent":
|
||||
log("Switch: ExamineIntent");
|
||||
if (itemName == null && puzzleName == null) {
|
||||
examine();
|
||||
}
|
||||
break;
|
||||
|
||||
//intent
|
||||
case "takeintent":
|
||||
log("Switch: TakeIntent");
|
||||
if (itemName != null) {
|
||||
take(currentRoom.getItem(itemName));
|
||||
} else {
|
||||
say("das kann nicht mitgenommen werden");
|
||||
}
|
||||
break;
|
||||
//intent
|
||||
case "openintent":
|
||||
log("Switch: OpenIntent");
|
||||
if (puzzleName != null) {
|
||||
open(currentRoom.getPuzzle(puzzleName));
|
||||
} else {
|
||||
say("das kann nicht geöffnet werden");
|
||||
}
|
||||
break;
|
||||
//intent
|
||||
case "resetintent":
|
||||
{
|
||||
log("Switch: ResetIntent");
|
||||
if (itemName == null && puzzleName == null) {
|
||||
say("Das Spiel wird nun neu gestartet");
|
||||
resetGame();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
//intent
|
||||
case "skipintent":
|
||||
{
|
||||
log("Switch: SkipIntent");
|
||||
if (itemName == null && puzzleName == null) {
|
||||
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());
|
||||
say(currentRoom.puzzles.get(i).getNextRoom().getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
itemName = null;
|
||||
intentName = null;
|
||||
puzzleName = null;
|
||||
|
||||
log("stoppFlag: " + stoppFlag);
|
||||
|
||||
if (stoppFlag == true) {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
|
||||
public void lookaround() {
|
||||
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() throws Exception {
|
||||
log("lookaround() ");
|
||||
say(currentRoom.getDescription());
|
||||
}
|
||||
|
||||
public void startGame() {
|
||||
public void startGame() throws Exception {
|
||||
log("startGame() ");
|
||||
for (int i = 0; i < story.size(); i++) {
|
||||
say(story.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void resetGame(){
|
||||
|
||||
public void resetGame() throws Exception {
|
||||
log("resetGame() ");
|
||||
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());
|
||||
}
|
||||
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!");
|
||||
setVariables();
|
||||
}
|
||||
@ -254,7 +308,8 @@ public class Game {
|
||||
in.close();
|
||||
}
|
||||
|
||||
public void say(String s) {
|
||||
public void say(String s) throws Exception {
|
||||
log("say(" + s + ") ");
|
||||
try {
|
||||
sendPost(s);
|
||||
} catch (Exception ex) {
|
||||
@ -262,16 +317,19 @@ public class Game {
|
||||
}
|
||||
}
|
||||
|
||||
public void setInput(String s) {
|
||||
public void setInput(String s) throws Exception {
|
||||
log("setInput(" + s + ") ");
|
||||
input = s;
|
||||
}
|
||||
|
||||
public void setRoom(Room nextRoom) {
|
||||
public void setRoom(Room nextRoom) throws Exception {
|
||||
log("setRoom(" + nextRoom.getName() + ") " );
|
||||
currentRoom = nextRoom;
|
||||
say(currentRoom.getDescription());
|
||||
}
|
||||
|
||||
public void examine() {
|
||||
public void examine() throws Exception {
|
||||
log("examine() : " + getInventory());
|
||||
|
||||
if (getInventory().isEmpty()) {
|
||||
say("Deine Taschen sind leer");
|
||||
@ -280,12 +338,17 @@ public class Game {
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
say("ist bereits geöffnet");
|
||||
@ -324,7 +387,8 @@ public class Game {
|
||||
|
||||
}
|
||||
|
||||
public void take(Item currentItem) {
|
||||
public void take(Item currentItem) throws Exception {
|
||||
log("take(" + currentItem.getName() + ") ");
|
||||
if ((!inventory.contains(currentItem)) && (currentItem.isPortableFlag() == true)) {
|
||||
inventory.add(currentItem);
|
||||
currentRoom.items.remove(currentItem);
|
||||
|
102
src/java/Log.java
Normal file
102
src/java/Log.java
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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 = {"/Log"})
|
||||
public class Log 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
|
||||
*/
|
||||
String context = "";
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException, Exception {
|
||||
|
||||
try (PrintWriter out = response.getWriter()) {
|
||||
/* TODO output your page here. You may use following sample code. */
|
||||
if(request.getParameter("log") != null) {
|
||||
context = context + "\n" + request.getParameter("log");
|
||||
}
|
||||
|
||||
out.println(context);
|
||||
}
|
||||
}
|
||||
|
||||
// <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", 2);
|
||||
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", 2);
|
||||
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>
|
||||
|
||||
}
|
@ -17,7 +17,7 @@ public class Room
|
||||
{
|
||||
for(Item i: items)
|
||||
{
|
||||
if(i.getName().equals(s))
|
||||
if(i.getName().equalsIgnoreCase(s))
|
||||
return i;
|
||||
}
|
||||
return null;
|
||||
@ -27,7 +27,7 @@ public class Room
|
||||
{
|
||||
for(Puzzle p: puzzles)
|
||||
{
|
||||
if(p.getName().equals(s))
|
||||
if(p.getName().equalsIgnoreCase(s))
|
||||
return p;
|
||||
}
|
||||
return null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user