mirror of
https://github.com/kmitresse/Cards-Rush.git
synced 2026-05-13 17:11:49 +00:00
feat: dev-web - servlet part
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package uppa.project;
|
||||
|
||||
public class Global {
|
||||
public final class Global {
|
||||
|
||||
public static final String PERSISTENCE_UNIT_NAME = "prod";
|
||||
public static final String PERSISTENCE_UNIT_NAME_TEST = "test";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package uppa.project;
|
||||
|
||||
import java.util.Calendar;
|
||||
import uppa.project.dao.DAO;
|
||||
import uppa.project.dao.DAOException;
|
||||
import uppa.project.dao.jpa.Game_JPA_DAO_Factory;
|
||||
@@ -7,8 +8,8 @@ import uppa.project.pojo.User;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
public static void main(String[] args) throws DAOException {
|
||||
try {
|
||||
Game_JPA_DAO_Factory jpaDaoFactory = new Game_JPA_DAO_Factory();
|
||||
DAO<User> daoJpaUser = jpaDaoFactory.getDAOUser();
|
||||
// DAO<Game> daoJpaGame = jpaDaoFactory.getDAOGame();
|
||||
@@ -21,17 +22,17 @@ public class Main {
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
// // Ajout d'User :
|
||||
// Calendar cal1 = Calendar.getInstance();
|
||||
// cal1.set(1996, Calendar.FEBRUARY, 20);
|
||||
// User user1 = new User("Kevin", "Mitresse", cal1.getTime(), User.Gender.MALE);
|
||||
//
|
||||
// Calendar cal2 = Calendar.getInstance();
|
||||
// cal2.set(2002, Calendar.JUNE, 28);
|
||||
// User user2 = new User("Lucàs", "Vabre", cal2.getTime(), User.Gender.MALE);
|
||||
//
|
||||
// daoJpaUser.create(user1);
|
||||
// daoJpaUser.create(user2);
|
||||
// Ajout d'User :
|
||||
Calendar cal1 = Calendar.getInstance();
|
||||
cal1.set(1996, Calendar.FEBRUARY, 20);
|
||||
User user1 = new User("Kevin","kmitresse@gmail.com", "Mitresse", cal1.getTime(), User.Gender.MALE);
|
||||
|
||||
Calendar cal2 = Calendar.getInstance();
|
||||
cal2.set(2002, Calendar.JUNE, 28);
|
||||
User user2 = new User("Lucàs", "lucas@gmail.com" ,"Vabre", cal2.getTime(), User.Gender.MALE);
|
||||
|
||||
daoJpaUser.create(user1);
|
||||
daoJpaUser.create(user2);
|
||||
|
||||
// System.out.println("test récupération user");
|
||||
// User[] users2 = daoJpaUser.findByField("username", "Kevin");
|
||||
|
||||
@@ -8,9 +8,6 @@ package uppa.project.pojo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Représentation d'un paquet de cartes
|
||||
@@ -24,7 +21,7 @@ public class Deck {
|
||||
* Ensemble de cartes du paquet
|
||||
* @see Card
|
||||
*/
|
||||
private Set<Card> cards;
|
||||
private ArrayList<Card> cards;
|
||||
|
||||
/**
|
||||
* Constructeur par défaut
|
||||
@@ -38,9 +35,13 @@ public class Deck {
|
||||
cards = initializeDeck(nbColors, nbValues);
|
||||
}
|
||||
|
||||
public Set<Card> getCards() {
|
||||
/**
|
||||
* @return l'ensemble de cartes du paquet
|
||||
*/
|
||||
public ArrayList<Card> getCards() {
|
||||
return cards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Créé un paquet de cartes mélangé avec un nombre de couleurs et de valeurs donné
|
||||
*
|
||||
@@ -48,9 +49,10 @@ public class Deck {
|
||||
* @param nbValues nombre de valeurs (doit être compris entre 1 et le nombre de valeurs de {@link Card.Value})
|
||||
* @return un ensemble de cartes mélangées
|
||||
*/
|
||||
private static Set<Card> initializeDeck(int nbColors, int nbValues) {
|
||||
Set<Card> cards = createSetOfCard(nbColors, nbValues);
|
||||
return shuffleSetOfCard(cards);
|
||||
private static ArrayList<Card> initializeDeck(int nbColors, int nbValues) {
|
||||
ArrayList<Card> cards = createSetOfCard(nbColors, nbValues);
|
||||
shuffleSetOfCard(cards);
|
||||
return cards;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,8 +65,8 @@ public class Deck {
|
||||
* @throws IllegalArgumentException si le nombre de couleurs ou de valeurs est incorrect
|
||||
* @return un ensemble de cartes
|
||||
*/
|
||||
private static Set<Card> createSetOfCard(int nbColors, int nbValues) throws IllegalArgumentException {
|
||||
Set<Card> cards = new HashSet<>();
|
||||
private static ArrayList<Card> createSetOfCard(int nbColors, int nbValues) throws IllegalArgumentException {
|
||||
ArrayList<Card> cards = new ArrayList<>(nbColors*nbValues);
|
||||
|
||||
if (nbColors < 1 || nbColors > Card.Color.values().length) {
|
||||
throw new IllegalArgumentException("Le nombre de couleurs doit être compris entre 1 et " + Card.Color.values().length);
|
||||
@@ -87,10 +89,8 @@ public class Deck {
|
||||
* @param cards ensemble de cartes à mélanger
|
||||
* @return un ensemble de cartes mélangées
|
||||
*/
|
||||
private static HashSet<Card> shuffleSetOfCard(Set<Card> cards) {
|
||||
List<Card> cardList = new ArrayList<>(cards);
|
||||
Collections.shuffle(cardList);
|
||||
return new HashSet<>(cardList);
|
||||
private static void shuffleSetOfCard(ArrayList<Card> cards) {
|
||||
Collections.shuffle(cards);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ import jakarta.persistence.TemporalType;
|
||||
import jakarta.persistence.Transient;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Représentation d'une partie de jeu
|
||||
@@ -60,7 +60,7 @@ public class Game implements Serializable {
|
||||
private int nbValuesPerColor;
|
||||
|
||||
@OneToMany(mappedBy = "game", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
private Set<Player> players;
|
||||
private ArrayList<Player> players;
|
||||
|
||||
@Transient
|
||||
private Deck deck;
|
||||
@@ -98,7 +98,7 @@ public class Game implements Serializable {
|
||||
* @param nbValuesPerColor le nombre de valeurs par couleur
|
||||
* @param players les joueurs de la partie
|
||||
*/
|
||||
public Game(BigDecimal id, Date createdAt, Difficulty difficulty, int nbRounds, int nbColors, int nbValuesPerColor, Set<Player> players) {
|
||||
public Game(BigDecimal id, Date createdAt, Difficulty difficulty, int nbRounds, int nbColors, int nbValuesPerColor, ArrayList<Player> players) {
|
||||
this.id = id;
|
||||
this.createdAt = createdAt;
|
||||
this.difficulty = difficulty;
|
||||
@@ -187,7 +187,7 @@ public class Game implements Serializable {
|
||||
/**
|
||||
* @return les joueurs de la partie
|
||||
*/
|
||||
public Set<Player> getPlayers() {
|
||||
public ArrayList<Player> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ public class Game implements Serializable {
|
||||
*
|
||||
* @param players les nouveaux joueurs
|
||||
*/
|
||||
public void setPlayers(Set<Player> players) {
|
||||
public void setPlayers(ArrayList<Player> players) {
|
||||
this.players = players;
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ public class Game implements Serializable {
|
||||
this.players.add(player);
|
||||
}
|
||||
|
||||
public Set<Card> getDeck() {
|
||||
public ArrayList<Card> getDeck() {
|
||||
return deck.getCards();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ import jakarta.persistence.Table;
|
||||
import jakarta.persistence.Transient;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Représentation d'un joueur
|
||||
@@ -259,7 +259,7 @@ public class Player implements Serializable {
|
||||
return (double) rapidClickCount * 100 / clickCount;
|
||||
}
|
||||
|
||||
public Set<Card> getDeck() {
|
||||
public ArrayList<Card> getDeck() {
|
||||
return deck.getCards();
|
||||
}
|
||||
@Override
|
||||
|
||||
@@ -23,9 +23,9 @@ import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Représentation d'un utilisateur
|
||||
@@ -60,10 +60,10 @@ public class User implements Serializable {
|
||||
private Gender gender;
|
||||
|
||||
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
private Set<Player> playedGame;
|
||||
private ArrayList<Player> playedGames;
|
||||
|
||||
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
private Set<RecoveryPasswordToken> recoveryPasswordTokens;
|
||||
private ArrayList<RecoveryPasswordToken> recoveryPasswordTokens;
|
||||
|
||||
/**
|
||||
* Constructeur par défaut
|
||||
@@ -98,13 +98,14 @@ public class User implements Serializable {
|
||||
* @param birth la date de naissance
|
||||
* @param gender le genre
|
||||
*/
|
||||
public User(BigDecimal id, String username, String email, String password, Date birth, Gender gender) {
|
||||
public User(BigDecimal id, String username, String email, String password, Date birth, Gender gender, ArrayList<Player> playedGames) {
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
this.birth = birth;
|
||||
this.gender = gender;
|
||||
this.playedGames = playedGames;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,13 +246,22 @@ public class User implements Serializable {
|
||||
return hashedPassword != null && hashedPassword.equals(this.password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère la liste des parties jouées par l'utilisateur
|
||||
*
|
||||
* @return la liste des parties jouées
|
||||
*/
|
||||
public ArrayList<Player> getPlayedGames() {
|
||||
return playedGames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le nombre de parties jouées
|
||||
*
|
||||
* @return le nombre de parties jouées
|
||||
*/
|
||||
public int getNbPlayedGame() {
|
||||
return playedGame.size();
|
||||
return playedGames.size();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,7 +271,7 @@ public class User implements Serializable {
|
||||
*/
|
||||
public int getNbWin(){
|
||||
int nbWin = 0;
|
||||
for (Player p : playedGame) {
|
||||
for (Player p : playedGames) {
|
||||
if (p.isWinner()) nbWin++;
|
||||
}
|
||||
return nbWin;
|
||||
@@ -283,7 +293,7 @@ public class User implements Serializable {
|
||||
*/
|
||||
public int getNbClicks(){
|
||||
int nbClicks = 0;
|
||||
for (Player p : playedGame) {
|
||||
for (Player p : playedGames) {
|
||||
nbClicks += p.getClickCount();
|
||||
}
|
||||
return nbClicks;
|
||||
@@ -296,7 +306,7 @@ public class User implements Serializable {
|
||||
*/
|
||||
public int getNbRightClicks(){
|
||||
int nbRightClicks = 0;
|
||||
for (Player p : playedGame) {
|
||||
for (Player p : playedGames) {
|
||||
nbRightClicks += p.getRightClickCount();
|
||||
}
|
||||
return nbRightClicks;
|
||||
@@ -318,7 +328,7 @@ public class User implements Serializable {
|
||||
*/
|
||||
public int getNbRapidClicks(){
|
||||
int nbRapidClicks = 0;
|
||||
for (Player p : playedGame) {
|
||||
for (Player p : playedGames) {
|
||||
nbRapidClicks += p.getRapidClickCount();
|
||||
}
|
||||
return nbRapidClicks;
|
||||
|
||||
@@ -19,7 +19,7 @@ import uppa.project.Global;
|
||||
* @see jakarta.persistence.EntityManager
|
||||
*/
|
||||
public final class EntityManagerProvider {
|
||||
private static final String PERSISTENCE_UNIT_NAME = Global.PERSISTENCE_UNIT_NAME;
|
||||
private static String PERSISTENCE_UNIT_NAME = Global.PERSISTENCE_UNIT_NAME;
|
||||
|
||||
private static EntityManager instance;
|
||||
private static EntityManagerFactory factory;
|
||||
@@ -35,6 +35,9 @@ public final class EntityManagerProvider {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void setPersitenceUnitName(String name) {
|
||||
PERSISTENCE_UNIT_NAME = name;
|
||||
}
|
||||
public static void close() {
|
||||
if (instance.isOpen()) instance.close();
|
||||
if (factory.isOpen()) factory.close();
|
||||
|
||||
@@ -12,6 +12,11 @@ import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import uppa.project.pojo.Game;
|
||||
import uppa.project.pojo.Player;
|
||||
import uppa.project.pojo.User;
|
||||
|
||||
@WebServlet(name = "mainMenuServlet", value = "/main-menu")
|
||||
public class MainMenuServlet extends HttpServlet {
|
||||
@@ -20,15 +25,39 @@ public class MainMenuServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
|
||||
if (request.getSession().getAttribute("user") == null) {
|
||||
request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
|
||||
User user = (User) request.getSession().getAttribute("user");
|
||||
if (user == null) {
|
||||
response.sendRedirect(request.getContextPath() + "/login");
|
||||
return;
|
||||
}
|
||||
|
||||
manageNewGame(request, response, user);
|
||||
manageStatistiques(request, response, user);
|
||||
response.sendRedirect(request.getContextPath() + "/main-menu");
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
}
|
||||
|
||||
private void manageMainMenu(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
|
||||
}
|
||||
|
||||
private void manageNewGame(HttpServletRequest request, HttpServletResponse response, User sessionUser) throws IOException, ServletException {
|
||||
List<User> connectedUsers = new ArrayList<User>();
|
||||
/*TODO: récuperer la liste des joueurs connectés
|
||||
penser à retirer l'utilisateur principal de la liste*/
|
||||
connectedUsers.remove(sessionUser);
|
||||
request.setAttribute("connectedUsers", connectedUsers);
|
||||
request.getRequestDispatcher("/WEB-INF/views/new-game.jsp").forward(request, response);
|
||||
}
|
||||
|
||||
private void manageStatistiques(HttpServletRequest request, HttpServletResponse response, User sessionUser) throws IOException, ServletException {
|
||||
List<Game> games = new ArrayList<Game>();
|
||||
for(Player player : sessionUser.getPlayedGames()) {
|
||||
Game game = player.getGame();
|
||||
game.sortPlayersByScore();
|
||||
games.add(game);
|
||||
}
|
||||
request.setAttribute("games", games);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,16 +26,6 @@ public class NewGameServlet extends HttpServlet {
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
|
||||
if (request.getSession().getAttribute("user") == null) {
|
||||
response.sendRedirect(request.getContextPath() + "/login");
|
||||
return;
|
||||
}
|
||||
User[] users = new User[0];
|
||||
/*TODO: récuperer la liste des joueurs connectés
|
||||
penser à retirer l'utilisateur principal de la liste*/
|
||||
|
||||
request.setAttribute("connectedUsers", users);
|
||||
request.getRequestDispatcher("/WEB-INF/views/new-game.jsp").forward(request, response);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<%@ page import="uppa.project.pojo.User" %>
|
||||
<%@ page import="java.util.List" %><%--
|
||||
Created by IntelliJ IDEA.
|
||||
User: kmitr
|
||||
Date: 19/03/2024
|
||||
Time: 15:47
|
||||
To change this template use File | Settings | File Templates.
|
||||
--%>
|
||||
<div id="newGameModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<span class="close">×</span>
|
||||
<h1> New Game</h1>
|
||||
<div id="settings">
|
||||
<form>
|
||||
<label for="nbRounds">Nombre de tours</label>
|
||||
<input type="number" id="nbRounds" name="nbRounds" min="1" max="50" value="10">
|
||||
<label for="timer">Timer</label>
|
||||
<input type="number" id="timer" name="timer" min="1" max="10" value="5">
|
||||
<label for="nbColors">Nb couleurs</label>
|
||||
<input type="range" id="nbColors" name="nbColors" min="1" max="4" value="4">
|
||||
<label for="nbValues">Nb valeurs par coleurs</label>
|
||||
<input type="range" id="nbValues" name="nbValues" min="5" max="13" value="13">
|
||||
</form>
|
||||
</div>
|
||||
<div id="players-selection">
|
||||
<table>
|
||||
<tr>
|
||||
<th>Nom d'utilisateur</th>
|
||||
<th>Nombre de partie jouées</th>
|
||||
<th>% Parties Gagnées</th>
|
||||
<th>% Clicks corrects</th>
|
||||
<th>% Clicks rapides</th>
|
||||
<th>Invite</th>
|
||||
</tr>
|
||||
<% List<User> connectedUsers = (List<User>) request.getAttribute("connectedUsers"); %>
|
||||
<% for (User user : connectedUsers) { %>
|
||||
<tr>
|
||||
<td><%= user.getUsername() %></td>
|
||||
<td><%= user.getNbPlayedGame() %></td>
|
||||
<td><%= user.getWinRate() %></td>
|
||||
<td><%= user.getRightClickPercentRate()%></td>
|
||||
<td><%= user.getRapidClickPercentRate()%></td>
|
||||
<td><input type="checkbox" id="<%= user.getUsername()%>-invite" name="<%= user.getUsername()%>-invite"/></td>
|
||||
</tr>
|
||||
<% } %>
|
||||
</table>
|
||||
<button id="startGame">Commencer la partie</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
```
|
||||
@@ -0,0 +1,95 @@
|
||||
<%@ page import="uppa.project.pojo.User" %>
|
||||
<%@ page import="uppa.project.pojo.Game" %>
|
||||
<%@ page import="java.util.Set" %>
|
||||
<%@ page import="java.util.ArrayList" %>
|
||||
<%@ page import="uppa.project.pojo.Player" %><%--
|
||||
Created by IntelliJ IDEA.
|
||||
User: kmitr
|
||||
Date: 26/03/2024
|
||||
Time: 11:05
|
||||
To change this template use File | Settings | File Templates.
|
||||
--%>
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
//modale statistque
|
||||
<% User user = (User) request.getAttribute("user"); %>
|
||||
<% ArrayList<Game> games = (ArrayList<Game>) request.getAttribute("games"); %>
|
||||
<div id="statisticsModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<span class="close">×</span>
|
||||
<h1> New Game</h1>
|
||||
<div id="selfSettings">
|
||||
<h2>Statistiques globales</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Nombre de parties jouées:</th>
|
||||
<td><%= user.getNbPlayedGame() %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Nombre de parties gagnées:</th>
|
||||
<td><%= user.getNbWin() %>, <%= user.getWinRate()%></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Nombre de clicks total:</th>
|
||||
<td><%= user.getNbClicks() %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Nombre de clicks corrects:</th>
|
||||
<td><%= user.getNbRightClicks() %>, <%= user.getRightClickPercentRate()%></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Nombre de clicks rapides:</th>
|
||||
<td><%= user.getNbRapidClicks() %>, <%= user.getRapidClickPercentRate()%></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div id="game-selection">
|
||||
//listes de game dont chacune est un onglet déroulante des joueurs
|
||||
<h2>Statistiques par jeu</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Date de la partie</th>
|
||||
<th>Nombre de joueurs</th>
|
||||
<th>Nombre de manches</th>
|
||||
<th>Nombre de couleurs</th>
|
||||
<th>Nombre de valeurs par couleur</th>
|
||||
<th>Vainqueur</th>
|
||||
</tr>
|
||||
<%
|
||||
for (Game game : games) {
|
||||
%>
|
||||
<tr>
|
||||
<td><%= game.getCreatedAt() %></td>
|
||||
<td><%= game.getNbPlayers() %></td>
|
||||
<td><%= game.getNbRounds() %></td>
|
||||
<td><%= game.getNbColors() %></td>
|
||||
<td><%= game.getNbValuesPerColor() %></td>
|
||||
<td><%= game.getPlayers().get(0).getUser().getUsername() %></td>
|
||||
</tr>
|
||||
<tr class="dropdown" aria-disabled="false">
|
||||
<table>
|
||||
<tr>
|
||||
<th>Username</th>
|
||||
<th>Score</th>
|
||||
<th>Nombre de click</th>
|
||||
<th>Nombre de click corrects</th>
|
||||
<th>Nombre de click rapides</th>
|
||||
</tr>
|
||||
<%
|
||||
for (Player player : game.getPlayers()) {
|
||||
%>
|
||||
<tr>
|
||||
<td><%= player.getUser().getUsername() %></td>
|
||||
<td><%= player.getScore() %></td>
|
||||
<td><%= player.getClickCount() %></td>
|
||||
<td><%= player.getRightClickCount() %>, <%= player.getRatioRightClick() %></td>
|
||||
<td><%= player.getRapidClickCount() %>, <%= player.getRatioRapidClick() %></td>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
</table>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,14 +1,13 @@
|
||||
window.onload = function (){
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
let error = null;
|
||||
if (urlParams.has('error')) {
|
||||
error = urlParams.get('error');
|
||||
}
|
||||
console.log(error);
|
||||
if (error != null && error === "expired-token") {
|
||||
window.alert("Lien expiré, veuillez recommencer la procédure de récupération de mot de passe.");
|
||||
}
|
||||
if (error != null && error === "invalid-token") {
|
||||
window.alert("Lien invalide, veuillez recommencer la procédure de récupération de mot de passe.");
|
||||
}
|
||||
const ERROR_MESSAGE = {
|
||||
"expired-token": "Lien expiré, veuillez recommencer la procédure de récupération de mot de passe.",
|
||||
"invalid-token": "Lien invalide, veuillez recommencer la procédure de récupération de mot de passe.",
|
||||
};
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const error = urlParams.get('error');
|
||||
|
||||
if (error) {
|
||||
const errorMessage = ERROR_MESSAGE[error];
|
||||
console.error(errorMessage);
|
||||
window.alert(errorMessage);
|
||||
}
|
||||
|
||||
@@ -24,14 +24,13 @@ loginForm.addEventListener("submit", (event) => {
|
||||
;
|
||||
});
|
||||
|
||||
window.onload = function (){
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
if (urlParams.has('success')) {
|
||||
if (urlParams.get('success') === "account-created") {
|
||||
window.alert("Compte créé avec succès.");
|
||||
}
|
||||
if (urlParams.get('success') === "password-reseted") {
|
||||
window.alert("Mot de passe réinitialisé avec succès.");
|
||||
}
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
if (urlParams.has('success')) {
|
||||
if (urlParams.get('success') === "account-created") {
|
||||
window.alert("Compte créé avec succès.");
|
||||
}
|
||||
if (urlParams.get('success') === "password-reseted") {
|
||||
window.alert("Mot de passe réinitialisé avec succès.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
// Mise à jour du nombre de rounds max en fonction du nombre de couleurs et de valeurs sélécetionnés
|
||||
document.getElementById("nbColors").addEventListener("change", function () {
|
||||
let nbColors = document.getElementById("nbColors").value;
|
||||
let nbValues = document.getElementById("nbValues").value;
|
||||
let nbRounds = document.getElementById("nbRounds");
|
||||
nbRounds.max = nbColors * nbValues;
|
||||
nbRounds.value = nbRounds.value > nbRounds.max ? nbRounds.max : nbRounds.value;
|
||||
});
|
||||
document.getElementById("nbValues").addEventListener("change", function () {
|
||||
let nbColors = document.getElementById("nbColors").value;
|
||||
let nbValues = document.getElementById("nbValues").value;
|
||||
let nbRounds = document.getElementById("nbRounds");
|
||||
nbRounds.max = nbColors * nbValues;
|
||||
nbRounds.value = nbRounds.value > nbRounds.max ? nbRounds.max : nbRounds.value;
|
||||
});
|
||||
const nbColorsElement = document.getElementById("nbColors");
|
||||
const nbValuesElement = document.getElementById("nbValues");
|
||||
const nbRoundsElement = document.getElementById("nbRounds")
|
||||
|
||||
/**
|
||||
* Mise à jour du nombre de rounds max en fonction du nombre de couleurs et de valeurs séléctionnés
|
||||
*/
|
||||
function updateOnChange() {
|
||||
nbRoundsElement.max = nbColorsElement.value * nbValuesElement.value;
|
||||
|
||||
nbRoundsElement.value =
|
||||
(nbRoundsElement.value > nbRoundsElement.max)
|
||||
? nbRoundsElement.max
|
||||
: nbRoundsElement.value
|
||||
;
|
||||
}
|
||||
|
||||
nbColorsElement.addEventListener("change", updateOnChange);
|
||||
nbValuesElement.addEventListener("change", updateOnChange);
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
const registerForm = document.getElementById("register-form");
|
||||
const confirmPassword = document.getElementById("confirmPassword");
|
||||
|
||||
registerForm.addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
const formData = new FormData(registerForm);
|
||||
|
||||
const data = {};
|
||||
formData.forEach((value, key) => data[key] = value);
|
||||
|
||||
const action = loginForm.getAttribute("action")
|
||||
const method = loginForm.getAttribute("method")
|
||||
|
||||
|
||||
fetch("/reset-password", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
}).then(response => {
|
||||
if (response.ok) {
|
||||
window.location.href = "/login";
|
||||
} else {
|
||||
response.json().then(data => {
|
||||
alert(data.message);
|
||||
});
|
||||
}
|
||||
}).catch(error => console.error("Error:", error));
|
||||
});
|
||||
@@ -1,15 +1,16 @@
|
||||
const ResetPasswordForm = document.getElementById("resetPasswordForm");
|
||||
const resetPasswordForm = document.getElementById("resetPasswordForm");
|
||||
const confirmPassword = document.getElementById("confirmPassword");
|
||||
|
||||
ResetPasswordForm.addEventListener("submit", function (event) {
|
||||
resetPasswordForm.addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
const formData = new FormData(ResetPasswordForm);
|
||||
const formData = new FormData(resetPasswordForm);
|
||||
|
||||
const data = {};
|
||||
formData.forEach((value, key) => data[key] = value);
|
||||
|
||||
const action = loginForm.getAttribute("action")
|
||||
const method = loginForm.getAttribute("method")
|
||||
|
||||
|
||||
fetch("/reset-password", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -28,5 +29,3 @@ ResetPasswordForm.addEventListener("submit", function (event) {
|
||||
console.error("Error:", error);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -26,5 +26,5 @@
|
||||
<%}%>
|
||||
</main>
|
||||
</body>
|
||||
<script defer type="text/javascript"><%@include file="../static/js/forgotten-password.js"%></script>
|
||||
<script defer type="module"><%@include file="../static/js/forgotten-password.js"%></script>
|
||||
</html>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<head>
|
||||
<title> Cards Rush - Connexion</title>
|
||||
<style><%@include file="../static/css/login.css" %></style>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -35,7 +36,7 @@
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<script defer type="text/javascript"><%@include file="../static/js/login.js" %></script>
|
||||
<script defer type="module"><%@include file="../static/js/login.js" %></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Cards Rush</title>
|
||||
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" type="text/css">
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
@@ -11,8 +12,10 @@
|
||||
<section id="main">
|
||||
<h1 id="Title">Titre du jeu</h1>
|
||||
<div class="main-button">
|
||||
<input type="button" value="New game" >
|
||||
<input type="button" value="Hard mode" >
|
||||
//create a modal button for new game:
|
||||
<button data-toggle="modal" data-target="#newGameModal" >New Game</button>
|
||||
<%@include file="../components/new-game.jsp"%>
|
||||
</div>;
|
||||
<input type="button" value="Statistics" >
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
<%@ page import="uppa.project.pojo.User" %><%--
|
||||
Created by IntelliJ IDEA.
|
||||
User: kmitr
|
||||
Date: 19/03/2024
|
||||
Time: 15:47
|
||||
To change this template use File | Settings | File Templates.
|
||||
--%>
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>New game</title>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<section id="newGame">
|
||||
<h1> New Game</h1>
|
||||
<div id="settings">
|
||||
<form>
|
||||
<label for="nbRounds">Nombre de tours</label>
|
||||
<input type="number" id="nbRounds" name="nbRounds" min="1" max="50" value="10">
|
||||
<label for="timer">Timer</label>
|
||||
<input type="number" id="timer" name="timer" min="1" max="10" value="5">
|
||||
<label for="nbColors">Nb coleurs</label>
|
||||
<input type="range" id="nbColors" name="nbColors" min="1" max="4" value="4">
|
||||
<label for="nbValues">Nb valeurs par coleurs</label>
|
||||
<input type="range" id="nbValues" name="nbValues" min="5" max="13" value="13">
|
||||
</form>
|
||||
</div>
|
||||
<div id="players-selection">
|
||||
<table>
|
||||
<tr>
|
||||
<th>Nom d'utilisateur</th>
|
||||
<th>Nombre de partie jouées</th>
|
||||
<th>% Parties Gagnées</th>
|
||||
<th>% Clicks corrects</th>
|
||||
<th>% Clicks rapides</th>
|
||||
<th>Invite</th>
|
||||
</tr>
|
||||
<% User[] connectedUsers = (User[]) request.getAttribute("connectedUsers"); %>
|
||||
<% for (User user : connectedUsers) { %>
|
||||
<tr>
|
||||
<td><%= user.getUsername() %></td>
|
||||
<td><%= user.getNbPlayedGame() %></td>
|
||||
<td><%= user.getWinRate() %></td>
|
||||
<td><%= user.getRightClickPercentRate()%></td>
|
||||
<td><%= user.getRapidClickPercentRate()%></td>
|
||||
<td><input type="checkbox" id="<%= user.getUsername()%>-invite" name="<%= user.getUsername()%>-invite"/></td>
|
||||
</tr>
|
||||
<% } %>
|
||||
</table>
|
||||
<button id="startGame">Commencer la partie</button>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</body>
|
||||
<script defer type="text/javascript"> <%@include file="../static/js/new-game.js"%></script>
|
||||
</html>
|
||||
@@ -51,4 +51,5 @@
|
||||
</main>
|
||||
|
||||
</body>
|
||||
<script defer type="module"><%@include file="../static/js/register.js"%></script>
|
||||
</html>
|
||||
|
||||
@@ -19,8 +19,11 @@ class DeckTest {
|
||||
|
||||
@Test
|
||||
void throw_error_on_creation_of_invalid_deck() {
|
||||
// Nombre de couleurs invalides
|
||||
assertThrows(IllegalArgumentException.class, () -> new Deck(0, 13));
|
||||
assertThrows(IllegalArgumentException.class, () -> new Deck(5, 13));
|
||||
|
||||
// Nombre de valeurs invalides
|
||||
assertThrows(IllegalArgumentException.class, () -> new Deck(1, 0));
|
||||
assertThrows(IllegalArgumentException.class, () -> new Deck(1, 15));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user