added sync point after trump determination
parent
c89026c6e1
commit
640443abbc
@ -0,0 +1,53 @@
|
|||||||
|
package eu.jonahbauer.wizard.core.machine.states;
|
||||||
|
|
||||||
|
import eu.jonahbauer.wizard.common.messages.observer.TimeoutMessage;
|
||||||
|
import eu.jonahbauer.wizard.common.messages.observer.UserInputMessage;
|
||||||
|
import eu.jonahbauer.wizard.common.messages.player.ContinueMessage;
|
||||||
|
import eu.jonahbauer.wizard.common.messages.player.PlayerMessage;
|
||||||
|
import eu.jonahbauer.wizard.core.machine.Game;
|
||||||
|
import eu.jonahbauer.wizard.core.machine.GameState;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static eu.jonahbauer.wizard.common.messages.observer.UserInputMessage.Action.SYNC;
|
||||||
|
import static eu.jonahbauer.wizard.core.machine.states.GameData.PLAYERS;
|
||||||
|
|
||||||
|
public abstract class SyncState extends GameState {
|
||||||
|
private final transient Set<UUID> ready = new HashSet<>();
|
||||||
|
|
||||||
|
public SyncState(GameData data) {
|
||||||
|
super(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<GameState> onEnter(Game game) {
|
||||||
|
game.notify(new UserInputMessage(null, SYNC, getSyncTimeout(game, true)));
|
||||||
|
return syncTimeout(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<GameState> onMessage(Game game, UUID player, PlayerMessage message) {
|
||||||
|
if (message instanceof ContinueMessage) {
|
||||||
|
ready.add(player);
|
||||||
|
|
||||||
|
if (ready.size() == get(PLAYERS).size()) {
|
||||||
|
return Optional.of(getNextState());
|
||||||
|
} else {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return super.onMessage(game, player, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<GameState> onTimeout(Game game) {
|
||||||
|
game.notify(new TimeoutMessage());
|
||||||
|
return Optional.of(getNextState());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract GameState getNextState();
|
||||||
|
}
|
@ -1,52 +1,17 @@
|
|||||||
package eu.jonahbauer.wizard.core.machine.states.round;
|
package eu.jonahbauer.wizard.core.machine.states.round;
|
||||||
|
|
||||||
import eu.jonahbauer.wizard.common.messages.observer.TimeoutMessage;
|
|
||||||
import eu.jonahbauer.wizard.common.messages.observer.UserInputMessage;
|
|
||||||
import eu.jonahbauer.wizard.common.messages.player.ContinueMessage;
|
|
||||||
import eu.jonahbauer.wizard.common.messages.player.PlayerMessage;
|
|
||||||
import eu.jonahbauer.wizard.core.machine.Game;
|
|
||||||
import eu.jonahbauer.wizard.core.machine.GameState;
|
import eu.jonahbauer.wizard.core.machine.GameState;
|
||||||
import eu.jonahbauer.wizard.core.machine.states.GameData;
|
import eu.jonahbauer.wizard.core.machine.states.GameData;
|
||||||
|
import eu.jonahbauer.wizard.core.machine.states.SyncState;
|
||||||
|
|
||||||
import java.util.HashSet;
|
public final class StartingRound extends SyncState {
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static eu.jonahbauer.wizard.common.messages.observer.UserInputMessage.Action.SYNC;
|
|
||||||
import static eu.jonahbauer.wizard.core.machine.states.GameData.PLAYERS;
|
|
||||||
|
|
||||||
public final class StartingRound extends RoundState {
|
|
||||||
private final transient Set<UUID> ready = new HashSet<>();
|
|
||||||
|
|
||||||
public StartingRound(GameData data) {
|
public StartingRound(GameData data) {
|
||||||
super(data);
|
super(RoundState.requirements(data));
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<GameState> onEnter(Game game) {
|
|
||||||
game.notify(new UserInputMessage(null, SYNC, getSyncTimeout(game, true)));
|
|
||||||
return syncTimeout(game);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<GameState> onMessage(Game game, UUID player, PlayerMessage message) {
|
|
||||||
if (message instanceof ContinueMessage) {
|
|
||||||
ready.add(player);
|
|
||||||
|
|
||||||
if (ready.size() == get(PLAYERS).size()) {
|
|
||||||
return Optional.of(new Dealing(getData()));
|
|
||||||
} else {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return super.onMessage(game, player, message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<GameState> onTimeout(Game game) {
|
protected GameState getNextState() {
|
||||||
game.notify(new TimeoutMessage());
|
return new Dealing(getData());
|
||||||
return Optional.of(new Dealing(getData()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package eu.jonahbauer.wizard.core.machine.states.round;
|
||||||
|
|
||||||
|
import eu.jonahbauer.wizard.core.machine.GameState;
|
||||||
|
import eu.jonahbauer.wizard.core.machine.states.GameData;
|
||||||
|
import eu.jonahbauer.wizard.core.machine.states.SyncState;
|
||||||
|
|
||||||
|
import static eu.jonahbauer.wizard.core.machine.states.GameData.*;
|
||||||
|
|
||||||
|
public final class TrumpDetermined extends SyncState {
|
||||||
|
|
||||||
|
public TrumpDetermined(GameData data) {
|
||||||
|
super(RoundState.requirements(data).requireEach(PLAYERS, HANDS).require(PREDICTIONS, TRUMP_SUIT, CURRENT_PLAYER));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GameState getNextState() {
|
||||||
|
return new Predicting(getData());
|
||||||
|
}
|
||||||
|
}
|
@ -1,52 +1,18 @@
|
|||||||
package eu.jonahbauer.wizard.core.machine.states.trick;
|
package eu.jonahbauer.wizard.core.machine.states.trick;
|
||||||
|
|
||||||
import eu.jonahbauer.wizard.common.messages.observer.TimeoutMessage;
|
|
||||||
import eu.jonahbauer.wizard.common.messages.observer.UserInputMessage;
|
|
||||||
import eu.jonahbauer.wizard.common.messages.player.ContinueMessage;
|
|
||||||
import eu.jonahbauer.wizard.common.messages.player.PlayerMessage;
|
|
||||||
import eu.jonahbauer.wizard.core.machine.Game;
|
|
||||||
import eu.jonahbauer.wizard.core.machine.states.GameData;
|
|
||||||
import eu.jonahbauer.wizard.core.machine.GameState;
|
import eu.jonahbauer.wizard.core.machine.GameState;
|
||||||
|
import eu.jonahbauer.wizard.core.machine.states.GameData;
|
||||||
|
import eu.jonahbauer.wizard.core.machine.states.SyncState;
|
||||||
|
import eu.jonahbauer.wizard.core.machine.states.round.RoundState;
|
||||||
|
|
||||||
import java.util.HashSet;
|
public final class StartingTrick extends SyncState {
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static eu.jonahbauer.wizard.common.messages.observer.UserInputMessage.Action.SYNC;
|
|
||||||
import static eu.jonahbauer.wizard.core.machine.states.GameData.PLAYERS;
|
|
||||||
|
|
||||||
public final class StartingTrick extends TrickState {
|
|
||||||
private final transient Set<UUID> ready = new HashSet<>();
|
|
||||||
|
|
||||||
public StartingTrick(GameData data) {
|
public StartingTrick(GameData data) {
|
||||||
super(data);
|
super(RoundState.requirements(TrickState.requirements(data)));
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<GameState> onEnter(Game game) {
|
|
||||||
game.notify(new UserInputMessage(null, SYNC, getSyncTimeout(game, true)));
|
|
||||||
return syncTimeout(game);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<GameState> onMessage(Game game, UUID player, PlayerMessage message) {
|
|
||||||
if (message instanceof ContinueMessage) {
|
|
||||||
ready.add(player);
|
|
||||||
|
|
||||||
if (ready.size() == get(PLAYERS).size()) {
|
|
||||||
return Optional.of(new PlayingCard(getData()));
|
|
||||||
} else {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return super.onMessage(game, player, message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<GameState> onTimeout(Game game) {
|
protected GameState getNextState() {
|
||||||
game.notify(new TimeoutMessage());
|
return new PlayingCard(getData());
|
||||||
return Optional.of(new PlayingCard(getData()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue