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
Backend: .net core 3.0
IDE: Visual Studio 2019
Database: NA (no persistence layer)
- 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)
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" ] } |
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" |
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" |