Backend for a turn-based game running on a serverless architecture. The game implemented is rock-paper-scissors for the Azure Functions platform, but the code is modular enough to change the game and the service provider more easily.
The front-end is implemented in a rock-paper-scissors game for Unity here using the following parts: C-sharp base scripts, with Unity specific utility scripts, an implementation of Scriptable Objects Architecture to emit UI Signals, and a modular network framework.
The main functionality is implemented in the class MatchFunctions. I comment the functions in more detail below. The interaction between the client and the 'server' is by polling, so the client must ckeck on the server repeatedly to know if the state of the game has changed and treat the changes.
Every function is called using a Request and responds with a Response.
The first interaction between the client and server on every session. Must be called with an unique device identifier. Creates (if new) or updates a PlayerRegistry to the database.
Each PlayerRegistry has a PlayerInfo field, which in turn has a CustomData field with public data about that player. This function allows to send custom data to that field.
Registers this player as looking for match and tries to match them right away if enough players are available. A temporary entry will be written to the database with this player info for future players finding matches.
Get info about a match, or tries to match the requester player if not matched yet. If a match is created, a MatchRegistry will be written to the database.
Takes measures to mark this player as retreated from the match. If only looking for match, deletes the entry from this player. If already in a match, sets this player as a "RetreatedPlayer".
Sends an ActionInfo with custom information to alter the match state. The game implemented must check and interpret the action sent.
Get the current match state if it's different from the last known state. Writes and updates a StateRegistry.
IService (Link)
Provides methods to be implemented for a service that will make specific reads and writes to the database.
IGame (Link)
Contains methods to be implemented according to the rules of the game. It checks actions sent and modifies the match state.
