kucherenko / ol0lo

0 stars 0 forks source link

Implement task #62 - Memory Game #64

Closed brian-ai-assistant-dev[bot] closed 1 year ago

brian-ai-assistant-dev[bot] commented 1 year ago

To implement the card memory game, I would modify the index.vue component as follows:

  1. Add a data property to store the game state, including the card values, whether they are flipped or not, and the number of matched cards. Example: data() { return { cards: [ { value: 'A', flipped: false, matched: false }, { value: 'B', flipped: false, matched: false }, // Add more cards with unique values ], // Other game state properties } }

  2. Add methods to handle the flipping and matching of cards.

    • The flipCard method should update the flipped property of the clicked card.
    • The checkForMatch method should check if there are two flipped cards with the same value and update their matched property accordingly. If the cards don't match, a delay can be added before flipping them back. Example: methods: { flipCard(card) { card.flipped = !card.flipped; }, checkForMatch() { const flippedCards = this.cards.filter(card => card.flipped && !card.matched); if (flippedCards.length === 2) { if (flippedCards[0].value === flippedCards[1].value) { flippedCards.forEach(card => { card.matched = true; }); } else { setTimeout(() => { flippedCards.forEach(card => { card.flipped = false; }); }, 1000); // Delay before flipping back } } }, // Other game-related methods }
  3. Update the template to display the card values and bind the click event to the flipCard method. Example: