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

  1. npm install
  2. docker-compose up -d - For local redis environment
  3. npm start
  4. 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

  1. Create an empty Heroku App. Note the app's name
  2. Get your Heroku API key from https://dashboard.heroku.com/account
  3. On GitHub repo for your fork, go to the Settings and click on Secrets > Actions
  4. Add 3 new repository secrets
    • HEROKU_API_KEY: API key from above
    • HEROKU_APP_NAME: App name from above
    • HEROKU_EMAIL: Email address of your Heroku account
  5. Push a commit to the main branch.

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..