Initial commit with deck creation.
This commit is contained in:
13
src/main/java/fr/aminelouveaau/cartes/CartesApplication.java
Normal file
13
src/main/java/fr/aminelouveaau/cartes/CartesApplication.java
Normal file
@ -0,0 +1,13 @@
|
||||
package fr.aminelouveaau.cartes;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class CartesApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CartesApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
5
src/main/java/fr/aminelouveaau/cartes/model/Number.java
Normal file
5
src/main/java/fr/aminelouveaau/cartes/model/Number.java
Normal file
@ -0,0 +1,5 @@
|
||||
package fr.aminelouveaau.cartes.model;
|
||||
|
||||
public enum Number {
|
||||
ACE, KING, QUEEN, JACK, TEN, NINE, HEIGHT, SEVEN, SIX, FIXE, FOUR, THREE, TWO
|
||||
}
|
5
src/main/java/fr/aminelouveaau/cartes/model/Shape.java
Normal file
5
src/main/java/fr/aminelouveaau/cartes/model/Shape.java
Normal file
@ -0,0 +1,5 @@
|
||||
package fr.aminelouveaau.cartes.model;
|
||||
|
||||
public enum Shape {
|
||||
SPADES, CLUBS, DIMONDS, HEARTS
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
package fr.aminelouveaau.cartes.rest;public class GameResource {
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package fr.aminelouveaau.cartes.service;
|
||||
|
||||
import fr.aminelouveaau.cartes.model.Number;
|
||||
import fr.aminelouveaau.cartes.model.Shape;
|
||||
import javafx.util.Pair;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class GameService {
|
||||
@Value("${cards.hand.number}")
|
||||
private Integer cardHandNumber;
|
||||
|
||||
private List<Shape> shapeOrder;
|
||||
private List<Number> numberOrder;
|
||||
|
||||
private List<Pair<Shape, Number>> deck = new ArrayList<>();
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
generateOrders();
|
||||
createDeck();
|
||||
}
|
||||
|
||||
public List<Shape> getShapeOrder() {
|
||||
return shapeOrder;
|
||||
}
|
||||
|
||||
public List<Number> getNumberOrder() {
|
||||
return numberOrder;
|
||||
}
|
||||
|
||||
public List<Pair<Shape, Number>> getDeck() {
|
||||
return deck;
|
||||
}
|
||||
|
||||
private void createDeck() {
|
||||
Arrays.stream(Shape.values()).forEach(shape -> {
|
||||
Arrays.stream(Number.values()).forEach(number -> {
|
||||
deck.add(new Pair<>(shape, number));
|
||||
});
|
||||
});
|
||||
Collections.shuffle(deck);
|
||||
}
|
||||
|
||||
private void generateOrders() {
|
||||
List<Shape> shapeOrder = Arrays.asList(Shape.values());
|
||||
Collections.shuffle(shapeOrder);
|
||||
List<Number> numberOrder = Arrays.asList(Number.values());
|
||||
Collections.shuffle(numberOrder);
|
||||
}
|
||||
|
||||
}
|
1
src/main/resources/application.properties
Normal file
1
src/main/resources/application.properties
Normal file
@ -0,0 +1 @@
|
||||
cards.hand.number=10
|
@ -0,0 +1,40 @@
|
||||
package fr.aminelouveaau.cartes;
|
||||
|
||||
import fr.aminelouveaau.cartes.model.Number;
|
||||
import fr.aminelouveaau.cartes.model.Shape;
|
||||
import fr.aminelouveaau.cartes.service.GameService;
|
||||
import javafx.util.Pair;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
@SpringBootTest
|
||||
class CartesApplicationTests {
|
||||
|
||||
@InjectMocks
|
||||
GameService gameService;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
ReflectionTestUtils.setField(gameService, "cardHandNumber", 10);
|
||||
gameService.init();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeckGeneration() {
|
||||
List<Pair<Shape, Number>> deck = gameService.getDeck();
|
||||
assertThat(deck.size()).isNotEqualTo(0).withFailMessage("Deck is empty");
|
||||
assertThat(deck.size()).isEqualTo(4 * 13).withFailMessage("Deck is not complete");
|
||||
}
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user