diff --git a/.idea/modules/Gamelib/marvelous-server.Gamelib.iml b/.idea/modules/Gamelib/marvelous-server.Gamelib.iml
deleted file mode 100644
index 8f7878a..0000000
--- a/.idea/modules/Gamelib/marvelous-server.Gamelib.iml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/Gamelib/marvelous-server.Gamelib.main.iml b/.idea/modules/Gamelib/marvelous-server.Gamelib.main.iml
deleted file mode 100644
index 265d461..0000000
--- a/.idea/modules/Gamelib/marvelous-server.Gamelib.main.iml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/Gamelib/marvelous-server.Gamelib.test.iml b/.idea/modules/Gamelib/marvelous-server.Gamelib.test.iml
deleted file mode 100644
index 21641f3..0000000
--- a/.idea/modules/Gamelib/marvelous-server.Gamelib.test.iml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/Server/marvelous-server.Server.iml b/.idea/modules/Server/marvelous-server.Server.iml
deleted file mode 100644
index 7e092db..0000000
--- a/.idea/modules/Server/marvelous-server.Server.iml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/Server/marvelous-server.Server.main.iml b/.idea/modules/Server/marvelous-server.Server.main.iml
deleted file mode 100644
index 58816b2..0000000
--- a/.idea/modules/Server/marvelous-server.Server.main.iml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/Server/marvelous-server.Server.test.iml b/.idea/modules/Server/marvelous-server.Server.test.iml
deleted file mode 100644
index 7a19350..0000000
--- a/.idea/modules/Server/marvelous-server.Server.test.iml
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/marvelous-server.iml b/.idea/modules/marvelous-server.iml
deleted file mode 100644
index 7ea181b..0000000
--- a/.idea/modules/marvelous-server.iml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/Lobby/Lobby.java b/Server/src/main/java/uulm/teamname/marvelous/server/Lobby/Lobby.java
index 4d22243..a5be839 100644
--- a/Server/src/main/java/uulm/teamname/marvelous/server/Lobby/Lobby.java
+++ b/Server/src/main/java/uulm/teamname/marvelous/server/Lobby/Lobby.java
@@ -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 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(){
diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/LobbyManager/LobbyConnection.java b/Server/src/main/java/uulm/teamname/marvelous/server/LobbyManager/LobbyConnection.java
index 1b8f002..a209421 100644
--- a/Server/src/main/java/uulm/teamname/marvelous/server/LobbyManager/LobbyConnection.java
+++ b/Server/src/main/java/uulm/teamname/marvelous/server/LobbyManager/LobbyConnection.java
@@ -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();
}