Move board and player to the lib folder

This commit is contained in:
2019-10-15 19:43:17 +02:00
parent ed39569828
commit effba59e0f
9 changed files with 39 additions and 38 deletions

View File

@@ -3,7 +3,7 @@ import { Action } from 'redux';
import { connect } from 'react-redux';
import styled from 'styled-components';
import Board from './components/Board';
import { Player } from './types/Player';
import { Player, Winner } from './lib/Player';
import { actions, GameState } from './redux/game';
import GlobalStyle from './theming/GlobalStyle';

View File

@@ -3,9 +3,9 @@ import { connect } from 'react-redux';
import { Action } from 'redux';
import styled from 'styled-components';
import Cell from './Cell';
import { Player } from '../types/Player';
import { Player } from '../lib/Player';
import { actions, IGameState } from '../redux/game';
import { Board } from '../types/Board';
import { Board } from '../lib/Board';
const Table = styled.table`
border: 0;

View File

@@ -1,7 +1,7 @@
import React from 'react';
import styled from 'styled-components';
import { Cell, empty } from '../types/Board';
import { Player } from '../types/Player';
import { Cell, empty } from '../lib/Board';
import { Player } from '../lib/Player';
export interface Props {
value: Cell;

14
src/lib/Board.ts Normal file
View File

@@ -0,0 +1,14 @@
import { Player } from './Player';
export enum EmptyEnum {}
export type Empty = String & EmptyEnum;
export const empty: Empty = ('empty' as String) as Empty;
export type Cell = Empty | Player;
export type Cells = Cell[];
export type Row = Cell[];
export type Rows = Row[];
export type Board = Rows;
export const createEmptyRow = (): Row => [empty, empty, empty];
export const createEmptyBoard = (): Board => [createEmptyRow(), createEmptyRow(), createEmptyRow()];

16
src/lib/Player.ts Normal file
View File

@@ -0,0 +1,16 @@
export enum Player {
X = 'X',
O = 'O',
}
enum TieEnum {}
type Tie = String & TieEnum;
export const tie: Tie = ('tie' as String) as Tie;
enum UndeterminedEnum {}
type Undetermined = String & UndeterminedEnum;
export const undetermined: Undetermined = ('undetermined' as String) as Undetermined;
export type Winner = Player | Tie | Undetermined;
export default Player;

View File

@@ -1,5 +1,5 @@
import { Board, Cell, Cells, empty, Rows } from '../types/Board';
import { Winner } from '../types/Player';
import { Board, Cell, Cells, empty, Rows } from './Board';
import { Player, Winner, tie, undetermined } from './Player';
enum NoOneEnum {}
type INoOne = string | NoOneEnum;

View File

@@ -1,6 +1,6 @@
import { Reducer, Action, Dispatch, MiddlewareAPI } from 'redux';
import { Player, Winner, undetermined } from '../types/Player';
import { Board, createEmptyBoard, Cell, empty } from '../types/Board';
import { Player, Winner, undetermined } from '../lib/Player';
import { Board, createEmptyBoard, Cell, empty } from '../lib/Board';
import { getBoardSummary } from '../lib/scoring';
export const START_GAME = 'START_GAME';

View File

@@ -1,13 +0,0 @@
import { Player } from './Player';
export enum EmptyEnum {}
export type Empty = string & EmptyEnum;
export const empty: Empty = 'empty' as Empty;
export type Cell = Empty | Player;
export type Cells = Cell[];
export type Row = Cell[];
export type Rows = Row[];
export type Board = Rows;
export const createEmptyBoard = (): Board => [[empty, empty, empty], [empty, empty, empty], [empty, empty, empty]];

View File

@@ -1,16 +0,0 @@
export enum Player {
X = 'X',
O = 'O',
}
enum TieEnum {}
type Tie = string | TieEnum;
export const tie: Tie = 'tie';
enum UndeterminedEnum {}
type Undetermined = string | UndeterminedEnum;
export const undetermined: Undetermined = 'undetermined';
export type Winner = Player | Tie | Undetermined;
export default Player;