rohitranjan-2702 / hangman

Built this realtime server to implement hangman game logic.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hangman Backend API

Features

  • Realtime score updates
  • Create rooms with passwords
  • Turn Based Multiplayer game
  • Games saved in redis cache storage

Setup

  • Clone the repo by running git clone https://github.com/rohitranjan-2702/hangman.git
  • Run docker run --name my-redis -d -p 6379:6379 redis to setup redis locally.
  • Run development server npm run dev to start the server.
  • Connect with postman, and send the event as text but in JSON form, as I am parsing it after that.

Usage

  • Events : Create a game
{
  "type": "create",
  "word": "Rohit",
  "password": "123123",
  "playerName": "Player 1"
}

Creates a new room, join the current player and returns a unique gameId for other players to join.

  • Events : Join a game
{
  "type": "join",
  "gameId": "c30aul5pj",
  "password": "123123",
  "playerName": "Player 1"
}

Returns the current gameState Object

{
  "word": "Rohit",
  "guesses": [],
  "turnsLeft": 6,
  "correctGuesses": [],
  "players": [{ "id": "N5YGCsVGXhxezqGkAAAB", "name": "Player 1" }],
  "isGameOver": false,
  "isWordGuessed": false,
  "scores": { "N5YGCsVGXhxezqGkAAAB": 0 },
  "currentPlayer": { "id": "N5YGCsVGXhxezqGkAAAB", "name": "Player 1" },
  "currentPlayerIndex": 0
}
  • Events : Guess the letter
{
  "type": "guess",
  "gameId": "c30aul5pj",
  "letter": "R"
}

Returns the updated gameState with individual scores of players.

{
  "word": "Rohit",
  "guesses": ["R"],
  "turnsLeft": 6,
  "correctGuesses": ["R"],
  "players": [
    { "id": "N5YGCsVGXhxezqGkAAAB", "name": "Player 1" },
    { "id": "9vbbjaeCuk1orYC2AAAD", "name": "Player 2" }
  ],
  "isGameOver": false,
  "isWordGuessed": false,
  "scores": { "N5YGCsVGXhxezqGkAAAB": 0, "9vbbjaeCuk1orYC2AAAD": 1 },
  "currentPlayer": { "id": "9vbbjaeCuk1orYC2AAAD", "name": "Player 2" },
  "currentPlayerIndex": 1
}
  • Get all games
curl http://localhost:8000/games
  • Get a game by id
curl http://localhost:8000/game/hteqi6vm5
  • Delete all games
curl http://localhost:8000/delete

About

Built this realtime server to implement hangman game logic.


Languages

Language:TypeScript 84.7%Language:Shell 13.9%Language:Dockerfile 1.4%