import { Bank, MancalaGame, Pit } from "mancala.js"; import * as React from "react"; import { FunctionComponent, useState } from "react"; import { Context } from "../context"; import BoardViewModel from "../viewmodel/BoardViewModel"; import PitViewModel from "../viewmodel/PitViewModel"; const BallView: FunctionComponent<{ color: string }> = ({ color }) => { return (
); }; function range(size: number) { var ans = []; for (let i = 0; i < size; i++) { ans.push(i); } return ans; } const HoleView: FunctionComponent<{ pitViewModel: PitViewModel; onClick: () => void; }> = ({ pitViewModel, onClick }) => { const balls = [...range(pitViewModel.stoneCount)].map((i) => ( )); return (
{balls}
); }; const StoreView: FunctionComponent<{ context: Context; pitViewModel: PitViewModel; gridColumn: string; gridRow: string; }> = ({ context, pitViewModel, gridColumn, gridRow }) => { const balls = [...range(pitViewModel.stoneCount)].map((i) => ( )); return (
{balls} {balls.length}
); }; const BoardView: FunctionComponent<{ game?: MancalaGame; context: Context; boardId: string; boardViewModel: BoardViewModel; userKey: string; onHoleSelect: (index: number, hole: Pit) => void; }> = ({ game, context, boardId, boardViewModel, userKey, onHoleSelect }) => { const createPitView = (pitViewModel: PitViewModel, onClick: () => void) => { return ; }; const player1Pits = game?.board.player1Pits.map((pit) => { const pitViewModel = boardViewModel.pits[pit.index]; return createPitView(pitViewModel, () => { if (game.turnPlayerId === game.player1Id) onHoleSelect(game.board.player1Pits.indexOf(pit), pit); }); }); const player2Pits = game!!.board.player2Pits.map((pit) => { const pitViewModel = boardViewModel.pits[pit.index]; return createPitView(pitViewModel, () => { if (game.turnPlayerId === game.player2Id) onHoleSelect(game.board.player2Pits.indexOf(pit), pit); }); }); const isUserTurn = game.checkIsPlayerTurn(userKey); const theme = context.themeManager.theme; const player1BankViewModel = boardViewModel.pits[game.board.player1BankIndex()]; const player2BankViewModel = boardViewModel.pits[game.board.player2BankIndex()]; const player1Bank = ( ); const player2Bank = ( ); return (
{userKey === game.player2Id ? ( <> {player1Pits.reverse()} {player2Pits} ) : ( <> {player2Pits.reverse()} {player1Pits} )}
); }; export default BoardView;