From 99d3ba2df9ec2c470f2efa23a9ac65f35640fe6b Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Mon, 5 Feb 2024 18:50:36 +0100 Subject: [PATCH] add ChooseColor for Bot --- .../hsfulda/onses/services/GameService.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 1101305..598d19b 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -5,6 +5,7 @@ import de.hsfulda.onses.models.Game; import de.hsfulda.onses.models.Player; import java.util.Collections; +import java.util.Random; public class GameService { private final Game game; @@ -69,6 +70,31 @@ public class GameService { // 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; + } + } } public void checkForWin() {