Code Monkey home page Code Monkey logo

rockpaperscissors's Introduction

Implementation of RESTful API for a rock,paper,scissors game

Usage

Prerequisite

  • Maven
  • Java 8 or higher

Start the application

Through following command:

mvn clean install spring-boot:run 

Maven will install all the dependencies and followed by run the application

APIs

POST /api/v1/games
GET /api/v1/games/{id}
POST /api/v1/games/{id}/play

Examples

Create Game

POST http://localhost:8080/api/v1/games
    Request: 
    {
    	"winningScore": 3, //optional default:3
    	"gameType": "COMPUTER" //optional default:COMPUTER
    }
    Response: 
    {
        "status": "SUCCESS",
        "errorMessage": null,
        "id": "493e74e4-8edd-4e50-97f6-5c739a86d86b",
        "winningScore": 3,
        "gameType": "COMPUTER",
        "gameStatus": "IN_PROGRESS"
    }

Retrieve Game

GET http://localhost:8080/api/v1/games/{id}  
    Response: 
    {
        "status": "SUCCESS",
        "errorMessage": null,
        "id": "493e74e4-8edd-4e50-97f6-5c739a86d86b",
        "winningScore": 3,
        "gameType": "COMPUTER",
        "gameStatus": "IN_PROGRESS"
    }
    Fail Response example:
    {
        "status": "FAILURE",
        "errorMessage": "Game can not be found with id: 493e74e4-8edd-4e50-97f6-5c739a86d"
    }

Play a Move

POST http://localhost:8080/api/v1/games/{id}/play
    Request:
        { 
        	"move":"ROCK"
        }
    Response: 
        {
            "status": "SUCCESS",
            "errorMessage": null,
            "gameId": "493e74e4-8edd-4e50-97f6-5c739a86d86b",
            "roundDto": {
                "roundResult": "BREAK",  //DRAW or BREAK
                "roundWinner": {
                    "type": "PERSON",
                    "score": 1
                }
            },
            "player1": {
                "type": "PERSON",
                "lastMove": "ROCK",
                "score": 1
            },
            "player2": {
                "type": "COMPUTER",
                "lastMove": "SCISSORS",
                "score": 0
            },
            "gameStatus": "IN_PROGRESS",
            "winnerOfTheGame": null
        }
        
* GameStatus will be 'FINISHED' after winning score is reached by any one of the players
    Finished Game Response:
        {
            "status": null,
            "errorMessage": null,
            "gameId": "493e74e4-8edd-4e50-97f6-5c739a86d86b",
            "roundDto": {
                "roundResult": "BREAK",
                "roundWinner": {
                    "type": "PERSON",
                    "score": 3
                }
            },
            "player1": {
                "type": "PERSON",
                "move": "ROCK",
                "score": 3
            },
            "player2": {
                "type": "COMPUTER",
                "move": "SCISSORS",
                "score": 2
            },
            "gameStatus": "FINISHED",
            "winnerOfTheGame": {
                "type": "PERSON",
                "score": 3
            }
        } 
        
     Fail Response Example:
        {
            "status": "FAILURE",
            "errorMessage": "Game with idd814c209-71cb-46c7-bcff-a876a8263402is already finished. You cannot play another move at this game."
        }   

rockpaperscissors's People

Contributors

apollo629 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.