On a website users (members or guests) can play a browser game against other players.
Members can choose between two actions:
- They create a new game and wait for other users to join.
- They join a random existing (waiting) game. When a user chooses to join a game and no games are waiting, he automatically gets redirected to game creation to start a new game.
For guests, only the second option is available. They have to try and join an existing game. Only if no games are available, a guest can create a new game.
But here is the problem: What if a new game opens up while the guest is presented with the option to create a new game?
Is there any good way to handle such a situation?
Here is a timeline of the problem for clarification:
Technically, the user is not allowed to create a new game when he finally submits his options. But I feel it would be wrong to just disallow him from creating his game at that point.
I thought of multiple different ways to handle this case:
- When a guest tries to join a game and fails, a variable in his session called
mayCreateOneGame
is set totrue
. While that variable is true, the user is allowed to create a game. When he has created a new game, the variable is set tofalse
again. But: What happens when the user does not immediately create a new game but rather comes back an hour (or a day) later. Should he still be allowed to create the game? - When a guest tries to join a game and fails, a variable in his session called
failedToJoinAt
is set to the current timestamp. While the timestamp is no older than - lets say - five minutes, the guest is allowed to create a game. But: What happens if the game creation takes the user longer than that time? - When a guest tries to join a game and fails, he simply is told to wait until a member created a new game. But: That might take a long time and be no fun for the guest, who just wants to play.