feat: add basic backbone for lobby

This commit is contained in:
punchready 2021-05-18 18:11:52 +02:00
parent 6cc904cae3
commit 0833976aca
9 changed files with 59 additions and 165 deletions

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -2,41 +2,77 @@ package uulm.teamname.marvelous.server.Lobby;
import uulm.teamname.marvelous.gamelibrary.IntVector2;
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.requests.Request;
import uulm.teamname.marvelous.server.LobbyManager.LobbyConnection;
import uulm.teamname.marvelous.server.LobbyManager.MessageSource;
public class Lobby {
import java.util.*;
String gameID;
GameInstance gameInstance; // This is the main "wrapper" class for Gamestate, Event creation and so son
public class Lobby extends EventObserver {
public final String gameID;
public final LobbyConnection connection;
public final GameInstance game;
public Lobby(String gameID){
//the LobbyManager can create a Lobby with a specific ID.
public Lobby(String gameID, IntVector2 mapSize, LobbyConnection connection) {
this.gameID = gameID;
this.connection = connection;
game = new GameInstance(mapSize);
game.addObserver(this);
}
public void recieveEvents(Request[] requests){
//Get Messages from the LobbyManager
//possible requests: MeleeAttackRequest, RangeAttackRequest, MoveRequest, ExchangeInfinityStoneRequest, UseInfinityStoneRequest.
@Override
protected void handle(Event[] events) {
connection.broadcastEvents(events);
}
public void sendEvents(Event[] events){
//Send Messages to the LobbyManager
//Events spliced in:
//Gamestate Events: Ack, Nack, Req, GamestateEvent, CustomEvent
//Entity Events: DestroyEntityEvent, HealedEvent, TakenDamageEvent, SpawnEntityEvent
//Character Events: MeleeAttackEvent, RangedAttackEvent, MoveEvent, UseInfinityStoneEvent, ExchangeInfinityStoneEvent
//Game Events: TimeoutEvent, TimeoutWarningEvent, WinEvent, RoundSetupEvent, TurnEvent, TurnTimeoutEvent, DisconnectEvent.
public void receiveRequests(MessageSource source, Request[] requests) {
ArrayList<Request> stateRelevant = new ArrayList<>();
for(Request request: requests) {
switch(request.type) {
case MeleeAttackRequest, RangedAttackRequest, MoveRequest, ExchangeInfinityStoneRequest, UseInfinityStoneRequest -> {
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
}
}
}
if(!game.checkRequestsAndApply((Request[]) stateRelevant.toArray())) {
// requests don't apply, tell the client that they need to update their state
connection.sendEvents(source, new EventBuilder(EventType.Nack).buildGameEvent(), game.getGameStateEvent());
}
}
public void processEvents(){
//The largest Block to handle all possible Events
//To defuse this Method you could use the smaller Methods below.
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 pause() {
}
public void unpause(){
@ -44,18 +80,6 @@ public class Lobby {
}
public void handleDisconnects(){
}
public void validateRequest(){
}
public void applyRequestToGamestate(){
}
public void generateEvents(){
}
public void saidEvents(){
}
public void DisconnectClient(){

View File

@ -100,12 +100,12 @@ public class LobbyConnection {
// Methods to send events
public void sendEvents(Event[] events, MessageSource target) {
public void sendEvents(MessageSource target, Event... events) {
// TODO: implement
MessageRelay.getInstance();
}
public void broadcastEvents(Event[] events) {
public void broadcastEvents(Event... events) {
// TODO: implement
MessageRelay.getInstance();
}