javascript - 双击/单击破坏 JS 记忆游戏
问题描述
当用户和我 4 岁的孩子一起测试记忆游戏时,她发现了一个错误。当您双击一张卡片时,它认为它是匹配的。我试图禁用已单击的,this.style.pointerEvents = 'none'
然后将其设置回自动。
这适用于第二个点击的卡片,但不适用于第一个(击败使用它并创建新错误的点!该项目当前部署在:https ://dandavies23.github.io/smoothie-moves/
如果您对我如何更好地做到这一点有任何想法,不胜感激!
function tumblerLift() {
let cardId = this.getAttribute('data-id')
this.style.pointerEvents = 'none';
cardsChosen.push(fruitVegArray[cardId].name)
cardsChosenId.push(cardId)
this.setAttribute('src', fruitVegArray[cardId].img)
console.log(fruitVegArray[cardId])
if (cardsChosen.length === 2) {
setTimeout(checkForMatch, 500)
this.style.pointerEvents = 'auto';
}
} ```
解决方案
感谢The Bomb Squad 的回答,该null
解决方案帮助修复了匹配后出现的另一个水果错误。
这是我现在拥有的代码:
// Tumbler lift
function tumblerLift() {
if (this.src.includes('images/blank.png')) {
return null
} // prevents fruit from reappearing, credit Y0urs Truly from Github for helping fix this bug
现在感觉好多了;实际游戏可以在这里玩:https ://dandavies23.github.io/smoothie-moves/
推荐阅读
- charts - Creating multi line graphs using Google Charts API
- python - 尝试加入3张图片
- android - Failed to resolve: com.google.android.material:material:1.0.0-alpha1
- php - 在滑块 Codeigniter 中显示图像
- linux - Bash 检查用户是否存在,如果存在,将数字添加到用户名
- android - conflict between fragments inside a viewpager
- python - 为python字典中的所有键添加新键
- sql - 如何使 postgres 快速搜索
- javascript - 在已经存在的 objectStore 上创建索引
- windows - 如何使用带有选项运行的任务计划程序运行批处理文件,无论是否登录