Browse Source

final fixes and removing outdated stuff

main^2
fdai7920 11 months ago
parent
commit
9087a8d495
  1. 50
      src/main/java/de/hsfulda/onses/services/GameService.java
  2. 24
      src/main/java/de/hsfulda/onses/services/PlayerService.java
  3. 89
      src/test/java/de/hsfulda/onses/GameServiceTest.java

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

@ -59,17 +59,11 @@ public class GameService {
game.getDrawCardDeck().removeFirst(); game.getDrawCardDeck().removeFirst();
} }
if (amount == 1 && !player.getPlayerDeck().isEmpty()) { if (amount == 1 && !player.getPlayerDeck().isEmpty()) {
Card drawnCard = player.getPlayerDeck().getLast();
if (legalMove(drawnCard)) {
player.getPlayerService().removeCardFromPlayerDeck(drawnCard);
playCard(drawnCard);
}
else nextPlayer();
game.getPlayerService().botMove();
nextPlayer();
if (!game.getPlayerService().getCurrentTurn()) game.getPlayerService().botMove();
} }
} }
if (amount != 1) {
if (amount == 7) {
nextPlayer(); nextPlayer();
} }
} }
@ -84,32 +78,9 @@ public class GameService {
public void chooseColor() { public void chooseColor() {
// Abfrage Farbe // Abfrage Farbe
Card.Color color = Card.Color.BLUE; //Vorübergehend Blau
game.changeLastPlayedCardColor(color);
if (!game.getPlayerService().getCurrentTurn()){
int min = 0;
int max = 3;
Random rand = new Random();
int randomNum = rand.nextInt((max - min) + 1) + min;
switch (randomNum){
case 0:
color = Card.Color.BLUE;
game.changeLastPlayedCardColor(color);
break;
case 1:
color = Card.Color.RED;
game.changeLastPlayedCardColor(color);
break;
case 2:
color = Card.Color.YELLOW;
game.changeLastPlayedCardColor(color);
break;
case 3:
color = Card.Color.GREEN;
game.changeLastPlayedCardColor(color);
break;
}
if (game.getPlayerService().getCurrentTurn()) {
Card.Color color = Card.Color.BLUE; //Vorübergehend Blau
game.changeLastPlayedCardColor(color);
} }
} }
@ -130,7 +101,10 @@ public class GameService {
public void checkForWin() { public void checkForWin() {
if (this.game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().isEmpty() || this.game.getPlayerService().getPlayerList().getLast().getPlayerDeck().isEmpty()) { if (this.game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().isEmpty() || this.game.getPlayerService().getPlayerList().getLast().getPlayerDeck().isEmpty()) {
System.out.println("gameOver");
System.out.println(game.getGameOver());
this.game.setGameOver(true); this.game.setGameOver(true);
System.out.println(game.getGameOver());
} }
} }
@ -150,11 +124,11 @@ public class GameService {
nextPlayer(); nextPlayer();
break; break;
case CHOOSE: case CHOOSE:
chooseColor();
//chooseColor();
nextPlayer(); nextPlayer();
break; break;
case CHOOSEDRAW: case CHOOSEDRAW:
chooseColor();
//chooseColor();
nextPlayer(); nextPlayer();
drawCard(4); drawCard(4);
break; break;
@ -182,8 +156,6 @@ public class GameService {
if (card.getValue() == lastCard.getValue()) legalMoveFound = true; // same value if (card.getValue() == lastCard.getValue()) legalMoveFound = true; // same value
if (card.getColor() == Card.Color.BLACK) legalMoveFound = true; // Color Black
return legalMoveFound; return legalMoveFound;
} }

24
src/main/java/de/hsfulda/onses/services/PlayerService.java

@ -6,6 +6,7 @@ import de.hsfulda.onses.models.Card;
import de.hsfulda.onses.services.GameService; import de.hsfulda.onses.services.GameService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random;
public class PlayerService { public class PlayerService {
@ -66,11 +67,32 @@ public class PlayerService {
if (getGame().getGameService().legalMove(this.playerList.getLast().getPlayerDeck().get(i))) { if (getGame().getGameService().legalMove(this.playerList.getLast().getPlayerDeck().get(i))) {
Card playCard = this.playerList.getLast().getPlayerDeck().get(i); Card playCard = this.playerList.getLast().getPlayerDeck().get(i);
this.removeCardFromPlayerDeck(playCard); this.removeCardFromPlayerDeck(playCard);
if (playCard.getValue() == Card.Value.CHOOSE || playCard.getValue() == Card.Value.CHOOSEDRAW)
{
int min = 0;
int max = 3;
Random rand = new Random();
int randomNum = rand.nextInt((max - min) + 1) + min;
switch (randomNum){
case 0:
playCard.setColor(Card.Color.BLUE);
break;
case 1:
playCard.setColor(Card.Color.RED);
break;
case 2:
playCard.setColor(Card.Color.YELLOW);
break;
case 3:
playCard.setColor(Card.Color.GREEN);
break;
}
}
getGame().getGameService().playCard(playCard); getGame().getGameService().playCard(playCard);
break; break;
} }
} }
if (lastPlayedCard == game.getLastPlayedCard()) {
if (lastPlayedCard == game.getLastPlayedCard() && !playerList.getLast().getPlayerDeck().isEmpty()) {
game.getGameService().drawCard(1); game.getGameService().drawCard(1);
} }
} }

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

@ -1,4 +1,3 @@
package de.hsfulda.onses; package de.hsfulda.onses;
import com.sun.jdi.ArrayReference; import com.sun.jdi.ArrayReference;
@ -120,37 +119,6 @@ public class GameServiceTest {
assertEquals(expected, answer); assertEquals(expected, answer);
} }
@Test
@DisplayName("legalMoveColorBlack")
public void legalMoveColorBlack() {
// arrange
Card input = new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE);
boolean expected = true;
// act
GameService gameService = new GameService();
gameService.setTest(true);
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.THREE));
boolean answer = gameService.legalMove(input);
// assert
assertEquals(expected, answer);
}
@Test
@DisplayName("legalMoveColorBlackCHOOSEDRAW")
public void legalMoveColorBlackCHOOSEDRAW() {
// arrange
Card input = new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSEDRAW);
boolean expected = true;
// act
GameService gameService = new GameService();
gameService.setTest(true);
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.GREEN).setValue(Card.Value.FIVE));
boolean answer = gameService.legalMove(input);
// assert
assertEquals(expected, answer);
}
@Test @Test
@DisplayName("ShuffelDeck") @DisplayName("ShuffelDeck")
@ -225,41 +193,6 @@ public class GameServiceTest {
assertEquals(expected, gameService.getGame().getPlayerService().getCurrentTurn()); assertEquals(expected, gameService.getGame().getPlayerService().getCurrentTurn());
} }
@Test
@DisplayName("ChooseTest")
public void ChooseTest() {
GameService gameService = new GameService();
gameService.setTest(true);
boolean expected = true;
boolean answer = false;
gameService.playCard(new Card().setValue(Card.Value.CHOOSE).setColor(Card.Color.BLACK));
if (gameService.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) {
answer = true;
}
assertEquals(expected, answer);
}
@Test
@DisplayName("ChooseDrawTest")
public void ChooseDrawTest() {
GameService gameService = new GameService();
gameService.setTest(true);
boolean expected = true;
boolean answer = false;
gameService.playCard(new Card().setValue(Card.Value.CHOOSEDRAW).setColor(Card.Color.BLACK));
if (gameService.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) {
answer = true;
}
assertEquals(expected, answer);
}
@Test @Test
@DisplayName("DrawByChoiceForceKeep") @DisplayName("DrawByChoiceForceKeep")
public void DrawByChoiceForceKeep() { public void DrawByChoiceForceKeep() {
@ -323,26 +256,6 @@ public class GameServiceTest {
assertEquals(expected, answer); assertEquals(expected, answer);
} }
@Test
@DisplayName("DrawByChoiceForcePlay")
public void DrawByChoiceForcePlay() {
GameService gameService = new GameService();
gameService.setTest(true);
Card input = new Card().setColor(Card.Color.RED).setValue(Card.Value.ONE);
gameService.getGame().getDrawCardDeck().clear();
gameService.getGame().getPlayerService().setCurrentTurn(true);
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.RED).setValue(Card.Value.SEVEN));
gameService.getGame().addCardToDrawCardDeck(input);
gameService.getGame().getPlayerService().getPlayerList().getFirst().addCardToPlayerDeck(new Card().setColor(Card.Color.BLUE).setValue(Card.Value.TWO));
gameService.drawCard(1);
Card answer = gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().getLast();
assertNotEquals(input, answer);
}
@Test @Test
@DisplayName("CheckThatBotDeckHasSevenCardsAfterGameStart") @DisplayName("CheckThatBotDeckHasSevenCardsAfterGameStart")
public void CheckThatBotDeckHasSevenCardsAfterGameStart() { public void CheckThatBotDeckHasSevenCardsAfterGameStart() {
@ -436,7 +349,7 @@ public class GameServiceTest {
gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().add(card); gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().add(card);
gameService.getGame().getPlayerService().setCurrentTurn(false); gameService.getGame().getPlayerService().setCurrentTurn(false);
gameService.playCard(card);
gameService.getGame().getPlayerService().botMove();
if (gameService.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK){ if (gameService.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK){
answer = true; answer = true;

Loading…
Cancel
Save