mirror of
https://github.com/kmitresse/Cards-Rush.git
synced 2026-05-13 17:11:49 +00:00
feat: dev-web - manage deck
This commit is contained in:
@@ -38,6 +38,9 @@ public class Deck {
|
||||
cards = initializeDeck(nbColors, nbValues);
|
||||
}
|
||||
|
||||
public Set<Card> getCards() {
|
||||
return cards;
|
||||
}
|
||||
/**
|
||||
* Créé un paquet de cartes mélangé avec un nombre de couleurs et de valeurs donné
|
||||
*
|
||||
@@ -89,4 +92,5 @@ public class Deck {
|
||||
Collections.shuffle(cardList);
|
||||
return new HashSet<>(cardList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.Temporal;
|
||||
import jakarta.persistence.TemporalType;
|
||||
import jakarta.persistence.Transient;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
@@ -61,6 +62,8 @@ public class Game implements Serializable {
|
||||
@OneToMany(mappedBy = "game", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
private Set<Player> players;
|
||||
|
||||
@Transient
|
||||
private Deck deck;
|
||||
/**
|
||||
* Constructeur par défaut
|
||||
*/
|
||||
@@ -81,6 +84,7 @@ public class Game implements Serializable {
|
||||
this.nbRounds = nbRounds;
|
||||
this.nbColors = nbColors;
|
||||
this.nbValuesPerColor = nbValuesPerColor;
|
||||
this.deck = new Deck(nbColors, nbValuesPerColor);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,6 +216,10 @@ public class Game implements Serializable {
|
||||
this.players.add(player);
|
||||
}
|
||||
|
||||
public Set<Card> getDeck() {
|
||||
return deck.getCards();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tri des joueurs de la partie par score
|
||||
*/
|
||||
|
||||
@@ -14,9 +14,11 @@ import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.Transient;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Représentation d'un joueur
|
||||
@@ -56,6 +58,9 @@ public class Player implements Serializable {
|
||||
@Column(name = "rapid_click_count")
|
||||
private int rapidClickCount;
|
||||
|
||||
@Transient
|
||||
private Deck deck;
|
||||
|
||||
/**
|
||||
* Constructeur par défaut
|
||||
*/
|
||||
@@ -74,6 +79,7 @@ public class Player implements Serializable {
|
||||
this.clickCount = 0;
|
||||
this.rightClickCount = 0;
|
||||
this.rapidClickCount = 0;
|
||||
this.deck = new Deck(game.getNbColors(), game.getNbValuesPerColor());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,6 +258,10 @@ public class Player implements Serializable {
|
||||
public double getRatioRapidClick() {
|
||||
return (double) rapidClickCount * 100 / clickCount;
|
||||
}
|
||||
|
||||
public Set<Card> getDeck() {
|
||||
return deck.getCards();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Player{id=%s, game=%s, user=%s, score=%d, winner=%b, clickCount=%d, rightClickCount=%d, rapidClickCount=%d}", id.toString(), game.toString(), user.toString(), score, winner, clickCount, rightClickCount, rapidClickCount);
|
||||
|
||||
Reference in New Issue
Block a user