Now that we have defined the data structure of our game, let's start with implementing the logic to create and persist a new game document in the database, all the while following Test-Driven Development practices.
In order to create a new game, we need to accept a POST to /create
with your name in the POST body:
{ name: 'player1' }
There are a few things we should think about:
We need to return the board information to the user, and whether or not game creation was successful
We need to ensure the player can access the game they just created, so we must send them the
boardId
In order for the player to identify themselves, we also need to ensure that we send them the
p1Key
, which will be needed for all future moves that Player One wishes to play to this board
Since we're building the game, we have the power to bend the rules of the game. So let's allow player 1 to optionally configure the size of the playing board! We should have a minimum size of 6x7, though.
So let's start...