feat: devWeb - add detail on connected users

This commit is contained in:
kmitresse
2024-05-01 19:19:29 +02:00
parent 650393e319
commit d1c4b84fa8
7 changed files with 56 additions and 5 deletions
@@ -192,6 +192,12 @@ public class Player implements Serializable {
this.score += points; 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 * @return si le joueur est gagnant
*/ */
@@ -328,4 +334,6 @@ public class Player implements Serializable {
public void setCurrentClick(ClickChoice currentClick) { public void setCurrentClick(ClickChoice currentClick) {
this.currentClick = currentClick; this.currentClick = currentClick;
} }
} }
@@ -346,6 +346,18 @@ public class User implements Serializable {
return nbWin; 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 * Récupère le pourcentage de victoire
* *
@@ -8,6 +8,8 @@ public class SimpleUser {
private final int nbPlayedGames; private final int nbPlayedGames;
private final int nbWin; private final int nbWin;
private final double winRate;
private final double scoreRate;
private final double rigthClickPercentRate; private final double rigthClickPercentRate;
private final double rapidClickPercentRate; private final double rapidClickPercentRate;
@@ -16,6 +18,8 @@ public class SimpleUser {
this.username = user.getUsername(); this.username = user.getUsername();
this.nbPlayedGames = user.getNbPlayedGame(); this.nbPlayedGames = user.getNbPlayedGame();
this.nbWin = user.getNbWin(); this.nbWin = user.getNbWin();
this.winRate = user.getWinRate();
this.scoreRate = user.getScoreRate();
this.rigthClickPercentRate = user.getRightClickPercentRate(); this.rigthClickPercentRate = user.getRightClickPercentRate();
this.rapidClickPercentRate = user.getRapidClickPercentRate(); this.rapidClickPercentRate = user.getRapidClickPercentRate();
} }
@@ -36,6 +40,14 @@ public class SimpleUser {
return nbWin; return nbWin;
} }
public double getWinRate() {
return winRate;
}
public double getScoreRate() {
return scoreRate;
}
public double getRigthClickPercentRate() { public double getRigthClickPercentRate() {
return rigthClickPercentRate; return rigthClickPercentRate;
} }
@@ -119,7 +119,10 @@ public class GameWS {
player.incrementClickCount(); player.incrementClickCount();
// Compteur de clics rapides // 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 // Vérifier le choix du joueur et attribuer les points
if (game.getDifficulty().equals(Game.Difficulty.EASY)) { if (game.getDifficulty().equals(Game.Difficulty.EASY)) {
@@ -68,7 +68,7 @@
<!-- Liste des utilisateurs dans le lobby --> <!-- Liste des utilisateurs dans le lobby -->
<div id="user-list-modal" class="modal"> <div id="user-list-modal" class="modal">
<div class="modal-background"></div> <div class="modal-background"></div>
<div class="modal-card"> <div class="modal-card modal-">
<header class="modal-card-head"> <header class="modal-card-head">
<p class="modal-card-title">Liste des utilisateurs connectés</p> <p class="modal-card-title">Liste des utilisateurs connectés</p>
<button class="delete" aria-label="close"></button> <button class="delete" aria-label="close"></button>
@@ -80,6 +80,7 @@
<th>Utilisateur</th> <th>Utilisateur</th>
<th>Nombre de parties jouées</th> <th>Nombre de parties jouées</th>
<th>Nombre de victoires</th> <th>Nombre de victoires</th>
<th>Score moyen</th>
<th>Clics corrects</th> <th>Clics corrects</th>
<th>Clics rapides</th> <th>Clics rapides</th>
<th>Action</th> <th>Action</th>
@@ -91,7 +92,7 @@
</table> </table>
</section> </section>
<footer class="modal-card-foot"> <footer class="modal-card-foot">
<button class="button is-primary is-light">Fermer</button> <button class="button is-light">Fermer</button>
</footer> </footer>
</div> </div>
</div> </div>
@@ -136,6 +137,7 @@
const $tdUsername = document.createElement('td'); const $tdUsername = document.createElement('td');
const $tdNbPlayedGame = document.createElement('td'); const $tdNbPlayedGame = document.createElement('td');
const $tdNbWins = document.createElement('td'); const $tdNbWins = document.createElement('td');
const $tdScore = document.createElement('td');
const $tdRightClick = document.createElement('td'); const $tdRightClick = document.createElement('td');
const $tdRapidClick = document.createElement('td'); const $tdRapidClick = document.createElement('td');
const $tdAction = document.createElement('td'); const $tdAction = document.createElement('td');
@@ -164,6 +166,7 @@
$tdUsername.textContent = user.username; $tdUsername.textContent = user.username;
$tdNbPlayedGame.textContent = user.nbPlayedGames; $tdNbPlayedGame.textContent = user.nbPlayedGames;
$tdNbWins.textContent = user.nbWin; $tdNbWins.textContent = user.nbWin;
$tdScore.textContent = user.scoreRate + "%";
$tdRightClick.textContent = user.rigthClickPercentRate + "%"; $tdRightClick.textContent = user.rigthClickPercentRate + "%";
$tdRapidClick.textContent = user.rapidClickPercentRate + "%"; $tdRapidClick.textContent = user.rapidClickPercentRate + "%";
$tdAction.appendChild($button); $tdAction.appendChild($button);
@@ -171,6 +174,7 @@
$tr.appendChild($tdUsername); $tr.appendChild($tdUsername);
$tr.appendChild($tdNbPlayedGame); $tr.appendChild($tdNbPlayedGame);
$tr.appendChild($tdNbWins); $tr.appendChild($tdNbWins);
$tr.appendChild($tdScore);
$tr.appendChild($tdRightClick); $tr.appendChild($tdRightClick);
$tr.appendChild($tdRapidClick); $tr.appendChild($tdRapidClick);
$tr.appendChild($tdAction); $tr.appendChild($tdAction);
@@ -11,6 +11,7 @@
<th>Nom d'utilisateur</th> <th>Nom d'utilisateur</th>
<th>Nombre de parties jouées</th> <th>Nombre de parties jouées</th>
<th>Nombre de victoires</th> <th>Nombre de victoires</th>
<th>Score moyen</th>
</tr> </tr>
</thead> </thead>
<tbody></tbody> <tbody></tbody>
@@ -37,12 +38,16 @@
tdNbGames.textContent = user.nbPlayedGames; tdNbGames.textContent = user.nbPlayedGames;
const tdNbWin = document.createElement('td'); const tdNbWin = document.createElement('td');
tdNbWin.dataset.id = user.id; tdNbWin.dataset.id = user.id;
tdNbWin.textContent = user.nbWin; tdNbWin.textContent = user.nbWin + " (" + user.winRate + "%)";
const tdScoreRate = document.createElement('td');
tdScoreRate.dataset.id = user.id;
tdScoreRate.textContent = user.scoreRate + "%";
tr.appendChild(tdUsername); tr.appendChild(tdUsername);
tr.appendChild(tdNbGames); tr.appendChild(tdNbGames);
tr.appendChild(tdNbWin); tr.appendChild(tdNbWin);
tr.appendChild(tdScoreRate);
table.appendChild(tr); table.appendChild(tr);
}); });
} }
@@ -2,8 +2,15 @@
--bulma-primary-h: 0; --bulma-primary-h: 0;
--bulma-primary-s: 70%; --bulma-primary-s: 70%;
--bulma-primary-l: 35%; --bulma-primary-l: 35%;
--modal-content-width: 50rem;
} }
.hero { .hero {
background: url("../img/Home.svg") lightgray 50% / cover no-repeat; background: url("../img/Home.svg") lightgray 50% / cover no-repeat;
} }
@media screen and (min-width: 769px) {
.modal-card, .modal-content {
width: var(--modal-content-width) !important;
}
}