Skip to content

Instantly share code, notes, and snippets.

@morintd

morintd/game.tsx Secret

Last active March 11, 2024 20:00
Show Gist options
  • Save morintd/a931698240eca5bdc7be678968c27be1 to your computer and use it in GitHub Desktop.
Save morintd/a931698240eca5bdc7be678968c27be1 to your computer and use it in GitHub Desktop.
import { GameDomainModel } from "./game.domain-model";
import { Board } from "./components";
import { useGameController } from "./game-controller";
import "./app.css";
import { GamePresenter } from "./adapters/game.presenter";
type Props = {
game: GameDomainModel.GameState;
};
const presenter = new GamePresenter();
export function Game(props: Props) {
const { game } = props;
const controller = useGameController(game, presenter);
return (
<div className="game">
<div className="game-board">
<Board
squares={controller.squares}
onClick={controller.onPlay}
status={controller.status}
/>
</div>
<div className="game-info">
<ol>
{controller.moves.map(({ move, description }) => (
<li key={move}>
<button onClick={() => controller.onJumpTo(move)}>
{description}
</button>
</li>
))}
</ol>
</div>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment