fix: dev-web - initialize list of player (... = new arrayList<>()) in User and Game constructors

This commit is contained in:
kmitresse
2024-03-29 09:44:54 +01:00
parent 64e7db3ab0
commit c3c0cbfe7d
2 changed files with 9 additions and 0 deletions
@@ -91,6 +91,8 @@ public class Game implements Serializable {
this.nbValuesPerColor = nbValuesPerColor; this.nbValuesPerColor = nbValuesPerColor;
this.deck = new Deck(nbColors, nbValuesPerColor); this.deck = new Deck(nbColors, nbValuesPerColor);
this.deck.shuffle(); this.deck.shuffle();
this.players = new ArrayList<>();
this.createdAt = new Date();
} }
/** /**
@@ -91,6 +91,7 @@ public class User implements Serializable {
this.password = hashPassword(password); this.password = hashPassword(password);
this.birth = birth; this.birth = birth;
this.gender = gender; this.gender = gender;
this.playedGames = new ArrayList<>();
} }
/** /**
@@ -288,6 +289,7 @@ public class User implements Serializable {
* @return le pourcentage de victoire * @return le pourcentage de victoire
*/ */
public double getWinRate(){ public double getWinRate(){
if (getNbPlayedGame() == 0 || getNbWin() == 0) return 0;
return (double) Math.abs(getNbWin() * 10000 / getNbPlayedGame()) /100; return (double) Math.abs(getNbWin() * 10000 / getNbPlayedGame()) /100;
} }
@@ -323,6 +325,7 @@ public class User implements Serializable {
* @return le pourcentage de clics réussi * @return le pourcentage de clics réussi
*/ */
public double getRightClickPercentRate(){ public double getRightClickPercentRate(){
if (getNbClicks() == 0 || getNbRightClicks() == 0) return 0;
return (double) Math.abs(getNbRightClicks() * 10000 / getNbClicks())/100; return (double) Math.abs(getNbRightClicks() * 10000 / getNbClicks())/100;
} }
@@ -345,11 +348,15 @@ public class User implements Serializable {
* @return le pourcentage de clics les plus rapides * @return le pourcentage de clics les plus rapides
*/ */
public double getRapidClickPercentRate(){ public double getRapidClickPercentRate(){
if (getNbClicks() == 0 || getNbRapidClicks() == 0) return 0;
return (double) Math.abs(getNbRapidClicks() * 10000 / getNbClicks())/100; return (double) Math.abs(getNbRapidClicks() * 10000 / getNbClicks())/100;
} }
public boolean isValidBirthDate(Date birthdate){ public boolean isValidBirthDate(Date birthdate){
System.out.println(birthdate.toString());
Date currentDate = new Date(); Date currentDate = new Date();
System.out.println(currentDate.toString());
return birthdate.before(currentDate) || birthdate.equals(currentDate); return birthdate.before(currentDate) || birthdate.equals(currentDate);
} }