2 Star 1 Fork 1

wu-jiajun/one

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
代码 1.43 KB
一键复制 编辑 原始数据 按行查看 历史
wu-jiajun 提交于 2025-03-20 15:07 +08:00 . add 代码.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>消灭方块</title>
<style>
#gameBoard {
width: 300px;
height: 300px;
margin: 20px auto;
position: relative;
border: 2px solid #000;
}
.block {
width: 50px;
height: 50px;
position: absolute;
background-color: red;
cursor: pointer;
}
</style>
</head>
<body>
<div id="gameBoard"></div>
<script>
const gameBoard = document.getElementById('gameBoard');
const blockCount = 9;
let score = 0;
function createBlock(index) {
const block = document.createElement('div');
block.classList.add('block');
block.style.left = (index % 3) * 100 + 'px';
block.style.top = Math.floor(index / 3) * 100 + 'px';
block.addEventListener('click', () => {
block.remove();
score++;
document.getElementById('score').innerText = `Score: ${score}`;
if (document.querySelectorAll('.block').length === 0) {
alert('You win!');
}
});
gameBoard.appendChild(block);
}
for (let i = 0; i < blockCount; i++) {
createBlock(i);
}
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wu-jiajun-12/one.git
git@gitee.com:wu-jiajun-12/one.git
wu-jiajun-12
one
one
master

搜索帮助