diff --git a/src/main.ts b/src/main.ts index aa7fa3b..e6e86c2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,7 +10,7 @@ import { StoneCreator } from './model/stone'; const board = new Board(); const io = new IO(prompt); - const othello = new Othello(board, StoneCreator, PlayerCreator, io); + const othello = new Othello(board, new StoneCreator, new PlayerCreator, io); othello.init(); } catch (e) { const _e = e as Error; diff --git a/src/model/othello.ts b/src/model/othello.ts index db2a114..51ed9d5 100644 --- a/src/model/othello.ts +++ b/src/model/othello.ts @@ -23,7 +23,7 @@ export const directions: XYDirection[] = [ export class Othello { private readonly board: IBoard; - private readonly StoneCreator: IStoneCreator; + private readonly stoneCreator: IStoneCreator; private readonly player1: IPlayer; private readonly player2: IPlayer; private readonly io: IIO; @@ -31,11 +31,11 @@ export class Othello { private pass = 0; private countStone = 0; - constructor(board: IBoard, StoneCreator: IStoneCreator, PlayerCreator: IPlayerCreator, io: IIO) { + constructor(board: IBoard, stoneCreator: IStoneCreator, playerCreator: IPlayerCreator, io: IIO) { this.board = board; - this.StoneCreator = StoneCreator; - this.player1 = PlayerCreator.factory('black', '黒'); - this.player2 = PlayerCreator.factory('white', '白'); + this.stoneCreator = stoneCreator; + this.player1 = playerCreator.factory('black', '黒'); + this.player2 = playerCreator.factory('white', '白'); this.io = io; this.turnPlayer = this.player1; @@ -51,9 +51,9 @@ export class Othello { for (let y = 0; y < 2; y++) { for (let x = 0; x < 2; x++) { if (x === y) { - this.board.putStone({ y: y + base, x: x + base }, this.StoneCreator.factory('black')); + this.board.putStone({ y: y + base, x: x + base }, this.stoneCreator.factory('black')); } else { - this.board.putStone({ y: y + base, x: x + base }, this.StoneCreator.factory('white')); + this.board.putStone({ y: y + base, x: x + base }, this.stoneCreator.factory('white')); } } } @@ -79,7 +79,7 @@ export class Othello { throw new Error('ひっくり返せる石がないよ'); } - this.board.putStone(coodinate, this.StoneCreator.factory(this.turnPlayer.color)); + this.board.putStone(coodinate, this.stoneCreator.factory(this.turnPlayer.color)); flipableStones.forEach(flipableStone => { const stone = this.board.getStone(flipableStone); stone?.flip(); diff --git a/src/model/player.ts b/src/model/player.ts index 8201d20..e82677a 100644 --- a/src/model/player.ts +++ b/src/model/player.ts @@ -19,8 +19,8 @@ export interface IPlayerCreator { factory: (color: StoneState, name: string) => IPlayer } -export const PlayerCreator: IPlayerCreator = class PlayerCreator { - public static factory = (color: StoneState, name: string) => { +export class PlayerCreator implements IPlayerCreator { + public factory = (color: StoneState, name: string) => { return new Player(color, name); } } diff --git a/src/model/stone.ts b/src/model/stone.ts index 7ac992c..0f827bd 100644 --- a/src/model/stone.ts +++ b/src/model/stone.ts @@ -29,8 +29,8 @@ export interface IStoneCreator { factory: (value: StoneState) => IStone; } -export const StoneCreator: IStoneCreator = class StoneCreator { - public static factory = (value: StoneState) => { +export class StoneCreator implements IStoneCreator { + public factory = (value: StoneState) => { return new Stone(value); }; };