From 1d6f217717fe8d67352197c4e0f5a496d8c914b4 Mon Sep 17 00:00:00 2001 From: kmitresse Date: Sat, 27 Apr 2024 11:10:06 +0200 Subject: [PATCH] feat: devWeb - game statistics is ok --- .../project/web/servlet/GameStatistics.java | 32 +++++++ .../webapp/WEB-INF/pages/game-statistics.jsp | 18 ++++ .../tags/components/game-statistics.tag | 89 +++++++++++++++++++ .../WEB-INF/tags/components/statistics.tag | 12 +-- .../Projet/src/main/webapp/WEB-INF/web.xml | 1 + 5 files changed, 142 insertions(+), 10 deletions(-) create mode 100644 S2/DevWeb/Projet/src/main/java/uppa/project/web/servlet/GameStatistics.java create mode 100644 S2/DevWeb/Projet/src/main/webapp/WEB-INF/pages/game-statistics.jsp create mode 100644 S2/DevWeb/Projet/src/main/webapp/WEB-INF/tags/components/game-statistics.tag diff --git a/S2/DevWeb/Projet/src/main/java/uppa/project/web/servlet/GameStatistics.java b/S2/DevWeb/Projet/src/main/java/uppa/project/web/servlet/GameStatistics.java new file mode 100644 index 0000000..43185b9 --- /dev/null +++ b/S2/DevWeb/Projet/src/main/java/uppa/project/web/servlet/GameStatistics.java @@ -0,0 +1,32 @@ +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.jpa.Game_JPA_DAO_Factory; +import uppa.project.database.pojo.Game; + +@WebServlet(name = "game-statistics", value = "/game-statistics") +public class GameStatistics extends HttpServlet { + + public void init() { + } + + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + Game game; + try { + DAO gameDAO = new Game_JPA_DAO_Factory().getDAOGame(); + game = gameDAO.findById(Integer.parseInt(request.getParameter("id"))); + request.removeAttribute("id"); + game.sortPlayersByScore(); + request.setAttribute("game", game); + request.getRequestDispatcher("/WEB-INF/pages/game-statistics.jsp").forward(request, response); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/S2/DevWeb/Projet/src/main/webapp/WEB-INF/pages/game-statistics.jsp b/S2/DevWeb/Projet/src/main/webapp/WEB-INF/pages/game-statistics.jsp new file mode 100644 index 0000000..8b7e2b4 --- /dev/null +++ b/S2/DevWeb/Projet/src/main/webapp/WEB-INF/pages/game-statistics.jsp @@ -0,0 +1,18 @@ +<%@ page import="java.util.List" %> +<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> + +<%@taglib prefix="layout" tagdir="/WEB-INF/tags/layouts" %> +<%@taglib prefix="component" tagdir="/WEB-INF/tags/components" %> +<%@taglib prefix="form" tagdir="/WEB-INF/tags/forms" %> + + + +
+
+ + + +
+
+
+
diff --git a/S2/DevWeb/Projet/src/main/webapp/WEB-INF/tags/components/game-statistics.tag b/S2/DevWeb/Projet/src/main/webapp/WEB-INF/tags/components/game-statistics.tag new file mode 100644 index 0000000..25d5b7d --- /dev/null +++ b/S2/DevWeb/Projet/src/main/webapp/WEB-INF/tags/components/game-statistics.tag @@ -0,0 +1,89 @@ +<%@ tag import="uppa.project.database.pojo.Player" %> +<%@ tag import="java.util.Calendar" %> +<%@ tag import="uppa.project.database.pojo.Game" %> +<%@tag description="component/statistics" pageEncoding="UTF-8" %> + +

Information sur la partie

+
+
+
+ <% String date = game.getCreatedAt().toLocaleString(); + System.out.println(date); + String day = date.substring(0,8) + date.substring(10,12); + String hour = date.substring(14,16) + "h" + date.substring(17,19); + %> +

Date de jeu

+

<%= day %>

+

<%= hour %>

+
+
+
+
+

Difficulté

+ <% if (game.getDifficulty().equals(Game.Difficulty.EASY)){%> +

Facile

+ <% } else {%> +

Difficile

+ <% } %> +
+
+
+
+

Nombre de rounds

+

${game.nbRounds}

+
+
+
+
+

Nombre de couleurs

+

${game.nbColors}

+
+
+
+
+

Nombre de valeurs

+

${game.nbValuesPerColor}

+
+
+
+
+

Nombre de joueurs

+

${game.nbPlayers}

+
+
+
+ +

Joueurs

+ + + + + + + + + + + + + <% for (Player player : game.getPlayers()) { %> + + + + + + + + <% } %> + +
Nom d'utilisateurScoreClics correctsClics rapidesVictoire
<%= player.getUser().getUsername() %><%= player.getScore() %><%= player.getRightClickCount() %> (<%= player.getRatioRightClick() %>%)<%= player.getRapidClickCount() %> (<%= player.getRatioRapidClick()%>%)<% if (player.getUser().getUsername().equals(game.getWinner())){ %> <% } %>
+ + + diff --git a/S2/DevWeb/Projet/src/main/webapp/WEB-INF/tags/components/statistics.tag b/S2/DevWeb/Projet/src/main/webapp/WEB-INF/tags/components/statistics.tag index ce309ec..e7925ca 100644 --- a/S2/DevWeb/Projet/src/main/webapp/WEB-INF/tags/components/statistics.tag +++ b/S2/DevWeb/Projet/src/main/webapp/WEB-INF/tags/components/statistics.tag @@ -41,8 +41,7 @@ - - + <% for (int i = 0; i < user.getPlayedGames().size(); i++) { Player player = user.getPlayedGames().get(i); %> @@ -50,15 +49,8 @@ <%= player.getGame().getCreatedAt().toLocaleString() %> <%= player.getScore() %> <%= player.getGame().getWinner() %> - Voir + Voir <% } %> -<%-- --%> -<%-- --%> -<%-- ${player.game.createdAt}--%> -<%-- ${player.score}--%> -<%-- ${player.game.winner}--%> -<%-- Voir--%> -<%-- --%> diff --git a/S2/DevWeb/Projet/src/main/webapp/WEB-INF/web.xml b/S2/DevWeb/Projet/src/main/webapp/WEB-INF/web.xml index 485444b..f882e18 100644 --- a/S2/DevWeb/Projet/src/main/webapp/WEB-INF/web.xml +++ b/S2/DevWeb/Projet/src/main/webapp/WEB-INF/web.xml @@ -18,6 +18,7 @@ /lobby /profile + /game-statistics /new /join /game