Browse Source

Merge branch 'implementFaceDown' into 'main'

Implement face down

See merge request fdai7736/onses!28
main
fdai7793 11 months ago
parent
commit
6fe522f3c1
  1. 4
      src/main/java/de/hsfulda/onses/models/Game.java
  2. 14
      src/main/java/de/hsfulda/onses/services/GameService.java
  3. 59
      src/test/java/de/hsfulda/onses/GameServiceTest.java

4
src/main/java/de/hsfulda/onses/models/Game.java

@ -31,7 +31,7 @@ public class Game {
} }
public Game setLastPlayedCard(Card lastPlayedCard) { public Game setLastPlayedCard(Card lastPlayedCard) {
final Card oldLastPlayedCard = this.lastPlayedCard; final Card oldLastPlayedCard = this.lastPlayedCard;
this.lastPlayedCard = lastPlayedCard;
this.lastPlayedCard = lastPlayedCard.setFacedown(false);
this.firePropertyChange(PROPERTY_LAST_PLAYED_CARD, oldLastPlayedCard, lastPlayedCard); this.firePropertyChange(PROPERTY_LAST_PLAYED_CARD, oldLastPlayedCard, lastPlayedCard);
return this; return this;
} }
@ -42,7 +42,7 @@ public class Game {
public void addCardToDrawCardDeck(Card card) { public void addCardToDrawCardDeck(Card card) {
final ArrayList<Card> oldCards = new ArrayList<>(this.drawCardDeck); final ArrayList<Card> oldCards = new ArrayList<>(this.drawCardDeck);
drawCardDeck.add(card);
drawCardDeck.add(card.setFacedown(true));
this.firePropertyChange(PROPERTY_DRAW_CARD_DECK, oldCards, drawCardDeck); this.firePropertyChange(PROPERTY_DRAW_CARD_DECK, oldCards, drawCardDeck);
} }

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

@ -45,14 +45,16 @@ public class GameService {
public void drawCard(int amount) { public void drawCard(int amount) {
if (!game.getDrawCardDeck().isEmpty()) { if (!game.getDrawCardDeck().isEmpty()) {
boolean isFaceDown = false;
Player player = null; Player player = null;
if (game.getPlayerService().getCurrentTurn()) { if (game.getPlayerService().getCurrentTurn()) {
player = game.getPlayerService().getPlayerList().getFirst(); player = game.getPlayerService().getPlayerList().getFirst();
} else { } else {
isFaceDown = true;
player = game.getPlayerService().getPlayerList().getLast(); player = game.getPlayerService().getPlayerList().getLast();
} }
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
player.getPlayerDeck().add(game.getDrawCardDeck().getFirst());
player.getPlayerDeck().add(game.getDrawCardDeck().getFirst().setFacedown(isFaceDown));
game.getDrawCardDeck().removeFirst(); game.getDrawCardDeck().removeFirst();
} }
if (amount == 1 && !player.getPlayerDeck().isEmpty()) { if (amount == 1 && !player.getPlayerDeck().isEmpty()) {
@ -75,7 +77,7 @@ public class GameService {
if (lastCard.getValue() == Card.Value.CHOOSE || lastCard.getValue() == Card.Value.CHOOSEDRAW) { if (lastCard.getValue() == Card.Value.CHOOSE || lastCard.getValue() == Card.Value.CHOOSEDRAW) {
lastCard.setColor(Card.Color.BLACK); lastCard.setColor(Card.Color.BLACK);
} }
game.addCardToDrawCardDeck(lastCard);
game.addCardToDrawCardDeck(lastCard.setFacedown(true));
} }
public void chooseColor() { public void chooseColor() {
@ -184,15 +186,15 @@ public class GameService {
for (Card.Color i : Card.Color.values()) { for (Card.Color i : Card.Color.values()) {
for (Card.Value j : Card.Value.values()) { for (Card.Value j : Card.Value.values()) {
if (i != Card.Color.BLACK && j != Card.Value.CHOOSE && j != Card.Value.CHOOSEDRAW) { 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));
game.addCardToDrawCardDeck(new Card().setColor(i).setValue(j).setFacedown(true));
game.addCardToDrawCardDeck(new Card().setColor(i).setValue(j).setFacedown(true));
} }
} }
} }
for (int i = 0; i != 4; i++) { 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));
game.addCardToDrawCardDeck(new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE).setFacedown(true));
game.addCardToDrawCardDeck(new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSEDRAW).setFacedown(true));
} }
} }

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

@ -479,6 +479,65 @@ public class GameServiceTest {
} }
@Test @Test
@DisplayName("CheckIfCardsInDrawCardDeckAreFaceDown")
public void CheckIfCardsInDrawCardDeckAreFaceDown() {
GameService gameService = new GameService();
for (int i = 0; i < gameService.getGame().getDrawCardDeck().size(); i++) {
assertTrue(gameService.getGame().getDrawCardDeck().get(i).isFacedown());
}
}
@Test
@DisplayName("CheckIfCardsInPlayerDeckAreFaceUp")
public void CheckIfCardsInPlayerDeckAreFaceUp() {
GameService gameService = new GameService();
for (int i = 0; i < gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().size(); i++) {
assertFalse(gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().get(i).isFacedown());
}
}
@Test
@DisplayName("CheckIfCardsInBotDeckAreFaceDown")
public void CheckIfCardsInBotDeckAreFaceDown() {
GameService gameService = new GameService();
for (int i = 0; i < gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().size(); i++) {
assertTrue(gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().get(i).isFacedown());
}
}
@Test
@DisplayName("CheckIfCardsPlayedByBotWillTurnFaceUp")
public void CheckIfCardsPlayedByBotWillTurnFaceUp() {
GameService gameService = new GameService();
Card card = new Card().setColor(Card.Color.GREEN).setValue(Card.Value.FOUR).setFacedown(true);
gameService.getGame().getPlayerService().setCurrentTurn(false);
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.GREEN).setValue(Card.Value.FIVE));
gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().clear();
gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().add(card);
gameService.getGame().getPlayerService().botMove();
assertFalse(gameService.getGame().getLastPlayedCard().isFacedown());
}
@Test
@DisplayName("CheckIfCardsMovedToDrawCardDeckWillBeFaceDown")
public void CheckIfCardsMovedToDrawCardDeckWillBeFaceDown() {
GameService gameService = new GameService();
Card card = new Card().setColor(Card.Color.GREEN).setValue(Card.Value.FOUR);
gameService.getGame().setLastPlayedCard(card);
gameService.addLastPlayedCardToDrawCardDeck();
assertTrue(gameService.getGame().getDrawCardDeck().getLast().isFacedown());
}
@DisplayName("PlaySevenPlayerDeckIsNowBotDeck") @DisplayName("PlaySevenPlayerDeckIsNowBotDeck")
public void PlaySevenPlayerDeckIsNowBotDeck() { public void PlaySevenPlayerDeckIsNowBotDeck() {
GameService gameService = new GameService(); GameService gameService = new GameService();

Loading…
Cancel
Save