0

I am trying to design a game which needs to do the following: Have a lobby period, move players into a pre-game setup, start the game, end the game, repeat.

My current setup is as follows: A MatchManager creates and destroys Match objects and sets it's state when needed. There is a MatchState enum (No lobby period) where players skip the lobby and go directly from the game ending to the pregame of the next. We would like to now add a Lobby period as described.

In a previous version of the game, we had a Lobby object with a queue of players inside of it. Then we simply had 2 fields inside MatchManager: current match and current lobby. Using a lot of painful null checks, we were able to tell whether or not the game was in lobby period. We do not like this solution, and wonder if there is a better one.

What I am wondering is, what is a good way to manage a Lobby without adding it to MatchState (since MatchState should only be responsible for the LifeCycle of a Match) and also not creating one global GameState (this game is intended to be very flexible, so it's likely at some point we will be running multiple matches at once. This requires some kind of MatchState, and it would be very confusing to manage 2 states at once). Additionally, is there an alternative to using enums for a "MatchState" all together? One of our main goals was to create a Core game engine in which we can easily add/remove states in the future without destroying the lifecycle of some code.

Edit: additionally, we don't want to directly add Lobby into the core (since our core may be used in a game that doesn't need a lobby). I just wanted to stress this, since it means we are looking for a different kind of solution (dynamic states).

njny
  • 559
  • 2
  • 15
  • Too broad to answer this but having a state object (that itself could contain sub-state-objects, maybe a specific one for matchstate and one for lobby state?) doesn't sound wrong. But finding the right design is hard. There are many opinions but never that one correct solution. E.g. you can drop the manager class and implement the logic in the state object itself. As in `State#goToLobby()` vs `Manager#goToLobby(State)` - http://stackoverflow.com/a/15020493/995891 explains why. – zapl Aug 29 '15 at 02:02
  • @zapl I need the manager class (my game is actually a modification to another, it wraps some classes using the manager), I can see why my question is pretty broad. But I agree: finding a design is hard. It's just that I'd like to see what various people (StackOverFlow Community) would do in this situation, since I'm a less experienced developer. Thank you for your solution idea though :) – njny Aug 29 '15 at 04:03

0 Answers0