var vm = new Vue({
el:"#ui",
data(){
return{
num:0,
saoleiStyle:{
width: "0px",
height: "0px",
},
bombNum:0,
bombs:[],
startBtn:true,
restartBtn:false
}
},
methods:{ mid(){
this.num = 100;
this.bombNum = 15;
this.$data.saoleiStyle.width=this.$data.saoleiStyle.height="500px";
for (let i = 0; i < this.bombNum; i++) {
this.addBombs();
}
}, dspl(){
this.startBtn = !this.startBtn;
this.restartBtn = !this.restartBtn;
}, //随机函数
randomNum(){
num = Math.floor(Math.random()*(this.num-1)+1);
return num;
},
//添加地雷
addBombs(){
var num = this.randomNum();
if (this.bombs.indexOf(num) == -1) {
this.bombs.push(num);
}else{
this.addBombs();
}
}, //打开菜单
openMenu(box){
var menuBox = document.getElementById(box);
menuBox.style.display = 'block';
for (let i = 0; i < this.num; i++) {
if (box!=i+1) {
this.closeMenu(i+1);
}
}
for (let i = 0; i < this.num; i++) {
if (this.bombs.indexOf(i+1) == -1) {
this.bombLoop(i + 1);
}
}
},
//关
closeMenu(box){
var menuBox = document.getElementById(box);
menuBox.style.display = 'none';
}, //标记
mark(box){
this.closeMenu(box,event);
var flag = document.getElementById('flag'+box);
if (flag.style.display == 'none') {
flag.style.display = 'block';
event.target.innerHTML="撤标";
}else{
flag.style.display = 'none';
event.target.innerHTML="标记";
}
}, //扫雷
openBox(box){
if (this.bombs.indexOf(box) != -1) {
var bomb = document.getElementById('Bomb'+box);
bomb.style.display="block";
document.getElementById('box'+box).style.background="red";
this.closeMenu(box);
this.timer = setTimeout(() => {
alert('你莫得了');
}, 500)
this.timer = setTimeout(() => {
window.location.reload();
}, 1000)
return;
}
var bombBox = document.getElementById('box'+box);
bombBox.className = "active box";
this.closeMenu(box); this.check(box); }, //检查周围
check(box){
var aroundBox = document.getElementById('around'+box);
var bombBox = document.getElementById('box'+box);
if (aroundBox.innerHTML == '0') {
bombBox.className = "active box";
aroundBox.innerHTML = '-1';
aroundBox.style.display="none";
//左边
var box_left = box - 1;
if (this.lastNum(box_left) >= 1) {
this.check(box_left);
}
//右边
var box_right = box + 1;
if (this.lastNum(box_right) != 1) {
this.check(box_right);
}
//上边
var box_up = box - 10;
if (box_up > 0) {
this.check(box_up);
//上左
var box_up_left = box_up - 1;
if (this.lastNum(box_up_left) >= 1) {
this.check(box_up_left);
}
//上右
var box_up_right = box_up + 1;
if (this.lastNum(box_up_right) != 1) {
this.check(box_up_right);
}
}
//下边
var box_down = box + 10;
if (box_down <= this.num) {
this.check(box_down);
//下左
var box_down_left = box_down - 1;
if (this.lastNum(box_down_left) >= 1) {
this.check(box_down_left);
}
//下右
var box_down_right = box_down + 1;
if (this.lastNum(box_down_right) != 1) {
this.check(box_down_right);
}
}
} else if (aroundBox.innerHTML != '-1') {
aroundBox.style.display = "block";
aroundBox.className = "box surround";
}
}, bombLoop(box){
var around = 0;
//左边
var left = box-1;
if (this.lastNum(left) > 0) {
if (this.bombs.indexOf(left) != -1) {
around += 1;
}
}
//右边
var right = box + 1;
if (this.lastNum(right) != 1) {
if (this.bombs.indexOf(right) != -1) {
around += 1;
}
}
//上边
var up = box - 10;
if (up > 0) {
if (this.bombs.indexOf(up) != -1) {
around += 1;
}
//上左
var up_Left = up - 1;
if (this.lastNum(up_Left) > 0) {
if (this.bombs.indexOf(up_Left) != -1) {
around += 1;
}
}
//上右
var up_Right = up + 1;
if (this.lastNum(up_Right) != 1) {
if (this.bombs.indexOf(up_Right) != -1) {
around += 1;
}
}
}
//下边
var down = box + 10;
if (down <= this.num) {
if (this.bombs.indexOf(down) != -1) {
around += 1;
}
//下左
var down_Left = down - 1;
if (this.lastNum(down_Left) > 0) {
if (this.bombs.indexOf(down_Left) != -1) {
around += 1;
}
}
//下右
var down_Right = down + 1;
if (this.lastNum(down_Right) != 1) {
if (this.bombs.indexOf(down_Right) != -1) {
around += 1;
}
}
}
document.getElementById('around'+box).innerHTML = around;
},
// 判断位置
lastNum(box){
var boxStr = box.toString().split('');
var last = boxStr[boxStr.length-1];
return parseInt(last);
}, //刷新按钮
restart(){
window.location.reload();
}
}, })

手写网页扫雷之js部分(vue)的更多相关文章

  1. 手写网页扫雷之HTML部分

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 手写网页扫雷之css部分

    #ui{ text-align: center; } #saolei{ width: 500px; height: 500px; border: 1px solid #456345; margin: ...

  3. 手机端网页返回顶部js代码

    <!DOCTYPE html>  <html>  <head>  <meta http-equiv="Content-Type" cont ...

  4. 自己手写的自动完成js类

    在web开发中,为了提高用户体验,会经常用到输入框的自动完成功能,不仅帮助用户进行快速输入,最重要的是帮助那些“记不全要输入什么”的用户进行选择.这个功能有很多插件已经实现了,为了适应项目的特殊需求, ...

  5. 一套手写ajax加一般处理程序的增删查改

    倾述下感受:8天16次驳回.这个惨不忍睹. 好了不说了,说多了都是泪. 直接上代码 : 这个里面的字段我是用动软生成的,感觉自己手写哪些字段太浪费时间了,说多了都是泪 ajax.model层的代码: ...

  6. Vue的学习--怎么在vue-cli中写网页

    vue.min.js和vue-cli的区别和联系我现在还是没有太清楚,大概是还没搞清楚export default和new Vue的区别,先浅浅记录一下怎么“用vue-cli来写网页”. “vue-c ...

  7. 2019前端面试系列——JS高频手写代码题

    实现 new 方法 /* * 1.创建一个空对象 * 2.链接到原型 * 3.绑定this值 * 4.返回新对象 */ // 第一种实现 function createNew() { let obj ...

  8. 基于vue手写tree插件那点事

    目录 iview提供的控件 手写控件 手写控件扩展 手写控件总结 # 加入战队 微信公众号 主题 Tree树形控件在前端开发中必不可少,对于数据的展示现在网站大都采取树形展示.因为大数据全部展示出来对 ...

  9. 一个手写的Vue放大镜,复制即可使用

    一个手写的vue放大镜 组件使用less,请确保已安装loader 本组件为放大镜组件,传参列表为: width: 必传,设置放大镜的宽高(正方形),放大区域等同,放大倍数为2倍 picList:必传 ...

随机推荐

  1. Form action 方法上传文件

    <form method="post" id="form1" runat="server" enctype="multipa ...

  2. Deno会在短期内取代Node吗?

    转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 原文出处:https://blog.bitsrc.io/what-is-deno-and-will-it-r ...

  3. C语言基础知识(五)——数组与指针的等价表示

    void f(void) { int * p; int a[3] = {1,2,3}; p = a; printf("%d %d", a[0], p[0], *(a+1), *(p ...

  4. 【Nginx】centos7 yum命令安装nginx

    安装nginx 首先我们需要使用root用户进行操作 第一步:添加nginx存储库 sudo yum install epel-release 出现如下图说明成功: 第二步:安装nginx sudo ...

  5. 蒲公英 · JELLY技术周刊 Vol.08 -- 技术周刊 · npm install -g typescript@3.9.3

    登高远眺 沧海拾遗,积跬步以至千里 基础技术 官宣: Typescript 3.9 正式发布 TypeScript 3.9 正式发布,这个版本主要聚焦于性能.改进某些特性和提升稳定性.编译器效率在这一 ...

  6. Pandas读取文件报错UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

    pandas读取文件时报UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start by ...

  7. Bank5

    Account: package banking5; //账户 public class Account { protected double balance; public Account(doub ...

  8. json工具--org.json.jar

    org.json可以解析json.把对象包装成json.API文档:http://resources.arcgis.com/en/help/arcobjects-java/api/arcobjects ...

  9. burpsuite 关于部分https抓包失败原因

    没导入证书 burpsuite生成证书 der格式,名字随便取,一路next  firefox浏览器导入 导入,勾选信任证书ok,重启浏览器  还有你要勾选这里,确保所有流量都走你的代理 ps:遇到浏 ...

  10. 小谢第8问:ui框架的css样式如何更改

    目前有三种方法, 1.使用scss,增加样式覆盖,但是此种方法要求css的className需要与框架内的元素相一致,因此修改时候需要特别注意,一个父级的不同就可能修改失败 2.deep穿透,这种方法 ...