仅作记录只用
// TODO:请补充代码
function startGame() {
let map = document.querySelectorAll(".img-box img");
console.log(map);
map.forEach((item) => {
item.style.display = "block";
});
let val = setTimeout(() => {
map.forEach((item) => {
item.style.display = "none";
});
clearTimeout(val);
}, 1000);
let btn = document.querySelector(".btn");
btn.style.display = "none";
let sc = document.querySelector("#score");
let flag = 0; //分数
let prev = null; //前一个元素
sc.innerHTML = `${flag}`;
document.querySelector(".container").onclick = (e) => {
console.log("666", e);
e.target.children[0].style.display = "block";
if (prev == null) {
prev = e.target;
} else {
val = setTimeout(() => {
if (e.target.children[0].alt == prev.children[0].alt) {
flag += 2;
e.target.style.visibility = "hidden";
prev.style.visibility = "hidden";
} else {
flag -= 2;
e.target.children[0].style.display = "none";
prev.children[0].style.display = "none";
}
sc.innerHTML = `${flag}`;
prev = null;
clearTimeout(val)
}, 500);
}
};
}