diff --git a/packages/game/src/js/Game.js b/packages/game/src/js/Game.js index 3a36f34..7b36579 100644 --- a/packages/game/src/js/Game.js +++ b/packages/game/src/js/Game.js @@ -73,6 +73,34 @@ export class Game return this.state.board; } + /** + * Dumps the state of the game. + * + * @returns {IState} + * The JSON string representing the state. + */ + dump() + { + return { + turnCount: this.state.turnCount, + board: { + ...this.state.board + } + }; + } + + /** + * Loads the game from the specified {@link data `data`}. + * + * @param {IState} data + * The data to load. + */ + load(data) + { + this.state.turnCount = data.turnCount; + Object.assign(this.state.board, data.board); + } + /** * Initializes the game. */ diff --git a/packages/game/src/js/types.d.ts b/packages/game/src/js/types.d.ts index 3633da2..a2a4c52 100644 --- a/packages/game/src/js/types.d.ts +++ b/packages/game/src/js/types.d.ts @@ -12,3 +12,19 @@ type Row = CellOwner[]; * Represents a game board. */ type Board = Row[]; + +/** + * Represents the state of a game. + */ +interface IState +{ + /** + * The number of rounds that have been played. + */ + turnCount: number; + + /** + * The board of the game. + */ + board: Board; +}