JSON data containing complete game state. This game state may include keys such as drawPile and discardPile, where each might store an array of card objects. We chose to store all game state in a single JSON column instead of separate JSON columns for each component of game state to simplify this module so that students can focus on AJAX and not DB schema.
When a user clicks the Start Game button, the app creates a Game record in the DB and adds a random 2nd player to the game. If there are no users in the DB other than the 2 seeded users, then the app will choose the non-logged-in user as the random 2nd player.
When either player clicks the Deal button, the app deals cards to the players and evaluates who has won that hand. The app records the result in the DB and sends the result in a response to the user.
Keep a running score of each user's wins and display that score on the game page.
First to 3
A game ends when a player wins 3 times total. Once a game ends, prompt the players to start a new game. Add a column to our Game table (in both migrations and models) such that the Game table can record the winner of each game. The winner's identity will be stored as a foreign key ID to the Users table.
When either user clicks Deal, allow them to specify how many cards get discarded before the app deals their cards. Show both users the discarded cards.
Create an EJS page in Express that displays a list of the login user's winning and losing games and any relevant information about those games.
When a user creates a game, let them choose from a dropdown list of users to play the game with.
Click here to see the reference solution for this post class.