import lastCard: {id, value}, locked: false });

import React, {Component} from ‘react’;import Card from ‘components/Card’;
function initialCards() { return {value: 2, matched: false, flipped: false}, {value: 4, matched: false, flipped: false}, {value: 1, matched: false, flipped: false}, {value: 1, matched: false, flipped: false}, {value: 3, matched: false, flipped: false}, {value: 4, matched: false, flipped: false}, {value: 2, matched: false, flipped: false}, {value: 3, matched: false, flipped: false} ;}
export default class Game extends Component { constructor(props) { super(props); this.renderCards = this.renderCards.bind(this); this.checkMatch = this.checkMatch.bind(this); this.reset = this.reset.bind(this);
this.state = { cards: initialCards(), lastCard: null, locked: false, matches: 0 }; }
checkMatch(value, id) { if (this.state.locked) { return; }
var cards = this.state.cards; cardsid.flipped = true; this.setState({cards, locked: true}); if (this.state.lastCard) { if (value === this.state.lastCard.value) { var matches = this.state.matches; cardsid.matched = true; cardsthis.state.lastCard.id.matched = true; this.setState({cards, lastCard: null, locked: false, matches: matches + 1}); } else { setTimeout(() => { cardsid.flipped = false; cardsthis.state.lastCard.id.flipped = false; this.setState({cards, lastCard: null, locked: false}); }, 1000); } } else { this.setState({ lastCard: {id, value}, locked: false }); } }
renderCards(cards) { return cards.map((card, index) => { return ( ); }); }
reset() { this.setState({ cards: initialCards(), lastCard: null, locked: false, matches: 0 }); }
render() { var btnText = ‘Reset’; if (this.state.matches === this.state.cards.length / 2) { btnText = ‘You Win! Play Again?’; } return (

{this.renderCards(this.state.cards)}

); }}

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now