feature : add id to MancalaGame
This commit is contained in:
parent
167bea0c82
commit
8859e63296
@ -5,8 +5,8 @@ import { GRLastStoneInBank } from './game_rules/GRLastStoneInBank';
|
|||||||
import { GRLastStoneInEmptyPit } from './game_rules/GRLastStoneInEmptyPit';
|
import { GRLastStoneInEmptyPit } from './game_rules/GRLastStoneInEmptyPit';
|
||||||
|
|
||||||
export class CommonMancalaGame extends MancalaGame {
|
export class CommonMancalaGame extends MancalaGame {
|
||||||
constructor(player1Id: string, player2Id: string) {
|
constructor(id: string, player1Id: string, player2Id: string) {
|
||||||
super(new CommonBoard(), player1Id, player2Id, player1Id, [
|
super(id, new CommonBoard(), player1Id, player2Id, player1Id, [
|
||||||
new GRLastStoneInEmptyPit(),
|
new GRLastStoneInEmptyPit(),
|
||||||
new GRLastStoneInBank(),
|
new GRLastStoneInBank(),
|
||||||
new GRClearBoardAtEnd()
|
new GRClearBoardAtEnd()
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { GameRule } from './GameRule';
|
|||||||
export type GameState = 'initial' | 'playing' | 'ended';
|
export type GameState = 'initial' | 'playing' | 'ended';
|
||||||
|
|
||||||
export class MancalaGame {
|
export class MancalaGame {
|
||||||
|
id: string;
|
||||||
board: Board;
|
board: Board;
|
||||||
player1Id: string;
|
player1Id: string;
|
||||||
player2Id: string;
|
player2Id: string;
|
||||||
@ -12,6 +13,7 @@ export class MancalaGame {
|
|||||||
gameRules: GameRule[];
|
gameRules: GameRule[];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
id: string,
|
||||||
board: Board,
|
board: Board,
|
||||||
player1Id: string,
|
player1Id: string,
|
||||||
player2Id: string,
|
player2Id: string,
|
||||||
@ -19,6 +21,7 @@ export class MancalaGame {
|
|||||||
gameRules: GameRule[],
|
gameRules: GameRule[],
|
||||||
state: GameState = 'initial'
|
state: GameState = 'initial'
|
||||||
) {
|
) {
|
||||||
|
this.id = id;
|
||||||
this.board = board;
|
this.board = board;
|
||||||
this.player1Id = player1Id;
|
this.player1Id = player1Id;
|
||||||
this.player2Id = player2Id;
|
this.player2Id = player2Id;
|
||||||
@ -193,6 +196,7 @@ export class MancalaGame {
|
|||||||
|
|
||||||
public static createFromMancalaGame(mancalaGame: MancalaGame): MancalaGame {
|
public static createFromMancalaGame(mancalaGame: MancalaGame): MancalaGame {
|
||||||
return new MancalaGame(
|
return new MancalaGame(
|
||||||
|
mancalaGame.id,
|
||||||
new Board(
|
new Board(
|
||||||
mancalaGame.board.playerPitCount,
|
mancalaGame.board.playerPitCount,
|
||||||
mancalaGame.board.initialStoneCountInPits,
|
mancalaGame.board.initialStoneCountInPits,
|
||||||
|
|||||||
@ -8,7 +8,7 @@ function createGame(): MancalaGame {
|
|||||||
const board = new Board(6, 4);
|
const board = new Board(6, 4);
|
||||||
const player1Id = '0';
|
const player1Id = '0';
|
||||||
const player2Id = '1';
|
const player2Id = '1';
|
||||||
const game = new MancalaGame(board, player1Id, player2Id, player1Id, [
|
const game = new MancalaGame('0', board, player1Id, player2Id, player1Id, [
|
||||||
new GRLastStoneInEmptyPit(),
|
new GRLastStoneInEmptyPit(),
|
||||||
new GRLastStoneInBank(),
|
new GRLastStoneInBank(),
|
||||||
new GRClearBoardAtEnd()
|
new GRClearBoardAtEnd()
|
||||||
|
|||||||
@ -8,7 +8,7 @@ function createGame(): MancalaGame {
|
|||||||
const board = new Board(6, 4);
|
const board = new Board(6, 4);
|
||||||
const player1Id = '0';
|
const player1Id = '0';
|
||||||
const player2Id = '1';
|
const player2Id = '1';
|
||||||
const game = new MancalaGame(board, player1Id, player2Id, player1Id, [
|
const game = new MancalaGame('0', board, player1Id, player2Id, player1Id, [
|
||||||
new GRLastStoneInEmptyPit(),
|
new GRLastStoneInEmptyPit(),
|
||||||
new GRLastStoneInBank(),
|
new GRLastStoneInBank(),
|
||||||
new GRClearBoardAtEnd()
|
new GRClearBoardAtEnd()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user