This commit is contained in:
aminecmi 2021-10-30 14:33:15 +02:00
parent 7ebea34f12
commit 9e789cc645
3 changed files with 9 additions and 3 deletions

View File

@ -1,5 +1,5 @@
package fr.aminelouveaau.cartes.model; package fr.aminelouveaau.cartes.model;
public enum Number { public enum Number {
ACE, KING, QUEEN, JACK, TEN, NINE, HEIGHT, SEVEN, SIX, FIXE, FOUR, THREE, TWO ACE, KING, QUEEN, JACK, TEN, NINE, HEIGHT, SEVEN, SIX, FIVE, FOUR, THREE, TWO
} }

View File

@ -0,0 +1,2 @@
package fr.aminelouveaau.cartes.model.api;public class SortingResult {
}

View File

@ -18,6 +18,7 @@ public class GameService {
private List<Number> numberOrder; private List<Number> numberOrder;
private Stack<Card> deck = new Stack<>(); private Stack<Card> deck = new Stack<>();
private Comparator<Card> comparator;
@PostConstruct @PostConstruct
public void init() { public void init() {
@ -47,10 +48,13 @@ public class GameService {
} }
private void generateOrders() { private void generateOrders() {
List<Shape> shapeOrder = Arrays.asList(Shape.values()); shapeOrder = Arrays.asList(Shape.values());
Collections.shuffle(shapeOrder); Collections.shuffle(shapeOrder);
List<Number> numberOrder = Arrays.asList(Number.values()); numberOrder = Arrays.asList(Number.values());
Collections.shuffle(numberOrder); Collections.shuffle(numberOrder);
comparator = Comparator.comparing((Card c) -> shapeOrder.indexOf(c.getShape()))
.thenComparing(c -> numberOrder.indexOf(c.getNumber()));
} }
} }