Skip to content

DevDogs-UGA/TicTacToe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

TicTacToe Server API

The first player to join will be X; the second player to join will be O.

Live Endpoint: http://tictactoe.devdogsuga.org/

Create Game

POST /

Creates a new TicTacToe game.

  • Returns a JSON response on 200 Success

Successful Response Shape:

{
  "gameCode": string,
  "playerId": string
}

Get Player Id for Game

GET /[gameCode]

Gets a new player id for a TicTacToe game with game code [gameCode].

  • Returns a JSON response on 200 Success
  • Returns 400 Bad Request if game already has two players
  • Returns 404 Not Found if game doesn't exist

Successful Response Shape:

{
  "playerId": string
}

Join Game

GET /[gameCode]?playerId=[playerId]

Join a new game via a WebSocket connection.

  • Returns 101 Switching Protocols on success
  • Returns 401 Unauthorized if player id is incorrect
  • Returns 404 Not Found if game doesn't exist

After joining the game, the following JSON messages are supported to be recieved by the server:

Client Messages

Pong

Required to be sent upon recieving a ping

{
  "type": "pong"
}

Move

Play a move a the provided index (0-8) for the connected player

{
  "type": "move",
  "data": number
}

Rematch

Set the rematch flag for the currently connected player.

{
  "type": "move",
  "data": number
}

Server Messages

Ping

Sent every 30 seconds to check if the connection is still alive

{
  "type": "ping",
  "data": number
}

State

Sent every time the game state changes (i.e., a player connections/disconnects, a player commits a move, or a player requests a rematch)

{
  "type": "state",
  "data": {
    "turn": "X" | "O",
    "connected": {
      "playerX": boolean,
      "playerO": boolean
    },
    "rematch": {
      "playerX": boolean,
      "playerO": boolean
    },
    "board": [
      "X" | "O" | null,
      "X" | "O" | null,
      "X" | "O" | null,
      "X" | "O" | null,
      "X" | "O" | null,
      "X" | "O" | null,
      "X" | "O" | null,
      "X" | "O" | null,
      "X" | "O" | null
    ]
  }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors