/* * 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.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import static java.nio.charset.StandardCharsets.UTF_8; import java.util.ArrayList; import java.util.Arrays; 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 = {"/IO"}) public class Logic extends HttpServlet { private ArrayList games = new ArrayList<>(); /** * Processes requests for both HTTP GET and POST * 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 = ""; String input = null; @Override public void init() { try { resetJSON(); } catch (FileNotFoundException ex) { Logger.getLogger(Logic.class.getName()).log(Level.SEVERE, null, ex); } } public void writeJSON(String s) throws Exception { PrintWriter writer = new PrintWriter("game.JSON", "UTF-8"); if (s != null) { writer.println(s); } writer.close(); } public void resetJSON() throws FileNotFoundException { File f = new File("game.JSON"); if (f.exists()) { f.delete(); } try { writeJSON("{" + "\"room\": [{" + "\"id\": 0," + "\"name\": \"Keller\"," + "\"description\": \"Ein alter modriger Keller. Es schimmelt überall und stinkt bestialisch. Vor dir liegt eine Leiche, im Raum steht ein Stuhl und ein Tisch. Am anderen Ende des Raumes ist ein Duschvorhang an der Wand aufgespannt.\"," + "\"items\": [" + "5," + "7," + "4," + "0," + "2," + "6," + "10" + "]," + "\"puzzles\": [" + "9," + "4," + "0" + "]," + "\"gameoverFlag\": false" + "}," + "{" + "\"id\": 5," + "\"name\": \"Flur\"," + "\"description\": \"