Reference Source
public class | source

Game

The WOJ game. Supports creation of board, wheel, and players which are used to track game play. This class should be used to create games and add rounds to ensure proper functionality.

Example:

let game = new Game();

// create default boards
let data = [data1, data2];

for(let i=0; i<data.length; i++){
     let round = game.addRound();
     round.board.import(JSON.stringify(data[i]));
     round.wheel.assignSectors();
     round.wheel.randomizeSectors();    
}

// edit board content if needed
round = game.getRound(0);
let clue = round.board.getCategory(1).clues[2];
clue.question = "What is the oldest soft drink in America?";
clue.answer = "Dr. Pepper.";

// start game
game.addPlayer("John");
game.addPlayer("Jane");

// start first round
round = game.getRound(0);
round.start();

// player spins
console.log(round.currentPlayer);
let spin = round.wheel.spin();
console.log(spin);
console.log(round.complete);

Member Summary

Public Members
public
public
public

rounds: Rounds[]

public get

Stats for the game.

Method Summary

Public Methods
public

Add a player to the game.

public

addRound(columns: number, rows: number, basePoints: number): id

Add and initialize a game round with an empty wheel and board.

public

editPlayer(id: number, name: string)

Retrieve and edit a player.

public

Retrieve array of players ordered by top score.

public

Retrieve a player.

public

getRound(id: Round): *

Retrieve a game round by id.

Public Members

public currentRound: number source

public players: Player[] source

public rounds: Rounds[] source

public get stats: GameStats: * source

Stats for the game.

Return:

GameStats

current stats for the game.

Public Methods

public addPlayer(name: string): number source

Add a player to the game. Players are assigned an ID starting with 0 and incrementing by 1.

Params:

NameTypeAttributeDescription
name string

the players name.

Return:

number

auto assigned player ID.

public addRound(columns: number, rows: number, basePoints: number): id source

Add and initialize a game round with an empty wheel and board. Rounds are assigned an ID starting with 0 and incrementing by 1.

Params:

NameTypeAttributeDescription
columns number
  • optional
  • default: 6

number of columns on the board.

rows number
  • optional
  • default: 5

number of rows on the board.

basePoints number
  • optional
  • default: 200

point value of each clues in the first row.

Return:

id

auto assigned round ID.

public editPlayer(id: number, name: string) source

Retrieve and edit a player.

Params:

NameTypeAttributeDescription
id number

the players id number, player one is id: 0.

name string

the players name.

public getLeaderBoard(): Player[] source

Retrieve array of players ordered by top score.

Return:

Player[]

array of players ordered by total score.

public getPlayer(id: number): Player source

Retrieve a player.

Params:

NameTypeAttributeDescription
id number

the players id number.

Return:

Player

the player at index number.

public getRound(id: Round): * source

Retrieve a game round by id.

Params:

NameTypeAttributeDescription
id Round

the rounds id number, round one is id: 0.

Return:

*