Networking Plan - PatrickMalara/battle GitHub Wiki
Questions Answered... hopefully
- How does a player create a match?
- How does a player join a match?
- How does a match progress?
- [UI](login screen) User login (through a form)
- [UI -> API] uses POST
/battle/login
- [API] authenticates the user and returns (user_id) of the User who logged in
- [UI](login screen -> rooms screen) Retrieves the user_id from the API call and then the [UI] screen changes to a "Waiting Room/Lobby"
- [UI](rooms screen) the user will have the option to create a room or join a room (in this user-flow we create a room)
- [UI -> API] uses CREATE
/battle/match
- [API] creates a match in the Database. Then returns the newly created match's id.
- [UI](rooms screen -> lobby screen) Retrieved the match_id from the API call and then the screen changes to "Waiting Room/Lobby"
- [UI](rooms screen -> lobby screen) Retrieves the user_id from the API call and then the [UI] screen changes to a "Waiting Room/Lobby"
- [UI](lobby screen) User waits for an opponent
- At this point another User(the anticipated opponent) will have to login, type the room name, and then the use will join the Match
- [API] We haven't touched on JOINING a room, just creating. The difference is that we do PATCH
battles/match
and update the second user_id as well as the status = "In Progress"
- [API] in the API... apart of the PATCH
battle/match
we emit an event. EventmatchStarted
that returns the match_id. - [UI](lobby screen -> game screen) the UI listens to an event called
matchStarted
and if the match_id === match_id of the lobby, then the UI transitions the lobby screen to the game screen we know so well :) -> this happens for both players - [UI](game screen) a move is done by calling the API, POST
battle/move
- [API] on
battle/move
we emit a 'move' event that returns the match_id, the board, and the user_id who made the move. - [UI] if the user_id returned from the 'move' event is === to your user_id then its NOT youre turn. If !== then it IS your Turn.