Im currently working on a memory game project. A function I am trying to implement, flips cards around after two seconds instead of having them flip instantly.
let openCards = [];
function cardActions(card) {
// prevent function from adding two classes over and over again
if (!(card.classList.contains( open ))) {
// display the card s symbol
card.className += open ;
card.className += show ;
// add card to list of open cards
openCards.push(card);
if(openCards.length === 2) {
if(openCards[0].innerHTML === openCards[1].innerHTML) {
// add the match class
Array.from(openCards).forEach(function(card){
card.className += match ;
});
console.log( match );
// empty open cards
openCards = [];
} else {
Array.from(openCards).forEach(function(card) {
// add the mismatch class
card.className += mismatch ;
});
在该方案的目前阶段,我计划当使用者已经找回卡片时将卡片lip。
因此,我的确创造了一个叫做“lip”的“yn”功能。 我把等待的睡觉带在休眠方案执行中,但所有休眠的人都没有被确定错误。
我不肯定,为什么这种情况发生,因为睡眠功能IS在短片功能中作了界定。
// flip cards around
async function flip() {
await sleep(2000);
Array.from(openCards).forEach(function(card) {
card.classList.remove( mismatch )
card.classList.remove( open );
card.classList.remove( show );
});
}
// give user time to look at the cards
flip();
console.log( these dont match );
// empty open cards
openCards = [];
}
}
}
}