Skip to content

Commit

Permalink
feat: 3-card waste implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Lewiscowles1986 committed Sep 15, 2024
1 parent 38c4067 commit fd863a9
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions components/klondike-solitaire.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ export function KlondikeSolitaireComponent() {
) : 'bg-blue-500'} flex items-center justify-center`}>
{card.faceUp ? `${card.rank}${card.suit}` : ''}
</div>
);
);
const visibleWasteCards = waste.slice(0, gameMode === '3-card' ? 3: 1).reverse();

return (
<CardGame className="w-full max-w-4xl mx-auto mt-8 p-4" onKeyDown={handleKeyPress} tabIndex={0}>
Expand All @@ -233,9 +234,9 @@ export function KlondikeSolitaireComponent() {
onClick={drawCards}>
{deck.length > 0 ? deck.length : 'R'}
</div>
{waste.slice(0, gameMode === '3-card' ? 3: 1).map((wasteCard, k) => (
{visibleWasteCards.map((wasteCard, k) => (
<div className="w-10 h-14" key={k}>
{renderCard(wasteCard, selectedWasteCard)}
{renderCard(wasteCard, selectedWasteCard && (visibleWasteCards.length && wasteCard == visibleWasteCards.at(-1) || false))}
</div>
))}
</div>
Expand Down Expand Up @@ -270,6 +271,21 @@ export function KlondikeSolitaireComponent() {
)}
</div>
{false && (
<div className="mt-4">
<p>Waste cards</p>
{waste.map((wasteCard, wasteCardIndex) => (
<div key={wasteCardIndex}>
{renderCard(
wasteCard,
visibleWasteCards.map(
(card: Card) => `${card.rank}-${card.suit}`
).includes(`${wasteCard.rank}-${wasteCard.suit}`)
)}
</div>
))}
</div>
)}
{false && (
<div className="mt-4">
<p>Selected cards</p>
{selectedCards.map((selectedCard, selectedCardIndex) => (
Expand Down

0 comments on commit fd863a9

Please sign in to comment.