Compare commits
3 Commits
f8f150cdf0
...
3dd2c389b8
| Author | SHA1 | Date | |
|---|---|---|---|
|
3dd2c389b8
|
|||
|
f7d878f430
|
|||
|
32f8521951
|
@@ -0,0 +1,6 @@
|
||||
package cz.jzitnik.common.socket.messages.game;
|
||||
|
||||
import cz.jzitnik.common.socket.SocketMessage;
|
||||
|
||||
public record GameWin() implements SocketMessage {
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package cz.jzitnik.common.socket.messages.game;
|
||||
|
||||
import cz.jzitnik.common.socket.SocketMessage;
|
||||
|
||||
public record PlayerDeath(int playerId) 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.EventManager;
|
||||
import cz.jzitnik.client.utils.roomtasks.RoomTaskScheduler;
|
||||
import cz.jzitnik.common.socket.messages.game.GameWin;
|
||||
import cz.jzitnik.common.socket.messages.room.MovePlayerRoom;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -71,6 +72,10 @@ public class RoomChangeEventHandler extends AbstractEventHandler<RoomChangeEvent
|
||||
eventManager.emitEvent(new SendSocketMessageEvent(new MovePlayerRoom(newRoom.getId(), oldCords, playerCords)));
|
||||
|
||||
gameState.setCurrentRoom(newRoom);
|
||||
scheduler.schedule(() -> roomTaskScheduler.setupNewSchedulers(newRoom), 200, TimeUnit.MILLISECONDS);
|
||||
if (newRoom.isEnd()) {
|
||||
eventManager.emitEvent(new SendSocketMessageEvent(new GameWin()));
|
||||
} else {
|
||||
scheduler.schedule(() -> roomTaskScheduler.setupNewSchedulers(newRoom), 200, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,9 @@ public class GameRoom {
|
||||
@JsonProperty("requirement")
|
||||
private Requirement requirement;
|
||||
|
||||
@JsonProperty("end")
|
||||
private boolean end;
|
||||
|
||||
private GameRoom left;
|
||||
private GameRoom right;
|
||||
private GameRoom up;
|
||||
|
||||
@@ -64,6 +64,8 @@ public class Player implements GamePlayer {
|
||||
public boolean dealDamage(int amount, DependencyManager dependencyManager) {
|
||||
if (health - amount <= 0) {
|
||||
health = 0;
|
||||
EventManager eventManager = dependencyManager.getDependencyOrThrow(EventManager.class);
|
||||
eventManager.emitEvent(new cz.jzitnik.client.events.SendSocketMessageEvent(new cz.jzitnik.common.socket.messages.game.PlayerDeath(id)));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package cz.jzitnik.client.game.setup.scenes;
|
||||
|
||||
import cz.jzitnik.client.screens.DeathScreen;
|
||||
import cz.jzitnik.client.screens.Screen;
|
||||
import cz.jzitnik.client.screens.scenes.Scene;
|
||||
|
||||
public class DeathScene extends Scene {
|
||||
public DeathScene() {
|
||||
super(new Screen[]{new DeathScreen()}, new OnEndAction.Repeat());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package cz.jzitnik.client.game.setup.scenes;
|
||||
|
||||
import cz.jzitnik.client.screens.WinScreen;
|
||||
import cz.jzitnik.client.screens.Screen;
|
||||
import cz.jzitnik.client.screens.scenes.Scene;
|
||||
|
||||
public class WinScene extends Scene {
|
||||
public WinScene() {
|
||||
super(new Screen[]{new WinScreen()}, new OnEndAction.Repeat());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package cz.jzitnik.client.screens;
|
||||
|
||||
import com.googlecode.lanterna.SGR;
|
||||
import com.googlecode.lanterna.TextColor;
|
||||
import com.googlecode.lanterna.graphics.TextGraphics;
|
||||
import com.googlecode.lanterna.screen.TerminalScreen;
|
||||
import cz.jzitnik.client.annotations.injectors.InjectState;
|
||||
import cz.jzitnik.client.events.KeyboardPressEvent;
|
||||
import cz.jzitnik.client.events.MouseAction;
|
||||
import cz.jzitnik.client.states.TerminalState;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DeathScreen extends Screen {
|
||||
@InjectState
|
||||
private TerminalState terminalState;
|
||||
|
||||
@Override
|
||||
public void fullRender() {
|
||||
TerminalScreen screen = terminalState.getTerminalScreen();
|
||||
screen.clear();
|
||||
TextGraphics tg = terminalState.getTextGraphics();
|
||||
|
||||
int termWidth = screen.getTerminalSize().getColumns();
|
||||
int termHeight = screen.getTerminalSize().getRows();
|
||||
|
||||
String message = "GAME OVER";
|
||||
tg.setForegroundColor(TextColor.ANSI.RED);
|
||||
tg.enableModifiers(SGR.BOLD);
|
||||
tg.putString((termWidth - message.length()) / 2, termHeight / 2, message);
|
||||
|
||||
try {
|
||||
screen.refresh(com.googlecode.lanterna.screen.Screen.RefreshType.COMPLETE);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseAction(MouseAction event) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleKeyboardAction(KeyboardPressEvent event) {
|
||||
}
|
||||
}
|
||||
46
game/src/main/java/cz/jzitnik/client/screens/WinScreen.java
Normal file
46
game/src/main/java/cz/jzitnik/client/screens/WinScreen.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package cz.jzitnik.client.screens;
|
||||
|
||||
import com.googlecode.lanterna.SGR;
|
||||
import com.googlecode.lanterna.TextColor;
|
||||
import com.googlecode.lanterna.graphics.TextGraphics;
|
||||
import com.googlecode.lanterna.screen.TerminalScreen;
|
||||
import cz.jzitnik.client.annotations.injectors.InjectState;
|
||||
import cz.jzitnik.client.events.KeyboardPressEvent;
|
||||
import cz.jzitnik.client.events.MouseAction;
|
||||
import cz.jzitnik.client.states.TerminalState;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class WinScreen extends Screen {
|
||||
@InjectState
|
||||
private TerminalState terminalState;
|
||||
|
||||
@Override
|
||||
public void fullRender() {
|
||||
TerminalScreen screen = terminalState.getTerminalScreen();
|
||||
screen.clear();
|
||||
TextGraphics tg = terminalState.getTextGraphics();
|
||||
|
||||
int termWidth = screen.getTerminalSize().getColumns();
|
||||
int termHeight = screen.getTerminalSize().getRows();
|
||||
|
||||
String message = "YOU WON!";
|
||||
tg.setForegroundColor(TextColor.ANSI.GREEN);
|
||||
tg.enableModifiers(SGR.BOLD);
|
||||
tg.putString((termWidth - message.length()) / 2, termHeight / 2, message);
|
||||
|
||||
try {
|
||||
screen.refresh(com.googlecode.lanterna.screen.Screen.RefreshType.COMPLETE);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseAction(MouseAction event) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleKeyboardAction(KeyboardPressEvent event) {
|
||||
}
|
||||
}
|
||||
@@ -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,34 @@
|
||||
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.DeathScene;
|
||||
import cz.jzitnik.client.socket.AbstractSocketEventHandler;
|
||||
import cz.jzitnik.client.utils.DependencyManager;
|
||||
import cz.jzitnik.common.socket.messages.game.PlayerDeath;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@SocketEventHandler(PlayerDeath.class)
|
||||
public class PlayerDeathHandler extends AbstractSocketEventHandler<PlayerDeath> {
|
||||
@InjectState
|
||||
private GameState gameState;
|
||||
|
||||
@InjectDependency
|
||||
private DependencyManager dependencyManager;
|
||||
|
||||
@InjectDependency
|
||||
private cz.jzitnik.client.utils.roomtasks.RoomTaskScheduler roomTaskScheduler;
|
||||
|
||||
@Override
|
||||
public void handle(PlayerDeath event) {
|
||||
log.debug("Player death: {}", event.playerId());
|
||||
roomTaskScheduler.finalShutdown();
|
||||
DeathScene deathScene = new DeathScene();
|
||||
dependencyManager.inject(deathScene);
|
||||
gameState.setScreen(deathScene);
|
||||
deathScene.fullRender();
|
||||
}
|
||||
}
|
||||
@@ -138,6 +138,7 @@
|
||||
texture: "ROOM6"
|
||||
requirement:
|
||||
item: "quest_item_final_key"
|
||||
end: true
|
||||
#objects:
|
||||
# - objectType: "exit"
|
||||
# cords: { x: 140, y: 40 }
|
||||
@@ -171,7 +172,7 @@
|
||||
updateRateMs: 700
|
||||
west: "filler_2"
|
||||
east: "spawn"
|
||||
north: null
|
||||
north: "empty_c"
|
||||
south: "filler_deadend_1"
|
||||
|
||||
|
||||
@@ -200,7 +201,7 @@
|
||||
west: "filler_c_west"
|
||||
east: null
|
||||
north: "boss"
|
||||
south: null
|
||||
south: "empty_a"
|
||||
|
||||
|
||||
|
||||
@@ -243,7 +244,7 @@
|
||||
|
||||
- id: "filler_1b"
|
||||
texture: "ROOM1"
|
||||
west: "filler_7"
|
||||
west: "filler_1"
|
||||
east: null
|
||||
north: null
|
||||
south: null
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package cz.jzitnik.server.events.handlers;
|
||||
|
||||
import cz.jzitnik.common.socket.messages.game.PlayerDeath;
|
||||
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(PlayerDeath.class)
|
||||
public class PlayerDeathHandler extends AbstractEventHandler<PlayerDeath> {
|
||||
public PlayerDeathHandler(GlobalContext globalContext) {
|
||||
super(globalContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PlayerDeath event, Client client) {
|
||||
for (Client player : client.getGame().getPlayers()) {
|
||||
player.getSession().sendMessage(new PlayerDeath(event.playerId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user