mirror of
https://github.com/kmitresse/Cards-Rush.git
synced 2026-05-13 17:11:49 +00:00
feat: devWeb - game statistics is ok
This commit is contained in:
@@ -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<Game> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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" %>
|
||||
|
||||
<layout:base title="Profil">
|
||||
<component:hero>
|
||||
<div class="columns is-centered">
|
||||
<div class="column is-9-tablet is-9-desktop is-9-widescreen">
|
||||
<component:card title="Statistiques de la partie">
|
||||
<component:game-statistics/>
|
||||
</component:card>
|
||||
</div>
|
||||
</div>
|
||||
</component:hero>
|
||||
</layout:base>
|
||||
@@ -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" %>
|
||||
<jsp:useBean id="game" class="uppa.project.database.pojo.Game" scope="request"/>
|
||||
<h4 class="title is-6">Information sur la partie</h4>
|
||||
<div class="level">
|
||||
<div class="level-item has-text-centered has-text-on-top">
|
||||
<div>
|
||||
<% 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);
|
||||
%>
|
||||
<p class="heading">Date de jeu</p>
|
||||
<p class="title"><%= day %></p>
|
||||
<p class="title"><%= hour %></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="level-item has-text-centered">
|
||||
<div>
|
||||
<p class="heading">Difficulté</p>
|
||||
<% if (game.getDifficulty().equals(Game.Difficulty.EASY)){%>
|
||||
<p class="title">Facile</p>
|
||||
<% } else {%>
|
||||
<p class="title">Difficile</p>
|
||||
<% } %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="level-item has-text-centered">
|
||||
<div>
|
||||
<p class="heading">Nombre de rounds</p>
|
||||
<p class="title">${game.nbRounds}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="level-item has-text-centered">
|
||||
<div>
|
||||
<p class="heading">Nombre de couleurs</p>
|
||||
<p class="title">${game.nbColors}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="level-item has-text-centered">
|
||||
<div>
|
||||
<p class="heading">Nombre de valeurs</p>
|
||||
<p class="title">${game.nbValuesPerColor}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="level-item has-text-centered">
|
||||
<div>
|
||||
<p class="heading">Nombre de joueurs</p>
|
||||
<p class="title">${game.nbPlayers}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h4 class="title is-4">Joueurs </h4>
|
||||
<table class="table is-fullwidth">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nom d'utilisateur</th>
|
||||
<th>Score</th>
|
||||
<th>Clics corrects</th>
|
||||
<th>Clics rapides</th>
|
||||
<th>Victoire</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="game-list">
|
||||
|
||||
<% for (Player player : game.getPlayers()) { %>
|
||||
<tr>
|
||||
<td><%= player.getUser().getUsername() %></td>
|
||||
<td><%= player.getScore() %></td>
|
||||
<td><%= player.getRightClickCount() %> (<%= player.getRatioRightClick() %>%)</td>
|
||||
<td><%= player.getRapidClickCount() %> (<%= player.getRatioRapidClick()%>%)</td>
|
||||
<td><% if (player.getUser().getUsername().equals(game.getWinner())){ %> <i class="fa-solid fa-crown" style="color: #FFD43B;"></i> <% } %></td>
|
||||
</tr>
|
||||
<% } %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
<div class="navbar-item">
|
||||
<a href="${pageContext.request.contextPath}/profile" class="button is-light is-right">
|
||||
<span class="icon">
|
||||
<i class="fa-solid fa-arrow-left"></i>
|
||||
</span>
|
||||
<span>Retour</span>
|
||||
</a>
|
||||
</div>
|
||||
@@ -41,8 +41,7 @@
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="game-list">
|
||||
|
||||
<tbody>
|
||||
<% for (int i = 0; i < user.getPlayedGames().size(); i++) {
|
||||
Player player = user.getPlayedGames().get(i);
|
||||
%>
|
||||
@@ -50,15 +49,8 @@
|
||||
<td><%= player.getGame().getCreatedAt().toLocaleString() %></td>
|
||||
<td><%= player.getScore() %></td>
|
||||
<td><%= player.getGame().getWinner() %></td>
|
||||
<td><a href="/game/<%= player.getGame().getId() %>">Voir</a></td>
|
||||
<td><a href="${pageContext.request.contextPath}/game-statistics?id=<%= player.getGame().getId() %>">Voir</a></td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<%-- <c:forEach var="player" items="${user.playedGames}">--%>
|
||||
<%-- <tr>--%>
|
||||
<%-- <td>${player.game.createdAt}</td>--%>
|
||||
<%-- <td>${player.score}</td>--%>
|
||||
<%-- <td>${player.game.winner}</td>--%>
|
||||
<%-- <td><a href="/game/${player.game.id}">Voir</a></td>--%>
|
||||
<%-- </tr>--%>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<!-- <url-pattern>/main-menu</url-pattern>-->
|
||||
<url-pattern>/lobby</url-pattern>
|
||||
<url-pattern>/profile</url-pattern>
|
||||
<url-pattern>/game-statistics</url-pattern>
|
||||
<url-pattern>/new</url-pattern>
|
||||
<url-pattern>/join</url-pattern>
|
||||
<url-pattern>/game</url-pattern>
|
||||
|
||||
Reference in New Issue
Block a user