diff --git a/S2/DevWeb/Projet/src/main/java/uppa/project/database/pojo/Player.java b/S2/DevWeb/Projet/src/main/java/uppa/project/database/pojo/Player.java index f356417..745b96b 100644 --- a/S2/DevWeb/Projet/src/main/java/uppa/project/database/pojo/Player.java +++ b/S2/DevWeb/Projet/src/main/java/uppa/project/database/pojo/Player.java @@ -192,6 +192,12 @@ public class Player implements Serializable { this.score += points; } + /** + * @return le score maximum possible + */ + public int getScoreMax(){ + return game.getNbRounds() * 3; // 2 points par bonne réponse + 1 point pour le clic rapide + } /** * @return si le joueur est gagnant */ @@ -328,4 +334,6 @@ public class Player implements Serializable { public void setCurrentClick(ClickChoice currentClick) { this.currentClick = currentClick; } + + } diff --git a/S2/DevWeb/Projet/src/main/java/uppa/project/database/pojo/User.java b/S2/DevWeb/Projet/src/main/java/uppa/project/database/pojo/User.java index 82988e0..dcee129 100644 --- a/S2/DevWeb/Projet/src/main/java/uppa/project/database/pojo/User.java +++ b/S2/DevWeb/Projet/src/main/java/uppa/project/database/pojo/User.java @@ -346,6 +346,18 @@ public class User implements Serializable { return nbWin; } + public double getScoreRate(){ + if (getNbPlayedGame() == 0) return 0; + int maxScore = 0; + int totalScore = 0; + for (Player p : playedGames) { + System.out.println("Score max : " + p.getScoreMax() + " Score : " + p.getScore()); + maxScore += p.getScoreMax(); + totalScore += p.getScore(); + } + return (double) Math.abs(totalScore * 100 / maxScore); + } + /** * Récupère le pourcentage de victoire * diff --git a/S2/DevWeb/Projet/src/main/java/uppa/project/json/websocket/SimpleUser.java b/S2/DevWeb/Projet/src/main/java/uppa/project/json/websocket/SimpleUser.java index 0269958..b10743f 100644 --- a/S2/DevWeb/Projet/src/main/java/uppa/project/json/websocket/SimpleUser.java +++ b/S2/DevWeb/Projet/src/main/java/uppa/project/json/websocket/SimpleUser.java @@ -8,6 +8,8 @@ public class SimpleUser { private final int nbPlayedGames; private final int nbWin; + private final double winRate; + private final double scoreRate; private final double rigthClickPercentRate; private final double rapidClickPercentRate; @@ -16,6 +18,8 @@ public class SimpleUser { this.username = user.getUsername(); this.nbPlayedGames = user.getNbPlayedGame(); this.nbWin = user.getNbWin(); + this.winRate = user.getWinRate(); + this.scoreRate = user.getScoreRate(); this.rigthClickPercentRate = user.getRightClickPercentRate(); this.rapidClickPercentRate = user.getRapidClickPercentRate(); } @@ -36,6 +40,14 @@ public class SimpleUser { return nbWin; } + public double getWinRate() { + return winRate; + } + + public double getScoreRate() { + return scoreRate; + } + public double getRigthClickPercentRate() { return rigthClickPercentRate; } diff --git a/S2/DevWeb/Projet/src/main/java/uppa/project/web/websocket/GameWS.java b/S2/DevWeb/Projet/src/main/java/uppa/project/web/websocket/GameWS.java index eb7e9ea..e2b5c21 100644 --- a/S2/DevWeb/Projet/src/main/java/uppa/project/web/websocket/GameWS.java +++ b/S2/DevWeb/Projet/src/main/java/uppa/project/web/websocket/GameWS.java @@ -119,7 +119,10 @@ public class GameWS { player.incrementClickCount(); // Compteur de clics rapides - if (gameClickCount == 1) player.incrementRapidClickCount(); + if (gameClickCount == 1) { + player.incrementRapidClickCount(); + player.addToScore(1); + }; // Vérifier le choix du joueur et attribuer les points if (game.getDifficulty().equals(Game.Difficulty.EASY)) { 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 index 9685de6..74f1a13 100644 --- a/S2/DevWeb/Projet/src/main/webapp/WEB-INF/pages/game.jsp +++ b/S2/DevWeb/Projet/src/main/webapp/WEB-INF/pages/game.jsp @@ -68,7 +68,7 @@