Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

(Obsolete) Ultimate-TTT Multiplayer Backend

License

Notifications You must be signed in to change notification settings

ultimate-ttt/ultimate-ttt-backend

Repository files navigation

Ultimate TicTacToe Backend

contributions welcome Build Status Quality Gate Status Coverage GitHub release Docker Pulls

Public API

TODO Visit #10 to see Progress

Running the Api on your system

Using the latest release of the Docker image

To use the latest release for local testing run the following steps. dotnet doesn't need to be installed on your local computer.

Prerequisites

  • Docker is installed & running

Setup

  1. Open command-line and navigate to the root of the repository
  2. run docker-compose up
  3. Access the API from your browser http://localhost:5023/playground

Localy Build and Test

If you have done some work on the code you probably want to check if your changes break the build or the tests. This can be done locally.

Prerequisites

  • dotnet core 2.1 SDK installed. (for specific version see global.json)

Using the Cake Tool

This solution works on all operation systems on which you can run dotnet core.

Prerequisites

  • Cake Tool installed(min. Version 0.33.0). To install run dotnet tool install -g Cake.Tool

Build and Test the Api

  1. Open command-line and navigate to the root of the repository
  2. run dotnet cake build.cake

Now the entire solution is built and the tests are executed.

Using Windows Powershell on Windows

This solution does not require Cake.Tool to be installed on your system but it only works on Windows.

Build and Test the Api

  1. Open command-line and navigate to the root of the repository
  2. run .\build.ps1

Now the entire solution is built and the tests are executed.

Running the Api on your local system

  1. Open command-line and navigate to the root of the repository
  2. Open /src/Api/appsettings.json and verify that Database:ConnectionString has a valid Connectionstring for a MongoDB according to your system setup
  3. run cd ./src/Api; dotnet watch run

Creating an new Image Version

After you finished developing you probably want to check if the changes behave correctly in the container environment. Therefore you can build the docker image locally.

  1. Open command-line and navigate to the root of the repository
  2. run .\build.ps1 -target "PublishApi" with Powershell or dotnet cake --target=PublishApi using the cake tool. This build the Api in Release Mode
  3. run docker build -t ultimatettt/ultimate-ttt-server:localtesting. this creates a local image of the previously built api.
  4. run docker-compose -f "docker-compose-localtesting.yml" up. This starts the local testing image.

Examples

Create a new game

mutation CreateNewGame{
   createGame{
    id
  }
}

Make a Move

mutation Move{
  move(
    input: {
      gameId: "abcdef"
      boardPosition: {x: 0, y:0}
      tilePosition: {x: 0, y:0}
      player:CROSS
    }
  ){
    isValid
  }
}

Get game status

query GameStatus{
  game(id: "abcdef"){
    id
    moves{
      moveNumber
      boardPosition{
        x
        y
      }
      tilePosition{
        x
        y
      }
      player
    }
    winner
  }
}

Live updates

In order to get notified of the opponents moves you have to specify 2 things.

gameId: The Id of the game you are playing

player: The player of which you want to receive the moves

subscription onOpponentMoved {
  onMove(gameId: "AAYfPSa", player: CROSS) {
    moveNumber
    boardPosition{
      x
      y
    }
    tilePosition{
      x
      y
    }
    player
  }
}