Browse Source

Merge branch 'AddDeckFunktion' into 'main'

Add deck funktion

See merge request fdai7736/onses!14
main
fdai7906 11 months ago
parent
commit
d7041499c1
  1. 22
      src/main/java/de/hsfulda/onses/services/GameService.java
  2. 34
      src/test/java/de/hsfulda/onses/GameServiceTest.java

22
src/main/java/de/hsfulda/onses/services/GameService.java

@ -4,6 +4,8 @@ import de.hsfulda.onses.models.Card;
import de.hsfulda.onses.models.Game;
import de.hsfulda.onses.models.Player;
import java.util.Collections;
public class GameService {
private final Game game;
public GameService(Game game) {
@ -34,4 +36,24 @@ public class GameService {
return legalMoveFound;
}
public void fillDrawDeck() {
for (Card.Color i : Card.Color.values()){
for (Card.Value j : Card.Value.values()){
if (i != Card.Color.BLACK && j != Card.Value.CHOOSE && j != Card.Value.CHOOSEDRAW){
game.addCardToDrawCardDeck(new Card().setColor(i).setValue(j));
game.addCardToDrawCardDeck(new Card().setColor(i).setValue(j));
}
}
}
for (int i = 0; i != 4; i++){
game.addCardToDrawCardDeck(new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE));
game.addCardToDrawCardDeck(new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSEDRAW));
}
}
public void shuffleDeck() {
Collections.shuffle(game.getDrawCardDeck());
}
}

34
src/test/java/de/hsfulda/onses/GameServiceTest.java

@ -1,6 +1,7 @@
package de.hsfulda.onses;
import de.hsfulda.onses.models.Game;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
@ -63,5 +64,38 @@ public class GameServiceTest {
// assert
assertEquals(expected, answer);
}
@Test
@DisplayName("FillDrawCardDeck")
public void FillDrawCardDeck() {
GameService gameService = new GameService();
int expected = 112;
gameService.fillDrawDeck();
int answer = gameService.getGame().getDrawCardDeck().size();
assertEquals(expected, answer);
}
@Test
@DisplayName("ShuffelDeck")
public void ShuffelDeck() {
GameService shuffled = new GameService();
GameService notshuffled = new GameService();
shuffled.fillDrawDeck();
notshuffled.fillDrawDeck();
shuffled.shuffleDeck();
int counter = 0;
for (int i = 0; i < notshuffled.getGame().getDrawCardDeck().size(); i++) {
if (shuffled.getGame().getDrawCardDeck().get(i).getValue() == notshuffled.getGame().getDrawCardDeck().get(i).getValue() &&
shuffled.getGame().getDrawCardDeck().get(i).getColor() == notshuffled.getGame().getDrawCardDeck().get(i).getColor()) {
counter ++;
}
if (counter == notshuffled.getGame().getDrawCardDeck().size()) {
fail("Deck wurde nicht richtig gemischt");
}
}
}
}
Loading…
Cancel
Save