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. select 下拉模糊查询

    http://ivaynberg.github.io/select2/ https://github.com/ https://github.com/ivaynberg.github.io/selec ...

  2. PHP关于syntax error语法错误的问题(Parse error: syntax error, unexpected end of file in xxxxxxxx)

    在php程序出现类似 Parse error: syntax error, unexpected end of file in xxxxxxxx  on line xx 的错误. 如图 如果发现php ...

  3. vue中 transition组件使用总结

    博客园比较啃爹啊,随笔只能手写,之前写在有道云笔记里面的内容也复制不了,忧伤..... 长话短说,看官方的transition 的讲解,可能是内容太多了,或者就是本人太辣鸡了,看的有点懵逼,但是项目中 ...

  4. 【图像处理】利用C++编写函数,绘制灰度图像直方图

    1. 简介 利用OpenCV读取图像,转换为灰度图像,绘制该灰度图像直方图.点击直方图,控制台输出该灰度级像素个数. 2. 原理 (1) 实现原理较为简单,主要利用了OpenCV读取图像,并转换为灰度 ...

  5. 安卓到底是不是Linux

    有人说安卓就是 Linux,也有人说安卓是安卓.Linux 是 Linux,两者没什么关系,还有人说安卓用的是 Linux 的内核,那么它们之间到底是什么关系呢.要想得到这个问题的答案,我们要先弄清楚 ...

  6. spring-kafka之KafkaListener注解深入解读

    简介 Kafka目前主要作为一个分布式的发布订阅式的消息系统使用,也是目前最流行的消息队列系统之一.因此,也越来越多的框架对kafka做了集成,比如本文将要说到的spring-kafka. Kafka ...

  7. Python 每日一练 | Flask 实现半成品留言板

    留言板Flask实现 引言 看了几天网上的代码,终于写出来一个半成品的Flask的留言板项目,为什么说是半成品呢?因为没能实现留言板那种及时评论刷新的效果,可能还是在重定向上有问题 或者渲染写的存在问 ...

  8. 在线编写复杂的数学公式--EdrawMath

    网址: EdrawMath , 非常好用

  9. AD17无法复制原理图到Word的解决方法

    标题: 解决AD17无法复制原理图到WORD 作者: 梦幻之心星 347369787@QQ.com 标签: [AD, Word, 原理图] 目录: 软件 日期: 2019-3-17 目录 前提说明: ...

  10. node_modules内容太大导致webstrom非常卡

    选中一个文件夹,例如node_modules,点击右键->mark directory as ->excluded,这样就可以把这个文件标记并排除出来,使webstorm不会扫描这个文件下 ...