GithubHelp home page GithubHelp logo

bowling-api's Introduction

Bowling API

A set of Javascript APIs for scoring a bowling game.

Requirements

The modules contained with this are ECMAScript 6 modules and as such, requires node ^14.0.0 and npm ^6.0.0

Classes

Game

Manage the scoring for a complete bowling game. Automatically tracks frames and records each roll and any spare or strike rolls into previous frames. (Note: there is currently no methods for editing frame rolls, so if you make a mistake...)

Example:

const game = new Game('Tom Dickman');
game.roll(4).roll(4);
console.log(game.score()) // 8
game.roll(10);
game.roll(7);
console.log(game.score()) // 32

Constructor


new Game(String: playerName)

Parameters

  • playerName: the name of the player this bowling game is for.

Methods


Game.roll(Number: noOfPins) : Game - Record the number of pins knocked over by a roll in the game.

Parameters

  • noOfPins: an integer Number between 0 and 10 (inclusive).

Returns

  • Game: the Game itself for method chaining.

Game.score() : Number - Get the current total Game score.

Returns

  • Number: The total of all recorded Frame scores within the Game.


Frame

Manage an individual frame within a bowling game.

Constructor


new Frame(Number: number)

Parameters

  • number: an integer Number between 1 and 10 (inclusive).

Methods


Frame.roll(Number: noOfPins) : Frame - Record the number of pins knocked over by a roll in the frame.

Parameters

  • noOfPins: an integer Number between 0 and 10 (inclusive).

Returns

  • Frame: the Frame itself for method chaining.

Frame.rollScore() : Number - Calculate the total score of all rolls made in this frame (excluding spare and strike rolls made in subsequent frames).

Returns

  • Number: integer total between 0 and 10.

Frame.spareRoll(Number: noOfPins) : Frame - Record the number of pins knocked over in a spare roll for Frame.

Parameters

  • noOfPins: an integer Number between 0 and 10 (inclusive).

Returns

  • Frame: the Frame itself for method chaining.

Frame.strikeRoll(Number: noOfPins) : Frame - Record the number of pins knocked over in a strike roll for Frame.

Parameters

  • noOfPins: an integer Number between 0 and 10 (inclusive).

Returns

  • Frame: the Frame itself for method chaining.

Frame.isSpare() : Boolean - Check if the Frame score constitutes a spare.

Returns

  • Boolean: true if the total across the two rolls was 10 (excluding if the Frame was a strike), false otherwise.

Frame.isStrike() : Boolean - Check if the Frame score constitutes a strike.

Returns

  • Boolean: true if the first and only roll in the Frame was a 10.

Frame.score() : Number - Get the current total Frame score.

Returns

  • Number: The total of all recorded Frame rolls and spare or strike rolls.

bowling-api's People

Contributors

tomdickman 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.