end: devWeb - ending project

This commit is contained in:
kmitresse
2024-05-01 21:28:36 +02:00
parent d1c4b84fa8
commit a78dcc6304
26 changed files with 48 additions and 2246 deletions
@@ -134,7 +134,6 @@ public class ForgottenPasswordBean implements Serializable {
// Envoi du message
Transport.send(message);
System.out.println("E-mail envoyé avec succès à : " + email);
} catch (MessagingException e) {
throw new RuntimeException("Erreur lors de l'envoi de l'e-mail", e);
}
@@ -56,6 +56,9 @@ public class Player implements Serializable {
@Column(name = "right_click_count")
private int rightClickCount;
@Transient
private int partialRightClickCount;
@Column(name = "rapid_click_count")
private int rapidClickCount;
@@ -68,6 +71,7 @@ public class Player implements Serializable {
@Transient
private ClickChoice currentClick = null;
/**
* Constructeur par défaut
*/
@@ -85,6 +89,7 @@ public class Player implements Serializable {
this.rapidClickCount = 0;
this.deck = new Deck(game.getNbColors(), game.getNbValuesPerColor());
this.deck.shuffle();
this.partialRightClickCount = 0;
}
/**
@@ -103,6 +108,7 @@ public class Player implements Serializable {
this.rapidClickCount = 0;
this.deck = new Deck(game.getNbColors(), game.getNbValuesPerColor());
this.deck.shuffle();
this.partialRightClickCount = 0;
}
/**
@@ -125,6 +131,7 @@ public class Player implements Serializable {
this.clickCount = clickCount;
this.rightClickCount = rightClickCount;
this.rapidClickCount = rapidClickCount;
this.partialRightClickCount = 0;
this.deck = new Deck(game.getNbColors(), game.getNbValuesPerColor());
this.deck.shuffle();
@@ -273,6 +280,20 @@ public class Player implements Serializable {
return rapidClickCount;
}
/**
* @return le nombre de clics partiels corrects
*/
public int getPartialRightClickCount() {
return partialRightClickCount;
}
/**
* Incrémente de 1 le nombre de clics partielement corrects
*/
public void incrementPartialRightClickCount() {
partialRightClickCount++;
}
/**
* Modifie le nombre de clics rapides
*
@@ -351,7 +351,6 @@ public class User implements Serializable {
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();
}
@@ -10,6 +10,7 @@ public class SimplePlayer {
private final boolean winner;
private final int clickCount;
private final int rightClickCount;
private final int partialRightClickCount;
private final int rapidClickCount;
private final Card currentCard;
@@ -20,8 +21,8 @@ public class SimplePlayer {
this.clickCount = player.getClickCount();
this.rightClickCount = player.getRightClickCount();
this.rapidClickCount = player.getRapidClickCount();
this.currentCard = player.getDeck().getCards().get(currentRound % player.getDeck().getCards().size());
this.partialRightClickCount = player.getPartialRightClickCount();
this.currentCard = player.getDeck().getCards().get((partialRightClickCount+rightClickCount) % player.getDeck().getCards().size());
}
public SimplePlayer(Player player) {
@@ -30,6 +31,7 @@ public class SimplePlayer {
this.winner = player.isWinner();
this.clickCount = player.getClickCount();
this.rightClickCount = player.getRightClickCount();
this.partialRightClickCount = player.getPartialRightClickCount();
this.rapidClickCount = player.getRapidClickCount();
this.currentCard = null;
}
@@ -54,6 +56,10 @@ public class SimplePlayer {
return clickCount;
}
public int getPartialRightClickCount() {
return partialRightClickCount;
}
public int getRightClickCount() {
return rightClickCount;
}
@@ -10,6 +10,7 @@ public class SimpleUser {
private final int nbWin;
private final double winRate;
private final double scoreRate;
private final double rigthClickPercentRate;
private final double rapidClickPercentRate;
@@ -44,7 +44,6 @@ public class ProfileServlet extends HttpServlet {
userDAO = new Game_JPA_DAO_Factory().getDAOUser();
User user = userDAO.findById(usersession.getId().intValue());
for(Player p : user.getPlayedGames()){
System.out.println("Partie jouée le " + p.getGame().getCreatedAt().toLocaleString());
}
request.getSession().setAttribute("user", user);
request.getRequestDispatcher("/WEB-INF/pages/profile.jsp").forward(request, response);
@@ -119,7 +119,7 @@ public class GameWS {
player.incrementClickCount();
// Compteur de clics rapides
if (gameClickCount == 1) {
if (gameClickCount == 1 && choice != ClickChoice.TIMER_END) {
player.incrementRapidClickCount();
player.addToScore(1);
};
@@ -141,6 +141,7 @@ public class GameWS {
player.incrementRightClickCount();
player.setScore(playerScore + 2);
} else {
player.incrementPartialRightClickCount();
player.setScore(playerScore + 1);
}
} else {
@@ -153,6 +154,7 @@ public class GameWS {
player.incrementRightClickCount();
player.setScore(playerScore + 2);
} else {
player.incrementPartialRightClickCount();
player.setScore(playerScore + 1);
}
} else {
@@ -180,11 +182,13 @@ public class GameWS {
player.incrementRightClickCount();
player.setScore(playerScore + 2);
} else {
player.setScore(playerScore - 1);
}
}
case COLOR -> {
if ((nbSameCard >= nbSameColor) && (nbSameCard >= nbSameValue) && (nbSameCard >= nbNone)) {
player.incrementPartialRightClickCount();
player.setScore(playerScore + 1);
} else if ((nbSameColor > nbSameCard) && (nbSameColor >= nbSameValue) && (nbSameColor >= nbNone)) {
player.incrementRightClickCount();
@@ -195,6 +199,7 @@ public class GameWS {
}
case VALUE -> {
if ((nbSameCard >= nbSameColor) && (nbSameCard >= nbSameValue) && (nbSameCard >= nbNone)) {
player.incrementPartialRightClickCount();
player.setScore(playerScore + 1);
} else if ((nbSameValue > nbSameCard) && (nbSameValue > nbSameColor) && (nbSameValue >= nbNone)) {
player.incrementRightClickCount();
@@ -218,9 +223,6 @@ public class GameWS {
// Diffuser le score du joueur
broadcast(new Message("updatePlayer", gson.toJson(new SimplePlayer(player))).toJson());
System.out.println(gameClickCount + " / " + games.get(game).size());
// Si tous les joueurs ont cliqué
if (gameClickCount >= games.get(game).size()) {
// Stopper le timer
@@ -261,7 +263,6 @@ public class GameWS {
for (Player p : games.get(game)) {
PlayerBean playerBean = new PlayerBean(p);
if (playerBean.validate()) System.out.println("Player " + p.getUser().getUsername() + " sauvegardé en base de données");
else System.out.println();
}
em.getTransaction().commit();
@@ -53,7 +53,7 @@
<div class="buttons is-flex-direction-column">
<p id="round" class="title has-text-white"></p>
<p id="timer" class="subtitle has-text-white"></p>
<button class="button is-fullwidth" data-value="COLOR_VALUE">Même couleur et valeur</button>
<button class="button is-fullwidth" data-value="COLOR_VALUE">Même carte</button>
<button class="button is-fullwidth" data-value="COLOR">Même couleur</button>
<button class="button is-fullwidth" data-value="VALUE">Même valeur</button>
<button class="button is-fullwidth" data-value="NONE">Aucun</button>
@@ -13,24 +13,24 @@
<img class="py-5" src="${pageContext.request.contextPath}/static/img/CardsRushLogoBlack.svg"/>
</div>
<p>
Card Rush est un jeu de rapidité multijoueur en ligne.<br>
Chaque joueur possède un jeu de carte identique mélangé aléatoirement. Au centre du plateau un jeu de carte
Card Rush est un jeu de rapidité multijoueurs en ligne.<br>
Chaque joueur possède un jeu de cartes identique mais mélangé aléatoirement. Au centre du plateau un jeu de carte
similaire.<br>
Votre objectif si vous l'acceptez, identifier les similitudes entre votre main et celle du plateau le plus
rapidement possible.
Plusieurs choix sont possibles:
Plusieurs choix sont possibles :
</p>
<ul>
<li>Les cartes comparées sont identiques</li>
<li>Les cartes comparées ont la même couleur mais pas la même valeur</li>
<li>Les cartes comparées ont la même valeur mais pas la même couleur</li>
<li>Les cartes comparées ont la même couleur, mais pas la même valeur</li>
<li>Les cartes comparées ont la même valeur, mais pas la même couleur</li>
<li>Les cartes comparées sont totalement différentes</li>
</ul>
<h2>Modes de difficultés</h2>
<p>Deux modes de difficultés s'offrent à vous :</p>
<ul>
<li><p>Le mode <span class="tag is-light is-medium is-primary">facile</span>: Vous ne devez effectuer des
comparaisons uniquement entre voter main et celle du plateau.</p>
<li><p>Le mode <span class="tag is-light is-medium is-primary">facile</span>: Vous ne devez uniquement effectuer des
comparaisons entre votre main et celle du plateau.</p>
<p>
Exemple : <br>
Vous : 4 de pique <br>
@@ -40,10 +40,10 @@
</li>
<li><p>
Le mode <span class="tag is-light is-medium is-primary">difficile</span>: Vous devez effectuer des
comparaisons avec les mains de chaque joueur et opter pour la réponse correspondant aux plus grand nombre
de joueur.<br>
comparaisons entre le plateau et les mains de chaque joueur (vous compris) et opter pour la réponse correspondant aux plus grand nombre
de joueurs.<br>
Attention : Une priorité est définie pour les réponses: </p>
<p class="has-text-weight-bold is-centered"> "Même carte" > "Même Couleur" > "Même Valeur" > "Aucun"</p>
<p class="has-text-weight-bold is-centered"> "Même carte" > "Même couleur" > "Même valeur" > "Aucun"</p>
<p>
Si deux réponses sont possibles car elles représentent le même nombre de joueurs, la réponse la plus prioritaire est définie comme correcte.
</p>
@@ -66,6 +66,7 @@
</li>
<li>Aucune réponse : <span class="tag is-light">+0pt</span></li>
<li>Mauvaise réponse : <span class="tag is-danger">-1pt</span></li>
<li>Bonus de rapidité : <span class="tag is-success">+1pt</span></li>
</ul>
<h2>Vainqueur de la partie</h2>
<p>Le vainqueur d'une partie est celui qui aura accumulé le plus de points, en cas d'égalité, le joueur le plus rapide est déclaré vainqueur.<br>
@@ -48,8 +48,6 @@
})
.then(() => window.location.href = "${pageContext.request.contextPath}/lobby")
.catch((error) => {
console.log(error)
// Animations des champs
inputs.forEach(input => {
input.classList.add("is-danger");
@@ -98,8 +98,6 @@
tooltip.innerHTML = input.value
nbRound.max = nbValues.value * nbColors.value;
nbRound.value = parseInt(nbRound.value) > parseInt(nbRound.max) ? nbRound.max : nbRoundtmp;
console.log("newValue : " + nbRound.value)
});
});
@@ -98,7 +98,6 @@
changePassword.addEventListener("click", (e) => {
e.preventDefault();
passwordFields.forEach(field => {
console.log(field)
field.style.display = "block";
});
});
@@ -122,7 +121,6 @@
const url = new URL(action);
const formData = new FormData(profileForm);
for (const [key, value] of formData.entries()) {
console.log(key, value);
url.searchParams.append(key, value);
}
url.searchParams.append("id", ${user.id})
@@ -130,7 +128,6 @@
fetch(url, {headers: {"Content-Type": "application/json"}, method})
.then(res => res.json())
.then(data => {
console.log(data)
if (data.code !== 200) throw new Error(data.message);
onSuccess()
})
@@ -163,7 +160,6 @@
notification.appendChild(notificationTitle);
notification.appendChild(notificationMessage);
document.body.appendChild(notification);
console.log("je suis bien dans la fonction mais la notification ne s'affiche pas")
setTimeout(() => {
notification.remove()
inputs.forEach(input => input.classList.remove("is-danger"));
@@ -193,7 +189,6 @@
notification.appendChild(notificationTitle);
notification.appendChild(notificationMessage);
document.body.appendChild(notification);
console.log("je suis bien dans la fonction mais la notification ne s'affiche pas")
setTimeout(() => notification.remove(), 5010);
}
@@ -3,7 +3,6 @@ export default class Message {
const message = JSON.parse(rawMessage);
message.data = JSON.parse(message.data);
console.log(message);
this.type = message.type;
this.data = message.data;