Skip to content

mahi2t/Battleship-State-Tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Battleship State Tracker

This is a Battleship State Tracking API which enables to simulate a battleship game with provision to

  • Create board
  • Add board to ship
  • Attack on the ship

Technical Details

Backend: .net core 3.0
IDE: Visual Studio 2019
Database: NA (no persistence layer)

Build

  • Open the solution in VS 2019
  • Restore the nuget packages.
  • Build and run the application which launches the localhost url
    http://localhost:26476/api/tracker
  • Open the resclient like Postman or Insomnia and provide the details calling the required endpoint.
    (refer to below section for endpoint detais)

API endpoint details

CreateBoard Endpoint

URL: ~/api/tracker/createboard
Description: Creates a N X N battleboard with the given size(N)
Request Method: POST
Request Body:

	{
		"size" : 10
	}

Response :

Status Code Response Message
201 NA
200 10X10 board already created
400 "errors": { "Size": [ "Value should be between 1 and 50" ] }

AddShip Endpoint

URL: ~/api/tracker/addship
Description: Adds ship to the board if the input is valid and ship is not already present on board
Request Method: POST
Request Body:

	{ 
	   "orientation":"horizontal",
	   "position":{ 
	      "x":8,
	      "y":8
	   },
	   "length":3
	}

Possible values for Orientation:

  • horizontal
  • vertical

Response :

Status Code Response Message
200 - Board is not created yet, please create board.
- Cannot place the ship outside the board.
- Ship is already placed on board.
- Cell is already occupied by ship.
- "EMPTY response when valid"
400 "Invalid field details"

Attack Endpoint

URL: ~/api/tracker/attack
Description: Attack the ship by providing the coordinates, if a ship exists in that position then responds with a "HIT" else "MISS". When the hit is the last block of the ship then "Hit, Ship drowned" is returned
Request Method: POST
Request Body:

	{
		"x":10,
		"y":8
	}

Response :

Status Code Response Message
200 - Hit
- Miss
- Hit, Ship drowned.
400 "Invalid field details"

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages