Home Reference Source Repository
import Darts501Game from 'darts-scorer-core/src/games/501.js'
public class | source

Darts501Game

Extends:

DartsBaseGame → Darts501Game

Class representing a 501 Game

Constructor Summary

Public Constructor
public

constructor(players: Player[], options: Object)

Initializes a new instance of the Darts501Game class.

Member Summary

Public Members
public get
public get
public get

Determines whether option doubleIn is set to true or false.

public get

Determines whether option doubleOut is set to true or false.

public get

Method Summary

Public Methods
public

getCheckoutHint(points: number, leftThrows: number): Array

Calculates step-by-step throws to check-out in the same round.

public

Calculates total points for specific player.

public

Calculates points for specific round.

public

throw(num: number, multiplier: number): Throw

Represents single throw.

Inherited Summary

From class DartsBaseGame
public get
public get
public get
public get

players: Player[]: *

public get
public

addPlayer(player: Player)

Adds a player to the game.

public

addPlayers(players: Player[])

Add multiple players to the game.

public

Invalidates specific round.

public

invalidateThrow(dartsThrow: Throw)

Invalidates specific throw.

public

Sets currentPlayer to the next one.

public

Creates new instance of the Round for each player.

public
public

throw(num: number, multiplier: number): Throw

Represents single throw.

public

Public Constructors

public constructor(players: Player[], options: Object) source

Initializes a new instance of the Darts501Game class.

Override:

DartsBaseGame#constructor

Params:

NameTypeAttributeDescription
players Player[]

An array of players.

options Object
  • optional
  • default: {}

The options object

Example:

// Creating the new instance
var game = new Darts501Game([new Player({name: 'Player 1'}), new Player({name: 'Player 2'})]);

Public Members

public get currentPlayerTotalPoints: number: * source

Return:

number

Calculates total points for currentPlayer

public get currentRoundPoints: number: * source

Return:

number

Calculates points for currentRound

public get doubleIn: boolean: * source

Determines whether option doubleIn is set to true or false.

Return:

boolean

If true it will affect game specific logic.

public get doubleOut: boolean: * source

Determines whether option doubleOut is set to true or false.

Return:

boolean

If true it will affect game specific logic.

public get startingPoints: Number: * source

Return:

Number

Points that game starts with.

Public Methods

public getCheckoutHint(points: number, leftThrows: number): Array source

Calculates step-by-step throws to check-out in the same round.

Params:

NameTypeAttributeDescription
points number

Total number of points left.

leftThrows number

Number of throws.

Return:

Array

Array of possible throws as string.

public getPointsByPlayer(player: Player): number source

Calculates total points for specific player.

Params:

NameTypeAttributeDescription
player Player

Instance of the Player class.

Return:

number

Total points.

public getPointsByRound(round: Round): number source

Calculates points for specific round.

Params:

NameTypeAttributeDescription
round Round

Round instance.

Return:

number

Points for round.

public throw(num: number, multiplier: number): Throw source

Represents single throw.

Override:

DartsBaseGame#throw

Params:

NameTypeAttributeDescription
num number

Number between 0 and 20 plus 25 (bull)

multiplier number
  • optional
  • default: 1

Multiplier is between 1 and 3 for all of the numbers but 25 (which has only x2 multiplier).

Return:

Throw

Throw instance.