added sync at start of round and trick
parent
421cae2ace
commit
10ca1ac9db
@ -1,4 +1,7 @@
|
|||||||
package eu.jonahbauer.wizard.common.messages.observer;
|
package eu.jonahbauer.wizard.common.messages.observer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link TimeoutMessage} is sent when an user input times out.
|
||||||
|
*/
|
||||||
public final class TimeoutMessage extends ObserverMessage {
|
public final class TimeoutMessage extends ObserverMessage {
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
package eu.jonahbauer.wizard.common.messages.player;
|
||||||
|
|
||||||
|
public final class ContinueMessage extends PlayerMessage {
|
||||||
|
}
|
@ -1,18 +1,52 @@
|
|||||||
package eu.jonahbauer.wizard.core.machine.states.round;
|
package eu.jonahbauer.wizard.core.machine.states.round;
|
||||||
|
|
||||||
import eu.jonahbauer.wizard.core.machine.states.GameData;
|
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.Game;
|
||||||
import eu.jonahbauer.wizard.core.machine.GameState;
|
import eu.jonahbauer.wizard.core.machine.GameState;
|
||||||
|
import eu.jonahbauer.wizard.core.machine.states.GameData;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Optional;
|
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 {
|
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(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<GameState> onEnter(Game game) {
|
public Optional<GameState> onEnter(Game game) {
|
||||||
return transition(new Dealing(getData()));
|
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
|
||||||
|
public Optional<GameState> onTimeout(Game game) {
|
||||||
|
game.notify(new TimeoutMessage());
|
||||||
|
return Optional.of(new Dealing(getData()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,52 @@
|
|||||||
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.Game;
|
||||||
import eu.jonahbauer.wizard.core.machine.states.GameData;
|
import eu.jonahbauer.wizard.core.machine.states.GameData;
|
||||||
import eu.jonahbauer.wizard.core.machine.GameState;
|
import eu.jonahbauer.wizard.core.machine.GameState;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Optional;
|
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 {
|
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(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<GameState> onEnter(Game game) {
|
public Optional<GameState> onEnter(Game game) {
|
||||||
return transition(new PlayingCard(getData()));
|
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
|
||||||
|
public Optional<GameState> onTimeout(Game game) {
|
||||||
|
game.notify(new TimeoutMessage());
|
||||||
|
return Optional.of(new PlayingCard(getData()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue