feat: add basic backbone for lobby
This commit is contained in:
parent
6cc904cae3
commit
0833976aca
@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$/../../../Gamelib">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/../../../Gamelib/.gradle" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/../../../Gamelib/build" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="jdk" jdkName="15" jdkType="JavaSDK" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
@ -1,15 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module external.system.module.type="sourceSet" type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<output url="file://$MODULE_DIR$/../../../Gamelib/build/classes/java/main" />
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$/../../../Gamelib/src/main">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/../../../Gamelib/src/main/java" isTestSource="false" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-annotations:2.12.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-databind:2.12.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-core:2.12.3" level="project" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
@ -1,30 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module external.system.module.type="sourceSet" type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<output-test url="file://$MODULE_DIR$/../../../Gamelib/build/classes/java/test" />
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$/../../../Gamelib/src/test">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/../../../Gamelib/src/test/java" isTestSource="true" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="module" module-name="marvelous-server.Gamelib.main" />
|
|
||||||
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-annotations:2.12.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-databind:2.12.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-core:2.12.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.junit.jupiter:junit-jupiter-api:5.8.0-M1" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.mockito:mockito-all:2.0.2-beta" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.assertj:assertj-core:3.19.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.junit.platform:junit-platform-commons:1.8.0-M1" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.apiguardian:apiguardian-api:1.1.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.opentest4j:opentest4j:1.2.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.junit.jupiter:junit-jupiter-engine:5.8.0-M1" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.junit.platform:junit-platform-engine:1.8.0-M1" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.20" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.20" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.4.20" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:1.4.20" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.jetbrains:annotations:13.0" level="project" />
|
|
||||||
</component>
|
|
||||||
<component name="TestModuleProperties" production-module="marvelous-server.Gamelib.main" />
|
|
||||||
</module>
|
|
@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$/../../../Server">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/../../../Server/.gradle" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/../../../Server/build" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="jdk" jdkName="15" jdkType="JavaSDK" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
@ -1,18 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module external.system.module.type="sourceSet" type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<output url="file://$MODULE_DIR$/../../../Server/build/classes/java/main" />
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$/../../../Server/src/main">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/../../../Server/src/main/java" isTestSource="false" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="module" module-name="marvelous-server.Gamelib.main" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.java-websocket:Java-WebSocket:1.5.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.slf4j:slf4j-api:1.7.25" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: com.fasterxml.jackson.core:jackson-annotations:2.12.3" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: com.fasterxml.jackson.core:jackson-databind:2.12.3" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: com.fasterxml.jackson.core:jackson-core:2.12.3" level="project" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
@ -1,31 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module external.system.module.type="sourceSet" type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<output-test url="file://$MODULE_DIR$/../../../Server/build/classes/java/test" />
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$/../../../Server/src/test" />
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="module" module-name="marvelous-server.Server.main" />
|
|
||||||
<orderEntry type="module" module-name="marvelous-server.Gamelib.main" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.java-websocket:Java-WebSocket:1.5.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.junit.jupiter:junit-jupiter-api:5.8.0-M1" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.mockito:mockito-all:2.0.2-beta" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.assertj:assertj-core:3.19.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.slf4j:slf4j-api:1.7.25" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.junit.platform:junit-platform-commons:1.8.0-M1" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.apiguardian:apiguardian-api:1.1.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.opentest4j:opentest4j:1.2.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.junit.jupiter:junit-jupiter-engine:5.8.0-M1" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: com.fasterxml.jackson.core:jackson-annotations:2.12.3" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: com.fasterxml.jackson.core:jackson-databind:2.12.3" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: com.fasterxml.jackson.core:jackson-core:2.12.3" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.junit.platform:junit-platform-engine:1.8.0-M1" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.20" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.20" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.4.20" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:1.4.20" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.jetbrains:annotations:13.0" level="project" />
|
|
||||||
</component>
|
|
||||||
<component name="TestModuleProperties" production-module="marvelous-server.Server.main" />
|
|
||||||
</module>
|
|
@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$/../..">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/../../.gradle" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/../../build" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="jdk" jdkName="15" jdkType="JavaSDK" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
@ -2,41 +2,77 @@ package uulm.teamname.marvelous.server.Lobby;
|
|||||||
|
|
||||||
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
||||||
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.events.EventType;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.gamelogic.EventObserver;
|
||||||
import uulm.teamname.marvelous.gamelibrary.gamelogic.GameInstance;
|
import uulm.teamname.marvelous.gamelibrary.gamelogic.GameInstance;
|
||||||
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
||||||
|
import uulm.teamname.marvelous.server.LobbyManager.LobbyConnection;
|
||||||
|
import uulm.teamname.marvelous.server.LobbyManager.MessageSource;
|
||||||
|
|
||||||
public class Lobby {
|
import java.util.*;
|
||||||
|
|
||||||
String gameID;
|
public class Lobby extends EventObserver {
|
||||||
GameInstance gameInstance; // This is the main "wrapper" class for Gamestate, Event creation and so son
|
public final String gameID;
|
||||||
|
public final LobbyConnection connection;
|
||||||
|
public final GameInstance game;
|
||||||
|
|
||||||
|
public Lobby(String gameID, IntVector2 mapSize, LobbyConnection connection) {
|
||||||
|
|
||||||
public Lobby(String gameID){
|
|
||||||
//the LobbyManager can create a Lobby with a specific ID.
|
|
||||||
this.gameID = gameID;
|
this.gameID = gameID;
|
||||||
|
this.connection = connection;
|
||||||
|
|
||||||
|
game = new GameInstance(mapSize);
|
||||||
|
game.addObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recieveEvents(Request[] requests){
|
@Override
|
||||||
//Get Messages from the LobbyManager
|
protected void handle(Event[] events) {
|
||||||
//possible requests: MeleeAttackRequest, RangeAttackRequest, MoveRequest, ExchangeInfinityStoneRequest, UseInfinityStoneRequest.
|
connection.broadcastEvents(events);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendEvents(Event[] events){
|
public void receiveRequests(MessageSource source, Request[] requests) {
|
||||||
//Send Messages to the LobbyManager
|
ArrayList<Request> stateRelevant = new ArrayList<>();
|
||||||
//Events spliced in:
|
|
||||||
//Gamestate Events: Ack, Nack, Req, GamestateEvent, CustomEvent
|
for(Request request: requests) {
|
||||||
//Entity Events: DestroyEntityEvent, HealedEvent, TakenDamageEvent, SpawnEntityEvent
|
switch(request.type) {
|
||||||
//Character Events: MeleeAttackEvent, RangedAttackEvent, MoveEvent, UseInfinityStoneEvent, ExchangeInfinityStoneEvent
|
case MeleeAttackRequest, RangedAttackRequest, MoveRequest, ExchangeInfinityStoneRequest, UseInfinityStoneRequest -> {
|
||||||
//Game Events: TimeoutEvent, TimeoutWarningEvent, WinEvent, RoundSetupEvent, TurnEvent, TurnTimeoutEvent, DisconnectEvent.
|
stateRelevant.add(request); // these need to be checked all together by the game instance itself
|
||||||
|
}
|
||||||
|
case PauseStopRequest, PauseStartRequest, EndRoundRequest, DisconnectRequest, Req -> {
|
||||||
|
processRequest(request);
|
||||||
|
return; // only one of these will ever be sent at once, and if that is the case, we wont have any other state relevant events
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processEvents(){
|
if(!game.checkRequestsAndApply((Request[]) stateRelevant.toArray())) {
|
||||||
//The largest Block to handle all possible Events
|
// requests don't apply, tell the client that they need to update their state
|
||||||
//To defuse this Method you could use the smaller Methods below.
|
connection.sendEvents(source, new EventBuilder(EventType.Nack).buildGameEvent(), game.getGameStateEvent());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause(){
|
private void processRequest(Request request) {
|
||||||
|
//TODO: handle the rest of the requests
|
||||||
|
switch(request.type) {
|
||||||
|
case PauseStopRequest -> {
|
||||||
|
|
||||||
|
}
|
||||||
|
case PauseStartRequest -> {
|
||||||
|
|
||||||
|
}
|
||||||
|
case EndRoundRequest -> {
|
||||||
|
|
||||||
|
}
|
||||||
|
case DisconnectRequest -> {
|
||||||
|
|
||||||
|
}
|
||||||
|
case Req -> {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pause() {
|
||||||
|
|
||||||
}
|
}
|
||||||
public void unpause(){
|
public void unpause(){
|
||||||
@ -44,18 +80,6 @@ public class Lobby {
|
|||||||
}
|
}
|
||||||
public void handleDisconnects(){
|
public void handleDisconnects(){
|
||||||
|
|
||||||
}
|
|
||||||
public void validateRequest(){
|
|
||||||
|
|
||||||
}
|
|
||||||
public void applyRequestToGamestate(){
|
|
||||||
|
|
||||||
}
|
|
||||||
public void generateEvents(){
|
|
||||||
|
|
||||||
}
|
|
||||||
public void saidEvents(){
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public void DisconnectClient(){
|
public void DisconnectClient(){
|
||||||
|
|
||||||
|
@ -100,12 +100,12 @@ public class LobbyConnection {
|
|||||||
|
|
||||||
// Methods to send events
|
// Methods to send events
|
||||||
|
|
||||||
public void sendEvents(Event[] events, MessageSource target) {
|
public void sendEvents(MessageSource target, Event... events) {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
MessageRelay.getInstance();
|
MessageRelay.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void broadcastEvents(Event[] events) {
|
public void broadcastEvents(Event... events) {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
MessageRelay.getInstance();
|
MessageRelay.getInstance();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user