import React from ‘react’;import ReactDOM from ‘react-dom’;import { Button } from ‘reactstrap’;import Card from ‘./Card’;function cardsInitialize(){ return { value: “A”, matched: false, flipped: false}, { value: “C”, matched: false, flipped: false}, { value: “B”, matched: false, flipped: false}, { value: “D”, matched: false, flipped: false}, { value: “A”, matched: false, flipped: false}, { value: “B”, matched: false, flipped: false}, { value: “C”, matched: false, flipped: false}, { value: “D”, matched: false, flipped: false}, { value: “E”, matched: false, flipped: false}, { value: “F”, matched: false, flipped: false}, { value: “H”, matched: false, flipped: false}, { value: “G”, matched: false, flipped: false}, { value: “F”, matched: false, flipped: false}, { value: “E”, matched: false, flipped: false}, { value: “G”, matched: false, flipped: false}, { value: “H”, matched: false, flipped: false}, ;}export default class Game extends React.Component{ constructor(props) { super(props); this.displayCards = this.displayCards.bind(this); this.checkCardMatch = this.checkCardMatch.bind(this); this.reset = this.reset.bind(this); this.state = { cards: cardsInitialize(), locked: false, finalcard: null, matchdone: 0, clicksperformed: 0 }; } checkCardMatch(value, id) { if (this.state.locked) { return; } var cards = this.state.cards; cardsid.flipped = true; this.setState({cards, locked: true}); if (this.state.finalcard) { if (value === this.state.finalcard.value) { var matchdone = this.state.matchdone; cardsid.matched = true; cardsthis.state.finalcard.id.matched = true; this.setState({cards, finalcard: null, locked: false, matchdone: matchdone + 1}); this.state.clicksperformed ++; } else { setTimeout(() => { cardsid.flipped = false; cardsthis.state.finalcard.id.flipped = false; this.setState({cards, finalcard: null, locked: false}); }, 2000); this.state.clicksperformed ++; } } else { this.setState({ finalcard: {id, value}, locked: false }); } } displayCards(cards) { return cards.map((card, index) => { return (
{this.displayCards(this.state.cards)}
); }}