about summary refs log tree commit diff stats
path: root/html/cards/script.js
diff options
context:
space:
mode:
Diffstat (limited to 'html/cards/script.js')
-rw-r--r--html/cards/script.js32
1 files changed, 23 insertions, 9 deletions
diff --git a/html/cards/script.js b/html/cards/script.js
index f8826cc..2320c37 100644
--- a/html/cards/script.js
+++ b/html/cards/script.js
@@ -53,13 +53,12 @@ const drawCardBack = card => {
 };
 
 const drawRetroPattern = card => {
-    ctx.strokeStyle = '#FF9900';
-    for (let i = 0; i < CARD_WIDTH; i += PATTERN_SIZE) {
-        for (let j = 0; j < CARD_HEIGHT; j += PATTERN_SIZE) {
-            if ((i + j) % (PATTERN_SIZE * 2) === 0) {
-                ctx.fillStyle = '#FFCC00';
-                ctx.fillRect(card.x + i, card.y + j, PATTERN_SIZE, PATTERN_SIZE);
-            }
+    const checkeredSize = 10; // Size of each square in the checkered pattern
+    for (let i = 0; i < CARD_WIDTH; i += checkeredSize) {
+        for (let j = 0; j < CARD_HEIGHT; j += checkeredSize) {
+            // Alternate colors for the checkered pattern
+            ctx.fillStyle = (Math.floor(i / checkeredSize) + Math.floor(j / checkeredSize)) % 2 === 0 ? '#FF9900' : '#FFCC00';
+            ctx.fillRect(card.x + i, card.y + j, checkeredSize, checkeredSize);
         }
     }
 };
@@ -95,7 +94,7 @@ const renderCard = card => {
 
 const renderAllCards = cards => {
     clearCanvas();
-    cards.forEach(renderCard);
+    cards.forEach(renderCard); // Renders cards in the order they are in the array
 };
 
 // State management
@@ -136,7 +135,22 @@ const handleMouseMove = e => {
     renderAllCards(gameState.cards);
 };
 
-const handleMouseUp = () => {
+const handleMouseUp = e => {
+    if (!gameState.draggingCard) {
+        const rect = canvas.getBoundingClientRect();
+        const x = e.clientX - rect.left;
+        const y = e.clientY - rect.top;
+
+        // Check if a card was clicked
+        const clickedCard = gameState.cards.slice().reverse().find(card => isPointInCard(x, y, card));
+        if (clickedCard) {
+            // Move the clicked card to the top of the stack
+            gameState.cards = gameState.cards.filter(card => card !== clickedCard);
+            gameState.cards.push(clickedCard);
+            renderAllCards(gameState.cards); // Re-render all cards
+        }
+    }
+
     gameState.draggingCard = null;
     document.removeEventListener('mousemove', handleMouseMove);
     document.removeEventListener('mouseup', handleMouseUp);