You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Logic.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. import java.io.IOException;
  7. import java.io.PrintWriter;
  8. import java.util.ArrayList;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11. import javax.servlet.ServletException;
  12. import javax.servlet.annotation.WebServlet;
  13. import javax.servlet.http.HttpServlet;
  14. import javax.servlet.http.HttpServletRequest;
  15. import javax.servlet.http.HttpServletResponse;
  16. /**
  17. *
  18. * @author Edi
  19. */
  20. @WebServlet(urlPatterns = {"/IO"})
  21. public class Logic extends HttpServlet {
  22. private ArrayList<Game> games = new ArrayList<Game>();
  23. /**
  24. * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
  25. * methods.
  26. *
  27. * @param request servlet request
  28. * @param response servlet response
  29. * @throws ServletException if a servlet-specific error occurs
  30. * @throws IOException if an I/O error occurs
  31. */
  32. Game g = new Game();
  33. String context = "";
  34. public void init() {
  35. try {
  36. g.setVariables();
  37. } catch (Exception ex) {
  38. Logger.getLogger(Logic.class.getName()).log(Level.SEVERE, null, ex);
  39. }
  40. }
  41. protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  42. throws ServletException, IOException, Exception {
  43. try (PrintWriter out = response.getWriter()) {
  44. /* TODO output your page here. You may use following sample code. */
  45. if(request.getParameter("alexaText") != null) {
  46. context = request.getParameter("alexaText");
  47. }
  48. out.println(context);
  49. //String deviceId = request.getParameter("deviceId"); // einzigartige DeviceID des Alexa Geräts
  50. String input = request.getParameter("intent");
  51. if (request.getParameter("slot") != null) {
  52. input = input + " " + request.getParameter("slot");
  53. }
  54. if(input != null)
  55. {
  56. g.setInput(input);
  57. g.play();
  58. }
  59. /* Mehrere Spieler auf einem Server
  60. for(int i = 0; i < games.size(); i++)
  61. {
  62. if(games.get(i).getId().equals(deviceId))
  63. {
  64. games.get(i).setInput(input);
  65. games.get(i).play();
  66. }
  67. }
  68. */
  69. }
  70. }
  71. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  72. /**
  73. * Handles the HTTP <code>GET</code> method.
  74. *
  75. * @param request servlet request
  76. * @param response servlet response
  77. * @throws ServletException if a servlet-specific error occurs
  78. * @throws IOException if an I/O error occurs
  79. */
  80. @Override
  81. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  82. throws ServletException, IOException {
  83. response.setIntHeader("Refresh", 2);
  84. try {
  85. processRequest(request, response);
  86. } catch (Exception ex) {
  87. Logger.getLogger(Logic.class.getName()).log(Level.SEVERE, null, ex);
  88. }
  89. }
  90. /**
  91. * Handles the HTTP <code>POST</code> method.
  92. *
  93. * @param request servlet request
  94. * @param response servlet response
  95. * @throws ServletException if a servlet-specific error occurs
  96. * @throws IOException if an I/O error occurs
  97. */
  98. @Override
  99. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  100. throws ServletException, IOException {
  101. response.setIntHeader("Refresh", 2);
  102. try {
  103. processRequest(request, response);
  104. } catch (Exception ex) {
  105. Logger.getLogger(Logic.class.getName()).log(Level.SEVERE, null, ex);
  106. }
  107. }
  108. /**
  109. * Returns a short description of the servlet.
  110. *
  111. * @return a String containing servlet description
  112. */
  113. @Override
  114. public String getServletInfo() {
  115. return "Short description";
  116. }// </editor-fold>
  117. }