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. MYSQL LOCK IN SHARE MODE&FOR UPDATE

    SELECT ... LOCK IN SHARE MODE sets a shared mode lock on the rows read. A shared mode lock enables o ...

  2. C# 数据操作系列 - 13 SugarSql初探

    0. 前言 前言,暂时挥别NHibernate(虽然我突然发现这玩意还挺有意思的,不过看得人不多).大步进入了有很多小伙伴向我安利的SQLSugar,嗯,我一直叫SugarSQL,好像是这个吧? 这是 ...

  3. 使用脚手架 vue-cli 4.0以上版本创建vue项目

    1. 什么是 Vue CLI 如果你只是简单写几个Vue的Demo程序, 那么你不需要Vue CLI:如果你在开发大型项目, 那么你需要, 并且必然需要使用Vue CLI. 使用Vue.js开发大型应 ...

  4. python基本数据类型:字符串及其方法(一)

    大小写转换类 方法一:capitalize()首字母大写字符串 name='hatusne miku' name1=name.capitalize() print(name,name1) 方法二:ti ...

  5. 一,View中引用自定义Dialog组件

    需求: 在项目中,有时候可能在不同画面需要完成同一功能,比如示例文件列表查看功能,系统上传文件,需要查看文件列表,以及文件历史记录 话不多说,上图 这个查看文件的Dialog需要在系统中的很多地方调用 ...

  6. css实现手机端导航栏左右滑动

    <html> <head> <meta charset="utf-8"> <meta name="viewport" ...

  7. Linux部分场景非常有用的命令集1_chattr&ldd&xargs&screen&ssh&磁盘&du

    这里不做详细说明或截图,仅作为记录和简单说明.注:可能只针对某一命令部分功能,不包含整个功能,若要查看全部请自行查阅文档或help 1.chattr 当某一文件或目录,不想被无意修改或删除(即使roo ...

  8. Java—JSON串转换成实体Bean对象模板

    介绍 模板需求说明   开发中经常遇到前端传递过来的JSON串的转换,后端需要解析成对象,有解析成List的,也有解析成Map的. 依赖 <dependency> <groupId& ...

  9. 循序渐进VUE+Element 前端应用开发(4)--- 获取后端数据及产品信息页面的处理

    在前面随笔<循序渐进VUE+Element 前端应用开发(3)--- 动态菜单和路由的关联处理>中介绍了在Vue + Element整合框架中,实现了动态菜单和动态路由的处理,从而可以根据 ...

  10. eatwhatApp开发实战(十四)

    之前我们就输入框EditText做了优化,而这次,我们为app添加拨打电话的功能. 首先是布局,将activity_shop_info.xml中对应的电话那一栏进行重新设计: <Relative ...