Reference Source
public class | source

Board

A WOJ board with column * row clues arranged in a grid. The top left corner is indexed at 0. Each column is a Category and each row in a category is a Clue. All categories must have the same number of clues. Each clue in the first row has Board#basePoints. Each clue in the next row equals the sum of the clue value in the prior row plus basePoints.

Constructor Summary

Public Constructor
public

constructor(columns: number, rows: number, basePoints: number)

Member Summary

Public Members
public get
public get
public get

Method Summary

Public Methods
public

editCategory(column: number, name: string)

Edit the name of a category at column index.

public

editClue(column: number, row: number, question: string, answer: string)

Edit the question and answer of a clue at column and row index.

public

Export board content to JSON board string.

public

Returns a category at the specified column.

public

getClue(column: number, row: number): Clue

Returns a clue at the specified column and row.

public

import(data: string)

Import JSON board, initializing board and setting categories and clues.

public

nextClue(column: number): Clue

Retrieve next unanswered clue in the category at column and increment cluesAnswered for that category.

public

reset()

Resets each category in the board and their cluesAnswered count to 0.

Private Methods
private

init_(columns: number, rows: number)

Initializes an empty board of size columns * rows with Clue's.

Public Constructors

public constructor(columns: number, rows: number, basePoints: number) source

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.

Public Members

public get categoryNames: string[] source

public get cluesAnswered: number source

public get complete: boolean source

Public Methods

public editCategory(column: number, name: string) source

Edit the name of a category at column index.

Params:

NameTypeAttributeDescription
column number

column index of the category.

name string

new category name.

public editClue(column: number, row: number, question: string, answer: string) source

Edit the question and answer of a clue at column and row index.

Params:

NameTypeAttributeDescription
column number

column index of the clue.

row number

row index of the clue.

question string

new question text.

answer string

new answer text.

public export(): string source

Export board content to JSON board string. See Board.import for details on JSON board structure.

Return:

string

serialized board.

public getCategory(column: number): Category source

Returns a category at the specified column.

Params:

NameTypeAttributeDescription
column number

column index of the category.

Return:

Category

category at the specified column.

public getClue(column: number, row: number): Clue source

Returns a clue at the specified column and row.

Params:

NameTypeAttributeDescription
column number

column index of the clue.

row number

row index of the clue.

Return:

Clue

clue at the specified column and row.

public import(data: string) source

Import JSON board, initializing board and setting categories and clues. Data should be a string. Use JSON.stringify if data is an object literal.

Params:

NameTypeAttributeDescription
data string

board JSON.

data.columns number

number of columns.

data.rows numnber

number of rows.

data.categories string[]

array of category names.

data.clues Object[]

array of clues, zero indexed from top left of board

data.clues.column number

column index of the clue.

data.clues.row number

row index of the clue.

data.clues.question string

new question text.

data.clues.answer string

new answer text.

See:

public nextClue(column: number): Clue source

Retrieve next unanswered clue in the category at column and increment cluesAnswered for that category. If all clues are answered, this will return undefined.

Params:

NameTypeAttributeDescription
column number

column index of the category.

Return:

Clue

the next unanswered clue.

Throw:

Error

throw error when board is complete.

public reset() source

Resets each category in the board and their cluesAnswered count to 0.

Private Methods

private init_(columns: number, rows: number) source

Initializes an empty board of size columns * rows with Clue's.

Params:

NameTypeAttributeDescription
columns number

number of columns on the board.

rows number

number of rows on the board.