UNPKG

tmemory

Version:

A terminal-based Memory card game built with React Ink. Features multiple grid sizes, AI opponent, and high scores.

15 lines (14 loc) 984 B
import { Box } from 'ink'; import React from 'react'; import { CardWrapper } from "../../../components/common/Card/index.js"; import { useGame } from "../../../context/GameContext/index.js"; export const GameGrid = () => { const { state } = useGame(); const { grid, gridDimension, flippedIndices, matchedIndices, selectedIndex, } = state; return (React.createElement(Box, { flexDirection: "column", alignItems: "center", flexGrow: 1 }, Array.from({ length: gridDimension.rows }, (_, row) => (React.createElement(Box, { key: row, gap: 1 }, Array.from({ length: gridDimension.cols }, (_, col) => { const index = row * gridDimension.cols + col; const card = grid[index]; return (React.createElement(Box, { key: col }, card && (React.createElement(CardWrapper, { card: card, gridDimension: gridDimension, faceUp: flippedIndices.includes(index) || matchedIndices.includes(index), selected: selectedIndex === index })))); })))))); };