//HTMEL <body> <p class="content"> </p></body> //css .bottom,over { text-align: center; line-height: 0px;} .bottom p { display: inline-block; width: 30px; height: 30px; border: 1px solid #808080; background-color: #f4a; text-align: center; font: 20px/30px arial; } //JS // 保存 初始雷化记录 和 拆雷记录 100个按钮中 有25个雷var box = Array(10); //初始化底层function initBottom() { const content = document.getElementsByClassName('content')[0]; const bottom = document.createElement('p'); content.appendChild(bottom); bottom.className = "bottom"; for (let i = 0; i < 10; i++) { box[i] = new Array(10); for (let j = 0; j < 10; j++) { const p = document.createElement('p'); bottom.appendChild(p); p.id = "bottom[" + i + "][" + j + "]"; box[i][j] = 0; } bottom.innerHTML = bottom.innerHTML + "<br />"; } initBom();} //初始化 25个 bom 颜色 和 innerHTMLfunction initBom() { //改变颜色 for (let i = 0; i < 25; i++) { let x = Math.floor(Math.random() * 10); let y = Math.floor(Math.random() * 10); while (box[x][y] == 1) { x = Math.floor(Math.random() * 10); y = Math.floor(Math.random() * 10); if (box[x][y] == 0) { break; } } box[x][y] = 1; document.getElementById("bottom[" + x + "][" + y + "]").style.backgroundColor = "rgb(0, 0, 0)"; document.getElementById("bottom[" + x + "][" + y + "]").innerHTML = "x"; // 否则 对不起 ? } // 生成底层数字 for (let i = 0; i < 10; i++) { for (let j = 0; j < 10; j++) { if (!box[i][j] == 1) { document.getElementById("bottom[" + i + "][" + j + "]").innerHTML = getNumber(i, j); } } }} // 取得 周围雷的个数function getNumber(i, j) { let num = 0, x, y; // 四周 雷的 个数统计 for (let x = i - 1; x <= i + 1; x++) { for (y = j - 1; y <= j + 1; y++) { if (x == i && y == j) { continue; } if (document.getElementById("bottom[" + x + "][" + y + "]")) { if (box[x][y] == 1) { num++; } } } } return num;} //初始化 上层 overfunction initOver() { const content = document.getElementsByClassName('content')[0]; const over = document.createElement('p'); content.appendChild(over); over.className = "over"; over.id = "over"; for (let i = 0; i < 10; i++) { for (let j = 0; j < 10; j++) { const p = document.createElement('p'); over.appendChild(p); p.id = "over[" + i + "][" + j + "]"; } over.innerHTML = over.innerHTML + "<br />"; } //取消 右击 菜单 over.oncontextmenu = function (e) { e.returnValue = false; } // 点击 做标记 over.onclick = function (e) { const target = e.srcElement; if (target.style.backgroundColor == "rgb(255, 255, 255)") { target.style.backgroundColor = "#808080"; } else { target.style.backgroundColor = "rgb(255, 255, 255)"; } } // 双击拆雷 over.ondblclick = function (e) { const target = e.srcElement; const strId = target.id.substring(4, target.id.length); if (document.getElementById("bottom" + strId).style.backgroundColor == "rgb(0, 0, 0)") { document.getElementById('over').style.display = "none"; } else { target.style.opacity = 0; let i = parseInt(strId.substring(1, 2)); let j = parseInt(strId.substring(4, 5)); box[i][j] = 1; // 等于0 扩散 if (document.getElementById("bottom" + strId).innerHTML == 0) { zooming(i, j); } else { if (isGameOver()) { alert("真厉害"); } } } }} //扩散: 当周围有 0时,自动显示function zooming(i, j) { for (let x = i - 1; x <= i + 1; x++) { for (y = j - 1; y <= j + 1; y++) { if (document.getElementById("bottom[" + x + "][" + y + "]") && document.getElementById("bottom[" + x + "][" + y + "]").innerHTML == 0) { document.getElementById("over[" + x + "][" + y + "]").style.opacity = 0; if (box[x][y] == 0) { box[x][y] = 1; zooming(x, y); } } } }} //是否清除完 box[][] 初始化 雷时赋值 1,拆雷是赋值 1,全部为1时,完成扫雷。function isGameOver() { for (let i = 0; i < 10; i++) { for (let j = 0; j < 10; j++) { if (box[i][j] == 0) { return false; } } } return true;}
相关文章:
以上是使用js开发网页版 扫雷(附代码详解)的详细内容。更多信息请关注PHP中文网其他相关文章!

不同JavaScript引擎在解析和执行JavaScript代码时,效果会有所不同,因为每个引擎的实现原理和优化策略各有差异。1.词法分析:将源码转换为词法单元。2.语法分析:生成抽象语法树。3.优化和编译:通过JIT编译器生成机器码。4.执行:运行机器码。V8引擎通过即时编译和隐藏类优化,SpiderMonkey使用类型推断系统,导致在相同代码上的性能表现不同。

JavaScript在现实世界中的应用包括服务器端编程、移动应用开发和物联网控制:1.通过Node.js实现服务器端编程,适用于高并发请求处理。2.通过ReactNative进行移动应用开发,支持跨平台部署。3.通过Johnny-Five库用于物联网设备控制,适用于硬件交互。

我使用您的日常技术工具构建了功能性的多租户SaaS应用程序(一个Edtech应用程序),您可以做同样的事情。 首先,什么是多租户SaaS应用程序? 多租户SaaS应用程序可让您从唱歌中为多个客户提供服务

本文展示了与许可证确保的后端的前端集成,并使用Next.js构建功能性Edtech SaaS应用程序。 前端获取用户权限以控制UI的可见性并确保API要求遵守角色库

JavaScript是现代Web开发的核心语言,因其多样性和灵活性而广泛应用。1)前端开发:通过DOM操作和现代框架(如React、Vue.js、Angular)构建动态网页和单页面应用。2)服务器端开发:Node.js利用非阻塞I/O模型处理高并发和实时应用。3)移动和桌面应用开发:通过ReactNative和Electron实现跨平台开发,提高开发效率。

JavaScript的最新趋势包括TypeScript的崛起、现代框架和库的流行以及WebAssembly的应用。未来前景涵盖更强大的类型系统、服务器端JavaScript的发展、人工智能和机器学习的扩展以及物联网和边缘计算的潜力。

JavaScript是现代Web开发的基石,它的主要功能包括事件驱动编程、动态内容生成和异步编程。1)事件驱动编程允许网页根据用户操作动态变化。2)动态内容生成使得页面内容可以根据条件调整。3)异步编程确保用户界面不被阻塞。JavaScript广泛应用于网页交互、单页面应用和服务器端开发,极大地提升了用户体验和跨平台开发的灵活性。

Python更适合数据科学和机器学习,JavaScript更适合前端和全栈开发。 1.Python以简洁语法和丰富库生态着称,适用于数据分析和Web开发。 2.JavaScript是前端开发核心,Node.js支持服务器端编程,适用于全栈开发。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

禅工作室 13.0.1
功能强大的PHP集成开发环境