Browse Source

Merge branch 'newFeatures' into 'main'

New features

See merge request fdai7736/onses!26
main
fdai7906 11 months ago
parent
commit
be4e41801b
  1. 30
      src/main/java/de/hsfulda/onses/models/Player.java
  2. 17
      src/main/java/de/hsfulda/onses/services/GameService.java
  3. 32
      src/test/java/de/hsfulda/onses/GameServiceTest.java
  4. 38
      src/test/java/de/hsfulda/onses/PlayerTest.java

30
src/main/java/de/hsfulda/onses/models/Player.java

@ -12,6 +12,9 @@ public class Player {
private PlayerService playerService;
private Game game;
private String playerName;
private boolean enemy;
private Card currentCard;
private final ArrayList<Card> playerDeck = new ArrayList<>();
public ArrayList<Card> getPlayerDeck() {
@ -42,6 +45,33 @@ public class Player {
return this;
}
public String getPlayerName() {
return playerName;
}
public Player setPlayerName(String playerName) {
this.playerName = playerName;
return this;
}
public boolean isEnemy() {
return enemy;
}
public Player setEnemy(boolean enemy) {
this.enemy = enemy;
return this;
}
public Card getCurrentCard() {
return currentCard;
}
public Player setCurrentCard(Card currentCard) {
this.currentCard = currentCard;
return this;
}
public PropertyChangeSupport listeners() {
if(this.listeners == null) {
this.listeners = new PropertyChangeSupport(this);

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

@ -4,6 +4,7 @@ import de.hsfulda.onses.models.Card;
import de.hsfulda.onses.models.Game;
import de.hsfulda.onses.models.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
@ -23,6 +24,7 @@ public class GameService {
public GameService(Game game) {
this.game = game;
this.game.setGameService(this);
this.game.getPlayerService().getPlayerList().getLast().setEnemy(true);
fillDrawDeck();
shuffleDeck();
setFirstCard();
@ -107,6 +109,21 @@ public class GameService {
}
}
public void playSeven() {
ArrayList<Card> übergangBot = new ArrayList<>(game.getPlayerService().getPlayerList().getLast().getPlayerDeck());
ArrayList<Card> übergangSpieler = new ArrayList<>(game.getPlayerService().getPlayerList().getFirst().getPlayerDeck());
game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().clear();
for (int i = 0; i < übergangBot.size(); i++) {
game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().add(übergangBot.get(i));
}
game.getPlayerService().getPlayerList().getLast().getPlayerDeck().clear();
for (int i = 0; i < übergangSpieler.size(); i++) {
game.getPlayerService().getPlayerList().getLast().getPlayerDeck().add(übergangSpieler.get(i));
}
}
public void checkForWin() {
if (this.game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().isEmpty() || this.game.getPlayerService().getPlayerList().getLast().getPlayerDeck().isEmpty()) {
this.game.setGameOver(true);

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

@ -1,6 +1,7 @@
package de.hsfulda.onses;
import com.sun.jdi.ArrayReference;
import de.hsfulda.onses.models.Game;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@ -11,6 +12,8 @@ import de.hsfulda.onses.models.Card;
import de.hsfulda.onses.models.Player;
import de.hsfulda.onses.services.GameService;
import java.util.ArrayList;
public class GameServiceTest {
@Test
@DisplayName("playCardRedEight")
@ -474,4 +477,33 @@ public class GameServiceTest {
assertTrue(answer);
}
@Test
@DisplayName("PlaySevenPlayerDeckIsNowBotDeck")
public void PlaySevenPlayerDeckIsNowBotDeck() {
GameService gameService = new GameService();
ArrayList<Card> botDeck = new ArrayList<>(gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck());
gameService.playSeven();
ArrayList<Card> answer = new ArrayList<>(gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck());
assertEquals(botDeck, answer);
}
@Test
@DisplayName("PlaySevenBotDeckIsNowPlayerDeck")
public void PlaySevenBotDeckIsNowPlayerDeck() {
GameService gameService = new GameService();
ArrayList<Card> playerDeck = new ArrayList<>(gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck());
gameService.playSeven();
ArrayList<Card> answer = new ArrayList<>(gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck());
assertEquals(playerDeck, answer);
}
@Test
@DisplayName("BotisEnemy")
public void botIsEnemy() {
GameService gameService = new GameService();
boolean answer = gameService.getGame().getPlayerService().getPlayerList().getLast().isEnemy();
boolean expected = true;
assertEquals(expected, answer);
}
}

38
src/test/java/de/hsfulda/onses/PlayerTest.java

@ -58,4 +58,42 @@ public class PlayerTest {
assertEquals(expected, answer1);
assertEquals(expected, answer2);
}
@Test
@DisplayName("GivePlayerName")
public void GivePlayerName() {
Player player = new Player();
String expected = "Spieler";
player.setPlayerName(expected);
String answer = player.getPlayerName();
assertEquals(expected, answer);
}
@Test
@DisplayName("ChangePlayerName")
public void ChangePlayerName() {
PlayerService playerService = new PlayerService();
String name1 = "Name1";
String name2 = "Name2";
playerService.getPlayerList().getFirst().setPlayerName(name1);
playerService.getPlayerList().getFirst().setPlayerName(name2);
String answer = playerService.getPlayerList().getFirst().getPlayerName();
assertEquals(name2, answer);
}
@Test
@DisplayName("BotIsEnemy")
public void BotIsEnemy() {
Player player = new Player();
player.setEnemy(true);
assertTrue(player.isEnemy());
}
@Test
@DisplayName("CurrentCard")
public void CurrentCard() {
Player player = new Player();
Card card = new Card().setValue(Card.Value.ONE).setColor(Card.Color.GREEN);
player.setCurrentCard(card);
assertEquals(card, player.getCurrentCard());
}
}
Loading…
Cancel
Save