Skip to content

Commit

Permalink
factoryメソッドをpublicに
Browse files Browse the repository at this point in the history
  • Loading branch information
takenaka committed Oct 13, 2021
1 parent 786750a commit e3eb71a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions src/model/othello.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ 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;
private turnPlayer: IPlayer;
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;
Expand All @@ -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'));
}
}
}
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/model/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/model/stone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
};

0 comments on commit e3eb71a

Please sign in to comment.