Saturday, May 16, 2015

Tic Tac Toe Service Design - The Lobby

I'm going to start this simple. Basic idea is that players discover other players who are looking at the Lobby. Clients poll the Lobby for challenges and responses to challenges. When a challenge is accepted, the Lobby contacts the Game service and creates a matchID. Both players get the matchID and either player can start the match.

Yes yes I know, polling is evil. But I wanted to build a RESTful service and didn't want to create yet another task app. In real life I would implement this as websockets or some such technology, and that conversion might be an interesting topic in the future.

I'm using websequencediagrams.com (this is the awesomeness) to draft out the ideas.




Here's the "source code":

title Tic Tac Toe Service - starting a game
Player1 -> Lobby: joinPlayer2 -> Lobby: join
Player1 -> Lobby: challenge Player1loop challenge polling, until timeout or challenge response received  Player1 -> Lobby: challenge response?  opt accept    Lobby -> Game: create matchID    Game -> Lobby: matchID    Lobby -> Player1: accept: matchID    Player1 -> Game: start match: matchID  end  opt reject    Lobby -> Player1: reject    Player1 -> Player: stop challenge polling  end  opt timeout    Player1 -> Player: stop challenge polling  endend
loop match polling, until challenge performed  Player2 -> Lobby: any challenges pending?  Lobby -> Player2: challenge available  opt accept    Player2 -> Lobby: accept    Lobby -> Lobby: prepare accept    Lobby -> Player2: matchID  end  opt reject    Player2 -> Lobby: reject    Lobby -> Lobby: prepare reject  endend
Player1 -> Game: start game: matchIDGame -> Game: prepare game
How the Game service should go about orchestrating a match is the subject of my next post.

No comments:

Post a Comment