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. 梳理继承中的has a和is a

    面向对象中的继承问题,研究了一天 ,简单梳理下其中最重要的has a和is a 1.has a 一个类中使用了另一个类中的自定义的类型 这里Student中使用了Book 和 computer2.类型 ...

  2. F. Dominant Indices

    题意:求每个点的子树中哪一层节点数最多,如果有节点数最多不唯一,取层数最小的. 题解:dus on tree 基本想法是对每一个节点都构建一个deep数组,然后从底向上更新过来,但是这样空间复杂度和时 ...

  3. Poj2109 (2) k^n = p.

    二分法,由p最大值最小值的中间值开始猜k,通过比较pow(k,n)与p的大小来进一步精确k,直到找到. #include<stdio.h> #include<math.h> # ...

  4. 0511Object类和异常

    Object类和异常 [要点] toString方法:将类中要打印的信息转换为自定义格式的打印内容 [返回的是当前对象对应的完整包名.类名@当前对象在内存空间首地址(十六进制)] equals方法 p ...

  5. 二、【Python】机器学习-监督学习

    关键词 分类(Classification) 回归(Regression) 泛化(Generalize) 过拟合(Overfitting) 欠拟合(Underfitting) 2.1 分类与回归 监督 ...

  6. Rocket - tilelink - WidthWidget

    https://mp.weixin.qq.com/s/pmJcsRMviJZjMwlwYw6OgA   简单介绍WidthWidget的实现.   ​​   1. 基本介绍   用于设定与上游节点连接 ...

  7. Java实现 洛谷 P1049 装箱问题

    题目描述 有一个箱子容量为V(正整数0≤V≤20000),同时有n个物品(0<n≤30,每个物品有一个体积(正整数). 要求nn个物品中,任取若干个装入箱内,使箱子的剩余空间为最小. 输入输出格 ...

  8. Java实现 洛谷 P6183 [USACO10MAR]The Rock Game S(DFS)

    P6183 [USACO10MAR]The Rock Game S 输入输出样例 输入 3 输出 OOO OXO OXX OOX XOX XXX XXO XOO OOO PS: 因为每一位只有两种可能 ...

  9. Java实现 LeetCode 514 自由之路

    514. 自由之路 视频游戏"辐射4"中,任务"通向自由"要求玩家到达名为"Freedom Trail Ring"的金属表盘,并使用表盘拼写 ...

  10. Java实现 LeetCode 500 键盘行

    500. 键盘行 给定一个单词列表,只返回可以使用在键盘同一行的字母打印出来的单词.键盘如下图所示. 示例: 输入: ["Hello", "Alaska", & ...