Merge pull request #1 from jhalitaksoy/feature/game-id

feature : add id to MancalaGame
This commit is contained in:
Halit Aksoy 2022-05-05 23:05:45 +03:00 committed by GitHub
commit 82dfe6fa96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 4 deletions

View File

@ -5,8 +5,8 @@ import { GRLastStoneInBank } from './game_rules/GRLastStoneInBank';
import { GRLastStoneInEmptyPit } from './game_rules/GRLastStoneInEmptyPit';
export class CommonMancalaGame extends MancalaGame {
constructor(player1Id: string, player2Id: string) {
super(new CommonBoard(), player1Id, player2Id, player1Id, [
constructor(id: string, player1Id: string, player2Id: string) {
super(id, new CommonBoard(), player1Id, player2Id, player1Id, [
new GRLastStoneInEmptyPit(),
new GRLastStoneInBank(),
new GRClearBoardAtEnd()

View File

@ -4,6 +4,7 @@ import { GameRule } from './GameRule';
export type GameState = 'initial' | 'playing' | 'ended';
export class MancalaGame {
id: string;
board: Board;
player1Id: string;
player2Id: string;
@ -12,6 +13,7 @@ export class MancalaGame {
gameRules: GameRule[];
constructor(
id: string,
board: Board,
player1Id: string,
player2Id: string,
@ -19,6 +21,7 @@ export class MancalaGame {
gameRules: GameRule[],
state: GameState = 'initial'
) {
this.id = id;
this.board = board;
this.player1Id = player1Id;
this.player2Id = player2Id;
@ -193,6 +196,7 @@ export class MancalaGame {
public static createFromMancalaGame(mancalaGame: MancalaGame): MancalaGame {
return new MancalaGame(
mancalaGame.id,
new Board(
mancalaGame.board.playerPitCount,
mancalaGame.board.initialStoneCountInPits,

View File

@ -8,7 +8,7 @@ function createGame(): MancalaGame {
const board = new Board(6, 4);
const player1Id = '0';
const player2Id = '1';
const game = new MancalaGame(board, player1Id, player2Id, player1Id, [
const game = new MancalaGame('0', board, player1Id, player2Id, player1Id, [
new GRLastStoneInEmptyPit(),
new GRLastStoneInBank(),
new GRClearBoardAtEnd()

View File

@ -8,7 +8,7 @@ function createGame(): MancalaGame {
const board = new Board(6, 4);
const player1Id = '0';
const player2Id = '1';
const game = new MancalaGame(board, player1Id, player2Id, player1Id, [
const game = new MancalaGame('0', board, player1Id, player2Id, player1Id, [
new GRLastStoneInEmptyPit(),
new GRLastStoneInBank(),
new GRClearBoardAtEnd()