手写网页扫雷之js部分(vue)
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)的更多相关文章
- 手写网页扫雷之HTML部分
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 手写网页扫雷之css部分
#ui{ text-align: center; } #saolei{ width: 500px; height: 500px; border: 1px solid #456345; margin: ...
- 手机端网页返回顶部js代码
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" cont ...
- 自己手写的自动完成js类
在web开发中,为了提高用户体验,会经常用到输入框的自动完成功能,不仅帮助用户进行快速输入,最重要的是帮助那些“记不全要输入什么”的用户进行选择.这个功能有很多插件已经实现了,为了适应项目的特殊需求, ...
- 一套手写ajax加一般处理程序的增删查改
倾述下感受:8天16次驳回.这个惨不忍睹. 好了不说了,说多了都是泪. 直接上代码 : 这个里面的字段我是用动软生成的,感觉自己手写哪些字段太浪费时间了,说多了都是泪 ajax.model层的代码: ...
- Vue的学习--怎么在vue-cli中写网页
vue.min.js和vue-cli的区别和联系我现在还是没有太清楚,大概是还没搞清楚export default和new Vue的区别,先浅浅记录一下怎么“用vue-cli来写网页”. “vue-c ...
- 2019前端面试系列——JS高频手写代码题
实现 new 方法 /* * 1.创建一个空对象 * 2.链接到原型 * 3.绑定this值 * 4.返回新对象 */ // 第一种实现 function createNew() { let obj ...
- 基于vue手写tree插件那点事
目录 iview提供的控件 手写控件 手写控件扩展 手写控件总结 # 加入战队 微信公众号 主题 Tree树形控件在前端开发中必不可少,对于数据的展示现在网站大都采取树形展示.因为大数据全部展示出来对 ...
- 一个手写的Vue放大镜,复制即可使用
一个手写的vue放大镜 组件使用less,请确保已安装loader 本组件为放大镜组件,传参列表为: width: 必传,设置放大镜的宽高(正方形),放大区域等同,放大倍数为2倍 picList:必传 ...
随机推荐
- IDEA三种注释详解
三种注释方式 行注释.块注释.方法或类说明注释. 一.快捷键:Ctrl + / 使用Ctrl+ /, 添加行注释,再次使用,去掉行注释 二.演示代码 if (hallSites != null &am ...
- 设置键盘return键样式
textField.returnKeyType = UIReturnKeySend; typedef NS_ENUM(NSInteger, UIReturnKeyType) { UIReturnKey ...
- 四、$jQuery
1.你觉得jQuery或zepto源码有哪些写的好的地方 jquery源码封装在一个匿名函数的自执行环境中,有助于防止变量的全局污染,然后通过传入window对象参数,可以使window对象作为局部变 ...
- Hystrix入门
hystrix对应的中文名字是“豪猪”,豪猪周身长满了刺,能保护自己不受天敌的伤害,代表了一种防御机制,这与hystrix本身的功能不谋而合,因此Netflix团队将该框架命名为Hystrix,并使用 ...
- APM 上报信息分析与应用
在入正题之前我们再回顾下它的架构图: 本文章主要分析AMP各索引的作用,与及结合1.7环境上已接入的服务数据对比后,对索引中的主要字段进行解析.文章分为四个小章节. 1.索引类型 apm索引分为四种类 ...
- nodejs链接mysql 中的问题
首先你得对mysql ,有个大概的认识. 比如说:如何安装,使用基本的语法,测试安装是否能成功,以及成功之后简单的对于数据库的,操作(增删改查)... 下面是业务场景:在爬虫过程中,租后需要将信息输出 ...
- Typora Ubuntu 不显示 加粗
问题描述: Typora 在 Ubuntu18.04 上面不显示 Markdown 加粗语法 解决办法: 在 Typora's github.css 里面,将 body 修改为如下内容 body { ...
- java方式实现插入排序
一.基本思想 通过构建有序序列,从前往后扫描未排序序列,依此取出未排序序列元素,然后从后往前扫描有序序列,找到相应位置并插入.该算法一个进行n-1趟插入,每一趟插入要进行n-k(k为第k趟插入)次比较 ...
- Linux光盘yum源软件安装
关于Linux中的软件安装,有三种方法,个人认为比较方便的就是yum安装,有网的话比较简单,暂且不提.本文主要记录在没有外网的情况下,如何以本地光盘搭建yum源来实现yum安装. 主要包括以下几步: ...
- Autofac依赖注入
简介 Autofac 是一款超赞的.NET IoC 容器 . 它管理类之间的依赖关系, 从而使 应用在规模及复杂性增长的情况下依然可以轻易地修改 .它的实现方式是将常规的.net类当做 组件 处理. ...