pig-dice-game
June 12, 2022 ยท View on GitHub
Pig is a simple dice game first described in print in John Scarne in 1945. Players take turns to roll a single dice as many times as they wish, adding all roll results to a running total, but losing their gained score for the turn if they roll a 1.
Available at https://pig-dice-game.pux.one or https://pux-pig-dice-game.herokuapp.com
Development
npm installdocker-compose up -d- For local redis environmentnpm start- Navigate to one of the following:
Forking
https://github.com/nick-ng/pig-card-game is newer so you should fork that repo instead.
Deploying to Heroku
- Create an empty Heroku App. Note the app's name
- Get your Heroku API key from https://dashboard.heroku.com/account
- On GitHub repo for your fork, go to the Settings and click on Secrets > Actions
- Add 3 new repository secrets
HEROKU_API_KEY: API key from aboveHEROKU_APP_NAME: App name from aboveHEROKU_EMAIL: Email address of your Heroku account
- Push a commit to the
mainbranch.
ToDos
- Make basic game functions in backend
- Use Redis to store game state
- Make front=end game lobby
- Make front-end game play
- GitHub build action & Heroku host
- Redis streams & Websocket
- Add CORS so people can write their own fron-ends
- Work on a new game (probably pig (card game))
Notes
Game State
On the server
{
"id": "1234-12345-12345-1234",
"host": "some-player's-uuid",
"maxPlayers": 2,
"players": [
{ "id": "some-player's-uuid", "name": "Alice" },
{ "id": "player-two's-uuid", "name": "Bob" }
],
// Things about the game that don't change once it's started.
"gameSettings": {
"gameSetting1": 3,
"gameSetting2": "hello"
},
// Secret information, only available to some players
"gameSecrets": {
"some-player's-uuid": {
"password": "asdf", // Used to prevent other players performing actions on your behalf.
"secret1": "world"
},
"player-two's-uuid": {
"password": "bsdf",
"secret1": "!"
}
},
// Everything else about the game
"gameState": {
"state": "main", // "lobby", "upkeep", "draw", "main", "combat", etc.
"activePlayer": "player-two's-uuid",
"turnOrder": ["player-two's-uuid", "some-player's-uuid"],
"score": "etc"
}
}
Sent to Alice
{
"id": "1234-12345-12345-1234",
"host": "some-player's-uuid",
"maxPlayers": 2,
"players": [
{ "id": "some-player's-uuid", "name": "Alice" },
{ "id": "player-two's-uuid", "name": "Bob" }
],
"gameSettings": {
"gameSetting1": 3,
"gameSetting2": "hello"
},
"gameSecrets": {
"password": "asdf",
"secret1": "world"
},
"gameState": {
"activePlayer": "player-two's-uuid",
"score": "etc"
}
}
WebSocket API
If you get disconnected, you need to reconnect and re-listen to the game. You'll still be in the game so you don't need to rejoin it..