Skip to content

cmiller-cenith/GridGame-Next

Repository files navigation

GridGame Backend Example

This is a sample implementation of Option 2 of the Cenith take-home GridGame assignment - which is to design a backend that could support the playing of the GridGame.

Problem Statement

Game Details

In a 100 by 100 2-D grid world, you are given a starting point A on one side of the grid, and an ending point B on the other side of the grid. Your objective is to get from point A to point B.

Each grid space can be in a state of [“Blank”, “Speeder”, “Lava”, “Mud”]. You start out with 200 points of health and 450 moves. Below is a mapping of how much your health and moves are affected by landing on a grid space.

[
“Blank”: {“Health”: 0, “Moves”: -1},
“Speeder”: {“Health”: -5, “Moves”: 0},
“Lava”: {“Health”: -50, “Moves”: -10},
“Mud”: {“Health”: -10, “Moves”: -5},
]

Assignment

Build a backend HTTP API using Node.js, or similar, and Typescript, that allows a player to save the game and come back to it later. It should also return any relevant data to the frontend, such as where the player is on the board, what the board is configured like, how much health or moves are left, etc. Try to include business logic such as how the board is initially configured and the change of state of the board / players as well. We expect to be able to play the game over your HTTP API.

Solution

About

The solution was implemented as a Next.js app. It's written in Typescript and uses Drizzle as an ORM and for other general databasing needs (schema definition, migrations, and seeds).

Structure

    .
    ├── app                     # Main application directory - it contains all of the source code for our solution
    │   ├── db                  # Directory containing database 
    │   │   ├── migrations      # Used by Drizzle to output automagically generated migration files.
    │   │   ├── schema          # Database schema definitions used by our app. These originate our tables in Postgres.
    │   │   ├── seeds           # Houses sample/input files that can be seeded into the database. 
    │   │   ├── drizzle.ts      # The primary database file. It establishes our DB connection and contains queries. 
    │   │   ├── drizzle.ts      # The primary database file. It establishes our DB connection and contains queries. 
    ├── env.example             # A sample .env file that can be used as the basis for configuring the application.
    ├── README.md               # You are here!
    ├── openapi.yaml            # An OpenAPI specification that describes how the application's API will behave.

Running

Out of the box

  1. docker-compose --profile next up

Local dev

  1. Create a new .env file: cp .env.example .env
  2. Start the Poostgres and SwaggerUI services: docker-compose --profile dev up
  3. Generate migrations and apply them: npm run db:generate && npm run db:migrate ( Should only need to be run once )
  4. (Optional) Seed the database: npm run db:seed (Should only be run once)
  5. Start the app in dev mode with watch, to hot reload code. npm run dev

Usage

About

App for Cenith GridGame take home

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors