|
|
|
@ -27,6 +27,7 @@ public final class Game extends BaseState {
|
|
|
|
|
private int round = -1;
|
|
|
|
|
private final Map<UUID, Integer> predictions = new HashMap<>();
|
|
|
|
|
private final Map<UUID, List<Card>> hands = new HashMap<>();
|
|
|
|
|
private final Map<UUID, List<List<Card>>> tricks = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
private int trick = -1;
|
|
|
|
|
private final List<Pair<UUID, Card>> stack = new ArrayList<>();
|
|
|
|
@ -49,6 +50,7 @@ public final class Game extends BaseState {
|
|
|
|
|
case "starting_round" -> {
|
|
|
|
|
client.printfln("Round %d is starting...", ++round);
|
|
|
|
|
predictions.clear();
|
|
|
|
|
tricks.clear();
|
|
|
|
|
trumpSuit = null;
|
|
|
|
|
trumpCard = null;
|
|
|
|
|
stack.clear();
|
|
|
|
@ -91,12 +93,21 @@ public final class Game extends BaseState {
|
|
|
|
|
}
|
|
|
|
|
} else if (observerMessage instanceof TrickMessage trick) {
|
|
|
|
|
this.stack.clear();
|
|
|
|
|
this.tricks.computeIfAbsent(trick.getPlayer(), player -> new ArrayList<>())
|
|
|
|
|
.add(trick.getCards());
|
|
|
|
|
client.printfln("This trick %s goes to %s.", trick.getCards(), nameOf(trick.getPlayer()));
|
|
|
|
|
} else if (observerMessage instanceof CardMessage card) {
|
|
|
|
|
this.stack.add(Pair.of(card.getPlayer(), card.getCard()));
|
|
|
|
|
|
|
|
|
|
var hand = this.hands.get(card.getPlayer());
|
|
|
|
|
if (hand != null) hand.remove(card.getCard());
|
|
|
|
|
if (hand != null) {
|
|
|
|
|
switch (card.getCard()) {
|
|
|
|
|
case CHANGELING_JESTER, CHANGELING_WIZARD -> hand.remove(Card.CHANGELING);
|
|
|
|
|
case JUGGLER_BLUE, JUGGLER_GREEN, JUGGLER_RED, JUGGLER_YELLOW -> hand.remove(Card.JUGGLER);
|
|
|
|
|
case CLOUD_BLUE, CLOUD_GREEN, CLOUD_RED, CLOUD_YELLOW -> hand.remove(Card.CLOUD);
|
|
|
|
|
default -> hand.remove(card.getCard());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (card.getPlayer().equals(self)) {
|
|
|
|
|
client.printfln("You played %s.", card.getCard());
|
|
|
|
@ -105,11 +116,20 @@ public final class Game extends BaseState {
|
|
|
|
|
}
|
|
|
|
|
} else if (observerMessage instanceof ScoreMessage score) {
|
|
|
|
|
score.getPoints().forEach((player, points) -> scores.merge(player, points, Integer::sum));
|
|
|
|
|
StringBuilder builder = new StringBuilder("The scores are as follows:\n");
|
|
|
|
|
scores.forEach((player, points) -> builder.append(nameOf(player)).append('\t').append(points).append('\n'));
|
|
|
|
|
client.println(builder.toString());
|
|
|
|
|
|
|
|
|
|
String[] col0 = new String[players.size()];
|
|
|
|
|
String[] col1 = new String[players.size()];
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (UUID player : players.keySet()) {
|
|
|
|
|
col0[i] = nameOf(player);
|
|
|
|
|
col1[i] = Objects.toString(scores.getOrDefault(player, 0));
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
client.print("The scores are as follows:", "", col0, col1);
|
|
|
|
|
} else if (observerMessage instanceof UserInputMessage input) {
|
|
|
|
|
if (input.getPlayer().equals(self)) {
|
|
|
|
|
if (self.equals(input.getPlayer())) {
|
|
|
|
|
client.printfln("It is your turn to %s. You have time until %s.", switch (input.getAction()) {
|
|
|
|
|
case CHANGE_PREDICTION -> "change your prediction";
|
|
|
|
|
case JUGGLE_CARD -> "juggle a card";
|
|
|
|
@ -135,8 +155,12 @@ public final class Game extends BaseState {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String nameOf(UUID player) {
|
|
|
|
|
if (player == null) {
|
|
|
|
|
return "all players";
|
|
|
|
|
} else {
|
|
|
|
|
return players.get(player);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Object getCommand() {
|
|
|
|
|