Skip to content

API Design

Sumeet Grewal edited this page Dec 16, 2020 · 14 revisions

API Design

Endpoints

Resource GET POST PUT DELETE
/game/connect subscribe to game SSE restart game exit game
/game/setup add player to game {username, password} update player {status, board}
/game/play handle player card selection    
/game/assets get boards and cards in play      

Event Listeners

Setting up a game

/game/connect

  • joined listener - when client subscribes to SSE

    • receives confirmation of connection
  • keepalive listener

    • maintains SSE connection by pinging every 50 second

/game/setup

  • playerUpdate listener

    • receives player data when 1) a new players joins the game lobby or 2) a player "is ready"
  • setupUpdate listener

    • receives gamestatus and setupData:
      • playerOrder
      • turnToChoose
      • boards
      • assignedBoards
  • gameUpdate listener

    • receives players and gameStatus ("join"/"lobby"/"boardSelection"/"game")

Playing a game

/game/play

  • turnUpdate listener

    • receives
      • metadata - age, turn, etc.
      • currentHand - array of card IDs in hand
      • handInfo - canBuild flag, coinCost, and PurchaseOptions for each card in hand
      • stageInfo - Whether a player can build the next stage
      • isWaiting = false (reset isWaiting flag)
  • playerDataUpdate listener

    • receives data for given player
  • allPlayerDataUpdate listener

    • receives data for all other players besides given player
  • gameFeed listener

    • received game feed data {player, type, message, card?}[]
      • turn data at end of each turn (card selected/discarded/staged)
      • military data at end of each age
      • payment data if you pay or receive coins

Clone this wiki locally