From 09e0568ecf7fd71d95608f3a53579c3ecaab665f Mon Sep 17 00:00:00 2001 From: Phil Harper Date: Wed, 20 Dec 2023 19:15:43 +0000 Subject: [PATCH] Allow any number of hearts and stop duplicate cards --- components/hearts.tsx | 9 ++++++--- lib/items.ts | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/components/hearts.tsx b/components/hearts.tsx index d1eec6b..5b9b04e 100644 --- a/components/hearts.tsx +++ b/components/hearts.tsx @@ -34,11 +34,14 @@ interface Props { export default function Hearts(props: Props) { const { lives } = props; + const elements: JSX.Element[] = []; + for (let counter = 1; counter <= lives; counter++) { + elements.push(= counter} />); + } + return (
- = 1} /> - = 2} /> - = 3} /> + {elements}
); } diff --git a/lib/items.ts b/lib/items.ts index b459d69..fb75809 100644 --- a/lib/items.ts +++ b/lib/items.ts @@ -20,6 +20,11 @@ export function getRandomItem(deck: Item[], played: Item[]): Item { if (tooClose(candidate, played)) { return false; } + for (const playedItem of played) { + if (playedItem.id === candidate.id) { + return false; + } + } return true; });