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 ed35819..e3f6e22 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 @@ -53,12 +53,19 @@ public class Player implements Serializable { @Column(name = "click_count") private int clickCount; + @Column(name = "right_click_count") private int rightClickCount; + @Transient + private int tmpRightClickCount; + @Transient private int partialRightClickCount; + @Transient + private int tmpPartialRightClickCount; + @Column(name = "rapid_click_count") private int rapidClickCount; @@ -90,6 +97,8 @@ public class Player implements Serializable { this.deck = new Deck(game.getNbColors(), game.getNbValuesPerColor()); this.deck.shuffle(); this.partialRightClickCount = 0; + this.tmpRightClickCount = 0; + this.tmpPartialRightClickCount = 0; } /** @@ -109,6 +118,8 @@ public class Player implements Serializable { this.deck = new Deck(game.getNbColors(), game.getNbValuesPerColor()); this.deck.shuffle(); this.partialRightClickCount = 0; + this.tmpRightClickCount = 0; + this.tmpPartialRightClickCount = 0; } /** @@ -132,6 +143,8 @@ public class Player implements Serializable { this.rightClickCount = rightClickCount; this.rapidClickCount = rapidClickCount; this.partialRightClickCount = 0; + this.tmpRightClickCount = 0; + this.tmpPartialRightClickCount = 0; this.deck = new Deck(game.getNbColors(), game.getNbValuesPerColor()); this.deck.shuffle(); @@ -265,6 +278,22 @@ public class Player implements Serializable { rightClickCount++; } + /** + * @return le nombre de clics corrects du joueur + */ + public int getTmpRightClickCount() { + return tmpRightClickCount; + } + + /** + * Incrémente de 1 le nombre de clics corrects + */ + public void incrementTmpRightClickCount() { + tmpRightClickCount++; + } + + + /** * @return le pourcentage de clics corrects du joueur sur la partie courante */ @@ -294,6 +323,20 @@ public class Player implements Serializable { partialRightClickCount++; } + /** + * @return le nombre de clics corrects du joueur + */ + public int getTmpPartialRightClickCount() { + return tmpPartialRightClickCount; + } + + /** + * Incrémente de 1 le nombre de clics corrects + */ + public void incrementTmpPartialRightClickCount() { + tmpPartialRightClickCount++; + } + /** * Modifie le nombre de clics rapides * @@ -357,4 +400,7 @@ public class Player implements Serializable { } + public void setPartialRightClickCount(int tmpPartialRightClickCount) { + this.partialRightClickCount = tmpPartialRightClickCount; + } } 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 c4f100d..00beec0 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 @@ -100,6 +100,12 @@ public class GameWS { timers.put(game, timer); } + ArrayList playersCurrentCards = new ArrayList<>(games.get(game).size()); + for (Player player : games.get(game)) { + playersCurrentCards.add(player.getDeck().getCards().get((player.getPartialRightClickCount()+player.getRightClickCount()) % player.getDeck().getCards().size())); + } + + if (message.getType().equals("click")) { ClickChoice choice = gson.fromJson(message.getData(), ClickChoice.class); @@ -188,10 +194,11 @@ public class GameWS { case TIMER_END -> {} } } else { - int nbSameCard = countSameCard(gameCard, games.get(game), game.getCurrentRound()); - int nbSameColor = countSameColor(gameCard, games.get(game), game.getCurrentRound()); - int nbSameValue = countSameValue(gameCard, games.get(game), game.getCurrentRound()); - int nbNone = countNone(gameCard, games.get(game), game.getCurrentRound()); + int nbSameCard = countSameCard(gameCard, playersCurrentCards); + int nbSameColor = countSameColor(gameCard, playersCurrentCards); + int nbSameValue = countSameValue(gameCard, playersCurrentCards); + int nbNone = countNone(gameCard, playersCurrentCards); + switch (choice) { case COLOR_VALUE -> { if ((nbSameCard >= nbSameColor) && (nbSameCard >= nbSameValue) && (nbSameCard >= nbNone)) { @@ -199,7 +206,7 @@ public class GameWS { player.incrementRapidClickCount(); playerScore++; } - player.incrementRightClickCount(); + player.incrementTmpRightClickCount(); player.setScore(playerScore + 2); } else { player.setScore(playerScore - 1); @@ -207,14 +214,14 @@ public class GameWS { } case COLOR -> { if ((nbSameCard >= nbSameColor) && (nbSameCard >= nbSameValue) && (nbSameCard >= nbNone)) { - player.incrementPartialRightClickCount(); + player.incrementTmpPartialRightClickCount(); player.setScore(playerScore + 1); } else if ((nbSameColor > nbSameCard) && (nbSameColor >= nbSameValue) && (nbSameColor >= nbNone)) { if (isRapid) { player.incrementRapidClickCount(); playerScore++; } - player.incrementRightClickCount(); + player.incrementTmpRightClickCount(); player.setScore(playerScore + 2); } else { player.setScore(playerScore - 1); @@ -222,14 +229,14 @@ public class GameWS { } case VALUE -> { if ((nbSameCard >= nbSameColor) && (nbSameCard >= nbSameValue) && (nbSameCard >= nbNone)) { - player.incrementPartialRightClickCount(); + player.incrementTmpPartialRightClickCount(); player.setScore(playerScore + 1); } else if ((nbSameValue > nbSameCard) && (nbSameValue > nbSameColor) && (nbSameValue >= nbNone)) { if (isRapid) { player.incrementRapidClickCount(); playerScore++; } - player.incrementRightClickCount(); + player.incrementTmpRightClickCount(); player.setScore(playerScore + 2); } else { player.setScore(playerScore - 1); @@ -241,7 +248,7 @@ public class GameWS { player.incrementRapidClickCount(); playerScore++; } - player.incrementRightClickCount(); + player.incrementTmpRightClickCount(); player.setScore(playerScore + 2); } else { player.setScore(playerScore - 1); @@ -249,6 +256,7 @@ public class GameWS { } case TIMER_END -> {} } + } // Diffuser le score du joueur @@ -260,7 +268,11 @@ public class GameWS { timers.get(game).cancel(); // Réinitialiser les clics courrants - for (Player p : games.get(game)) p.setCurrentClick(null); + for (Player p : games.get(game)) { + p.setRightClickCount(p.getTmpRightClickCount()); + p.setPartialRightClickCount(p.getTmpPartialRightClickCount()); + p.setCurrentClick(null); + } List players = games.get(game); players.sort((p1, p2) -> { @@ -308,15 +320,14 @@ public class GameWS { * Retourne le nombre de joueurs avec une carte identique à celle du plateau * * @param gameCard carte du plateau - * @param players liste des joueurs - * @param currentRound manche courante + * @param currentCards liste des cartes des joueurs * @return nombre de cartes identiques à celle du plateau */ - private int countSameCard(Card gameCard, List players, int currentRound) { + private int countSameCard(Card gameCard, List currentCards) { int counter = 0; - for (Player player : players) { - Card card = player.getDeck().getCards().get(currentRound); + for (Card card : currentCards) { if (gameCard.equals(card)) { + counter++; } } @@ -326,15 +337,13 @@ public class GameWS { /** * Retourne le nombre de joueurs avec une carte avec seulement la couleur correspondante à celle du plateau * - * @param gameCard - * @param players - * @param currentRound + * @param gameCard carte du plateau + * @param currentCards liste des cartes des joueurs * @return nombre de couleurs identiques à celle du plateau */ - private int countSameColor(Card gameCard, List players, int currentRound) { + private int countSameColor(Card gameCard, List currentCards) { int counter = 0; - for (Player player : players) { - Card card = player.getDeck().getCards().get(currentRound); + for (Card card : currentCards) { if (gameCard.getColor().equals(card.getColor()) && !gameCard.getValue().equals(card.getValue())) { counter++; } @@ -346,14 +355,12 @@ public class GameWS { * Retourne le nombre de joueurs avec une carte avec seulement la valeur correspondante à celle du plateau * * @param gameCard carte du plateau - * @param players liste des joueurs - * @param currentRound manche courante + * @param currentCards liste des cartes des joueurs * @return nombre de valeurs identiques à celle du plateau */ - private int countSameValue(Card gameCard, List players, int currentRound) { + private int countSameValue(Card gameCard, List currentCards) { int counter = 0; - for (Player player : players) { - Card card = player.getDeck().getCards().get(currentRound); + for (Card card : currentCards) { if (gameCard.getValue().equals(card.getValue()) && !gameCard.getColor().equals(card.getColor())) { counter++; } @@ -364,15 +371,13 @@ public class GameWS { /** * Retourne le nombre de joueurs avec une carte totalement différente de celle du plateau * - * @param gameCard - * @param players - * @param currentRound + * @param gameCard carte du plateau + * @param currentCards liste des cartes des joueurs * @return nombre de cartes totalement différentes de celle du plateau */ - private int countNone(Card gameCard, List players, int currentRound) { + private int countNone(Card gameCard, List currentCards) { int counter = 0; - for (Player player : players) { - Card card = player.getDeck().getCards().get(currentRound); + for (Card card : currentCards) { if (!gameCard.getColor().equals(card.getColor()) && !gameCard.getValue().equals(card.getValue())) { counter++; } diff --git a/S2/DevWeb/Projet/src/main/webapp/static/js/websockets/game-management-websocket.js b/S2/DevWeb/Projet/src/main/webapp/static/js/websockets/game-management-websocket.js index 4a9727d..12d0f5c 100644 --- a/S2/DevWeb/Projet/src/main/webapp/static/js/websockets/game-management-websocket.js +++ b/S2/DevWeb/Projet/src/main/webapp/static/js/websockets/game-management-websocket.js @@ -201,7 +201,6 @@ wsgame.onMessage("nextRound", (game) => { game.players .filter(p => p.user.id.toString() !== userSessionId.value) .forEach(p => { - console.log('adversaire:', p) const playerHand = new PlayerHand(p); otherCards.innerHTML += playerHand.render({ textPosition: PlayerHand.TextPosition.TOP,