我有一个包含16张牌的牌组。每个牌都有一个名为isOpened的状态,用于检查牌是否被打开。一旦打开两张类似的卡片,我就想将它们锁定在打开的位置。如何循环打开卡组件并检查匹配状态?
constructor(props){
super(props);
this.state = {
isOpened: true,
currentState: this.props.img,
prevState: "doubt.png"
}
this.showHideCard = this.showHideCard.bind(this);
// this.showCard = this.showCard.bind(this);
// this.setFlagIsOpened = this.setFlagIsOpened.bind(this);
setTimeout(() => {this.showHideCard();}, 2000);
}
showHideCard(){
if(this.state.isOpened === false) {
this.setState({isOpened: true});
console.log("true");
} else {
this.setState({isOpened: false});
console.log("false");
}
this.setState({currentState: this.state.prevState , prevState: this.state.currentState});
}