feat: Multiplayer
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
package cz.jzitnik.common.socket.messages.game;
|
||||||
|
|
||||||
|
import cz.jzitnik.common.socket.SocketMessage;
|
||||||
|
|
||||||
|
public record GameWin() implements SocketMessage {
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ import cz.jzitnik.common.models.coordinates.RoomCords;
|
|||||||
import cz.jzitnik.client.utils.events.AbstractEventHandler;
|
import cz.jzitnik.client.utils.events.AbstractEventHandler;
|
||||||
import cz.jzitnik.client.utils.events.EventManager;
|
import cz.jzitnik.client.utils.events.EventManager;
|
||||||
import cz.jzitnik.client.utils.roomtasks.RoomTaskScheduler;
|
import cz.jzitnik.client.utils.roomtasks.RoomTaskScheduler;
|
||||||
|
import cz.jzitnik.common.socket.messages.game.GameWin;
|
||||||
import cz.jzitnik.common.socket.messages.room.MovePlayerRoom;
|
import cz.jzitnik.common.socket.messages.room.MovePlayerRoom;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@@ -72,10 +73,9 @@ public class RoomChangeEventHandler extends AbstractEventHandler<RoomChangeEvent
|
|||||||
|
|
||||||
gameState.setCurrentRoom(newRoom);
|
gameState.setCurrentRoom(newRoom);
|
||||||
if (newRoom.isEnd()) {
|
if (newRoom.isEnd()) {
|
||||||
cz.jzitnik.client.game.setup.scenes.WinScene winScene = new cz.jzitnik.client.game.setup.scenes.WinScene();
|
eventManager.emitEvent(new SendSocketMessageEvent(new GameWin()));
|
||||||
gameState.setScreen(winScene);
|
} else {
|
||||||
winScene.fullRender();
|
|
||||||
}
|
|
||||||
scheduler.schedule(() -> roomTaskScheduler.setupNewSchedulers(newRoom), 200, TimeUnit.MILLISECONDS);
|
scheduler.schedule(() -> roomTaskScheduler.setupNewSchedulers(newRoom), 200, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package cz.jzitnik.client.socket.events;
|
||||||
|
|
||||||
|
import cz.jzitnik.client.annotations.SocketEventHandler;
|
||||||
|
import cz.jzitnik.client.annotations.injectors.InjectDependency;
|
||||||
|
import cz.jzitnik.client.annotations.injectors.InjectState;
|
||||||
|
import cz.jzitnik.client.game.GameState;
|
||||||
|
import cz.jzitnik.client.game.setup.scenes.WinScene;
|
||||||
|
import cz.jzitnik.client.socket.AbstractSocketEventHandler;
|
||||||
|
import cz.jzitnik.common.socket.messages.game.GameWin;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@SocketEventHandler(GameWin.class)
|
||||||
|
public class GameWinHandler extends AbstractSocketEventHandler<GameWin> {
|
||||||
|
@InjectState
|
||||||
|
private GameState gameState;
|
||||||
|
|
||||||
|
@InjectDependency
|
||||||
|
private cz.jzitnik.client.utils.roomtasks.RoomTaskScheduler roomTaskScheduler;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(GameWin event) {
|
||||||
|
log.debug("Game won!");
|
||||||
|
roomTaskScheduler.finalShutdown();
|
||||||
|
WinScene winScene = new WinScene();
|
||||||
|
gameState.setScreen(winScene);
|
||||||
|
winScene.fullRender();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package cz.jzitnik.server.events.handlers;
|
||||||
|
|
||||||
|
import cz.jzitnik.common.socket.messages.game.GameWin;
|
||||||
|
import cz.jzitnik.server.annotations.EventHandler;
|
||||||
|
import cz.jzitnik.server.context.GlobalContext;
|
||||||
|
import cz.jzitnik.server.events.AbstractEventHandler;
|
||||||
|
import cz.jzitnik.server.game.Client;
|
||||||
|
|
||||||
|
@EventHandler(GameWin.class)
|
||||||
|
public class GameWinHandler extends AbstractEventHandler<GameWin> {
|
||||||
|
public GameWinHandler(GlobalContext globalContext) {
|
||||||
|
super(globalContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(GameWin event, Client client) {
|
||||||
|
for (Client player : client.getGame().getPlayers()) {
|
||||||
|
player.getSession().sendMessage(new GameWin());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user