From 548effdfbe8addab9daadce632f50727986ea1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luc=C3=A0s?= Date: Tue, 23 Apr 2024 15:01:16 +0200 Subject: [PATCH] draft(DevWeb): Start game page --- .../java/uppa/project/database/pojo/Game.java | 4 +- .../uppa/project/web/servlet/GameServlet.java | 41 +++++++++++ .../src/main/webapp/WEB-INF/pages/game.jsp | 71 +++++++++++++++++++ 3 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 S2/DevWeb/Projet/src/main/java/uppa/project/web/servlet/GameServlet.java create mode 100644 S2/DevWeb/Projet/src/main/webapp/WEB-INF/pages/game.jsp diff --git a/S2/DevWeb/Projet/src/main/java/uppa/project/database/pojo/Game.java b/S2/DevWeb/Projet/src/main/java/uppa/project/database/pojo/Game.java index fa3e15c..44bca4d 100644 --- a/S2/DevWeb/Projet/src/main/java/uppa/project/database/pojo/Game.java +++ b/S2/DevWeb/Projet/src/main/java/uppa/project/database/pojo/Game.java @@ -82,6 +82,8 @@ public class Game implements Serializable { * Constructeur par défaut */ public Game() { + this.createdAt = new Date(); + this.players = new ArrayList<>(); } /** @@ -89,7 +91,7 @@ public class Game implements Serializable { * * @param difficulty la difficulté de la partie * @see Difficulty - * @param timer le timer de chaque rounds en seconde + * @param timer le timer de chaque round en seconde * @param nbRounds le nombre de tours de la partie * @param nbColors le nombre de couleurs présente dans le deck * @param nbValuesPerColor le nombre de valeurs par couleur diff --git a/S2/DevWeb/Projet/src/main/java/uppa/project/web/servlet/GameServlet.java b/S2/DevWeb/Projet/src/main/java/uppa/project/web/servlet/GameServlet.java new file mode 100644 index 0000000..f587bd1 --- /dev/null +++ b/S2/DevWeb/Projet/src/main/java/uppa/project/web/servlet/GameServlet.java @@ -0,0 +1,41 @@ +/* + * MainMenuServlet.java, 20/03/2024 + * UPPA M1 TI 2023-2024 + * Pas de copyright, aucun droits + */ + +package uppa.project.web.servlet; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; +import uppa.project.database.dao.DAO; +import uppa.project.database.dao.DAOException; +import uppa.project.database.dao.jpa.DAO_JPA_Game; +import uppa.project.database.dao.jpa.Game_JPA_DAO_Factory; +import uppa.project.database.pojo.Game; + +@WebServlet(name = "gameServlet", value = "/game") +public class GameServlet extends HttpServlet { + + public void init() { + } + + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + try { + DAO gameDAO = new Game_JPA_DAO_Factory().getDAOGame(); + Game game = gameDAO.findById(Integer.parseInt(request.getParameter("id"))); + request.setAttribute("game", game); + + request.getRequestDispatcher("/WEB-INF/pages/game.jsp").forward(request, response); + } catch (DAOException e) { + throw new RuntimeException(e); + } + } + + public void destroy() { + } +} diff --git a/S2/DevWeb/Projet/src/main/webapp/WEB-INF/pages/game.jsp b/S2/DevWeb/Projet/src/main/webapp/WEB-INF/pages/game.jsp new file mode 100644 index 0000000..5ae0a77 --- /dev/null +++ b/S2/DevWeb/Projet/src/main/webapp/WEB-INF/pages/game.jsp @@ -0,0 +1,71 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@taglib prefix="layout" tagdir="/WEB-INF/tags/layouts" %> +<%@taglib prefix="component" tagdir="/WEB-INF/tags/components" %> + + + +
+
+ + + Ajouter + + +
+
+ + + +

Créé le: ${game.createdAt.toLocaleString()}

+

Difficulté: ${game.difficulty}

+

Nombre de tours: ${game.nbRounds}

+

Valeurs par couleur: ${game.nbValuesPerColor}

+

Nombre de couleurs: ${game.nbColors}

+
+
+
+
+ + + + + + +
\ No newline at end of file