Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tic-tac-toe-app/src/components/board/Board.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { SquareValue } from "../square/Square";
import { Mark } from "../square/Square";
import { BoardRaw } from "./BoardRaw";

type BoardProps = {
rawSize: number;
columnSize: number;
squares: SquareValue[];
squares: Mark[];
onClick: (i: number) => void;
};

Expand Down
8 changes: 4 additions & 4 deletions tic-tac-toe-app/src/components/board/BoardRaw.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Square, SquareValue } from "../square/Square";
import { Square, Mark } from "../square/Square";

type BoardRawProps = {
rawIndex: number;
columnSize: number;
squares: SquareValue[];
squares: Mark[];
onClick: (i: number) => void;
};

Expand All @@ -13,11 +13,11 @@ export const BoardRaw = (props: BoardRawProps) => {

return (
<div className="board-row">
{props.squares.slice(start, end).map((value, index) => {
{props.squares.slice(start, end).map((mark, index) => {
return (
<Square
key={index}
value={value}
mark={mark}
onClick={() => props.onClick(start + index)}
/>
);
Expand Down
6 changes: 3 additions & 3 deletions tic-tac-toe-app/src/components/game/Game.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useCallback, useReducer } from "react";
import { Board } from "../board/Board";
import { SquareValue } from "../square/Square";
import { Mark } from "../square/Square";
import { GameInfo } from "./GameInfo";
import { GameState, gameReducer } from "../../reducers/gameReducer";

export type GameHistory = {
squares: SquareValue[];
squares: Mark[];
};

const initialHistory: GameHistory[] = [
Expand All @@ -26,7 +26,7 @@ export const Game = () => {
const columnSize = 3;

const handleClick = useCallback((squareIndex: number) => {
dispatch({ type: "add_value", squareIndex: squareIndex });
dispatch({ type: "add_mark", squareIndex: squareIndex });
}, []);

const jumpTo = useCallback((step: number) => {
Expand Down
6 changes: 3 additions & 3 deletions tic-tac-toe-app/src/components/square/Square.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export type SquareValue = "X" | "O" | null;
export type Mark = "X" | "O" | null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

良いと思います 👍
僕もこうしました
後で若干nullを分けたくなるかもですがそんなに大した話ではないです

type SquareProps = {
value: SquareValue;
mark: Mark;
onClick: () => void;
};

export const Square = (props: SquareProps) => {
return (
<button className="square" onClick={props.onClick}>
{props.value}
{props.mark}
</button>
);
};
8 changes: 4 additions & 4 deletions tic-tac-toe-app/src/reducers/gameReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export type GameState = {
xIsNext: boolean;
};
export type GameAction =
| AddValueAction
| AddmarkAction
| JumpHistoryAction

type AddValueAction = {
type: "add_value";
type AddmarkAction = {
type: "add_mark";
squareIndex: number;
}

Expand All @@ -26,7 +26,7 @@ export const gameReducer: React.Reducer<GameState, GameAction> = (
action: GameAction
) => {
switch (action.type) {
case "add_value": {
case "add_mark": {
const updatedHistory = state.history.slice(0, state.stepNumber + 1);
Comment thread
ookura-mf marked this conversation as resolved.
const current = updatedHistory[state.stepNumber];
const squares = current.squares.slice();
Expand Down
4 changes: 2 additions & 2 deletions tic-tac-toe-app/src/usecases/CalculateWinner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SquareValue } from "../components/square/Square";
import { Mark } from "../components/square/Square";

export const calculateWinner = (squares: Array<SquareValue>) => {
export const calculateWinner = (squares: Array<Mark>) => {
const lines = [
[0, 1, 2],
[3, 4, 5],
Expand Down