/mines-sweeper-api

RESTful API for the classic game & API client library - 5 hours test exercise

Primary LanguageRuby

login-app logo

MineSweeper API & JS Library

RESTful API for the classic game & API client library - 5 hours test exercise

Features implemented

MineSweeper JS Library

  • createGame function. Parameters: (rows, columns, mines)
  • getGame function. Parameters: (gameId)
  • drawGame function. Parameters: (gameData)
  • updateSquare function. Parameters: (gameId, row, column, action)

MineSweeper API

  • Current API Version available: V1
  1. Games CREATE endpoint: POST /games. Params: (rows, columns, mines)

  2. a) On success returns:

{ id: 2, rows: 10, columns: 10, mines: 5, mines_positions: Array(5) ...
  1. b) On failure returns:
{ status: 400, message: "Game can't be created", errors: [...] }
  1. Games SHOW endpoint: GET /games/:id. Params: (id)

  2. a) On sucess returns:

{ id: 2, rows: 10, columns: 10, mines: 5, mines_positions: Array(5) ...
  1. b) On failure returns:
{ status: 404, message: "Game not found" }
  1. Squares UPDATE endpoint: PUT /games/:game_id/squares. Params: (game_id, row, column, action). game_id must belong to an existing Game. row must be an integer. column must be an integer. action must be one of these 3 values: reveal, question_mark or red_flag.

Development

Clone repository:

$ git clone git@github.com:juanroldan1989/mines-sweeper-api.git

Install gems:

$ bundle install

Setup DB:

$ cp config/database.yml.sample config/database.yml
$ rake db:create db:migrate

Run server:

$ rails s

Live app

Testing steps

  1. Access testing area where JS Library will be loaded within the page: https://mines-sweeper-api.herokuapp.com/testing

  2. Create a game:

// inside browser's console

MineSweeper.createGame(10,10,4);
  1. Fetch a game to play using the id returned on the previous step:
// inside browser's console

MineSweeper.getGame(1);
  1. Start clicking around and revealing squares : )
// OR you can use the JS library from inside browser's console

MineSweeper.updateSquare(1, 10, 8, 'reveal');
MineSweeper.updateSquare(1, 5, 2, 'question_mark');
  1. a) Square revealed doesn't contain a bomb, phew !
  2. b) Square revealed contains a bomb! (game over, clicking around doesn't make any changes in the server side)
  3. c) Squares can be flagged with a question mark (by clicking with the right button mouse).

Enjoy !