GithubHelp home page GithubHelp logo

pecavalheiro / bowling Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 80 KB

Coding example of a Bowling Game using traditional scoring rules. Details in https://en.wikipedia.org/wiki/Ten-pin_bowling

Ruby 99.61% HTML 0.39%

bowling's Introduction

Bowling Game

Coding example of a Bowling Game using traditional scoring rules. Details in https://en.wikipedia.org/wiki/Ten-pin_bowling

Configuration

Dependencies

Installation

# Clone the repo
git clone https://github.com/pecavalheiro/bowling

# Install the dependencies
bundle install

# Database steps
rake db:create
rake db:migrate

Running

To execute the project, run the following command in your terminal:

bundle exec rails s

This will run the web app and allow access to it in localhost:3000

Workflow and Endpoints

Create a new game

Used to start a new game with 1 or 2 players. Only the first player name is required, the second is optional (in case of a single player game).

Example usage:

→ curl -X POST http://localhost:3000/games --data '{"game": { "player_1": "John Doe", "player_2": "Jane Doe"  } }' --header "Content-Type: application/json"

Status-code 201 (Created)
(empty body)

New ball throw

Used to throw a new ball in the current game. Can be attach to a sensor that reads the amount of knocked pins at every round.

Example usage:

→  curl -X POST -v http://localhost:3000/game/throws --data '{"knocked_pins": 5 }' --header "Content-Type: application/json"

Status-code 200 (Ok)
(empty body)

Current game status

Used to fetch the status of the current game.

Example usage:

→  curl -X GET -v http://localhost:3000/games --header "Content-Type: application/json"

Status-code 200 (Ok)

{
	"data": {
		"id": "14",
		"type": "game",
		"attributes": {
			"player_1_score": 10,
			"player_2_score": 0
		},
		"relationships": {
			"frames": {
				"data": [{
					"id": "211",
					"type": "frame"
				}, {
					"id": "212",
					"type": "frame"
				}, {
					"id": "213",
					"type": "frame"
				}, {
					"id": "214",
					"type": "frame"
				}, {
					"id": "215",
					"type": "frame"
				}, {
					"id": "216",
					"type": "frame"
				}, {
					"id": "217",
					"type": "frame"
				}, {
					"id": "218",
					"type": "frame"
				}, {
					"id": "219",
					"type": "frame"
				}, {
					"id": "220",
					"type": "frame"
				}, {
					"id": "221",
					"type": "frame"
				}, {
					"id": "222",
					"type": "frame"
				}, {
					"id": "223",
					"type": "frame"
				}, {
					"id": "224",
					"type": "frame"
				}, {
					"id": "225",
					"type": "frame"
				}, {
					"id": "226",
					"type": "frame"
				}, {
					"id": "227",
					"type": "frame"
				}, {
					"id": "228",
					"type": "frame"
				}, {
					"id": "229",
					"type": "frame"
				}, {
					"id": "230",
					"type": "frame"
				}]
			}
		}
	},
	"included": [{
		"id": "211",
		"type": "frame",
		"attributes": {
			"number": 1,
			"player_id": 1,
			"ball_1": 10,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 10
		}
	}, {
		"id": "212",
		"type": "frame",
		"attributes": {
			"number": 2,
			"player_id": 1,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "213",
		"type": "frame",
		"attributes": {
			"number": 3,
			"player_id": 1,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "214",
		"type": "frame",
		"attributes": {
			"number": 4,
			"player_id": 1,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "215",
		"type": "frame",
		"attributes": {
			"number": 5,
			"player_id": 1,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "216",
		"type": "frame",
		"attributes": {
			"number": 6,
			"player_id": 1,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "217",
		"type": "frame",
		"attributes": {
			"number": 7,
			"player_id": 1,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "218",
		"type": "frame",
		"attributes": {
			"number": 8,
			"player_id": 1,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "219",
		"type": "frame",
		"attributes": {
			"number": 9,
			"player_id": 1,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "220",
		"type": "frame",
		"attributes": {
			"number": 10,
			"player_id": 1,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "221",
		"type": "frame",
		"attributes": {
			"number": 1,
			"player_id": 2,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "222",
		"type": "frame",
		"attributes": {
			"number": 2,
			"player_id": 2,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "223",
		"type": "frame",
		"attributes": {
			"number": 3,
			"player_id": 2,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "224",
		"type": "frame",
		"attributes": {
			"number": 4,
			"player_id": 2,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "225",
		"type": "frame",
		"attributes": {
			"number": 5,
			"player_id": 2,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "226",
		"type": "frame",
		"attributes": {
			"number": 6,
			"player_id": 2,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "227",
		"type": "frame",
		"attributes": {
			"number": 7,
			"player_id": 2,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "228",
		"type": "frame",
		"attributes": {
			"number": 8,
			"player_id": 2,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "229",
		"type": "frame",
		"attributes": {
			"number": 9,
			"player_id": 2,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}, {
		"id": "230",
		"type": "frame",
		"attributes": {
			"number": 10,
			"player_id": 2,
			"ball_1": null,
			"ball_2": null,
			"ball_extra": null,
			"total_points": 0
		}
	}]
}

Assumptions and expected behaviors

  • When a game does not exist, the app will return code 404 (Not found) when trying to throw a ball
  • When the game has already ended, any new throws will result in a response code 403 (Forbidden)

bowling's People

Contributors

pecavalheiro avatar dependabot[bot] avatar

Watchers

James Cloos avatar  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.