基于javascript扫雷小游戏,以前上学经常玩,2024年最新2024历年网易跳动前端面试真题解析

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Web前端全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上前端开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip1024c (备注前端)
img

正文

创建背景及相关元素


//绘制背景及相关默认元素

Saolei.prototype.drawBG=function(){

var image,img,sx=0,sy=0,sWidth=141,sHeight=54,dx=20,dy=340,dWidth=141,dHeight=54;

//计时

image = this.imgObj[‘common’][15];

img = new _.ImageDraw({image:image,sx:sx,sy:sy,sWidth:sWidth,sHeight:sHeight, dx:dx, dy:dy ,dWidth:dWidth,dHeight:dHeight});

this.renderArr.push(img);

sx=0,sy=0,sWidth=141,sHeight=52,dx=180,dy=340,dWidth=141,dHeight=52;

//计雷

image = this.imgObj[‘common’][14];

img = new _.ImageDraw({image:image,sx:sx,sy:sy,sWidth:sWidth,sHeight:sHeight, dx:dx, dy:dy ,dWidth:dWidth,dHeight:dHeight});

this.renderArr.push(img);

//创建一个方形区域

var rect = new _.Rect({

x:24,

y:44,

width:289,

height:289,

stroke:true

})

this.renderArr.push(rect);

sx=0,sy=0,sWidth=100,sHeight=40,dx=120,dy=2,dWidth=100,dHeight=40;

//重新开始按钮

image = this.imgObj[‘common’][21];

img = new _.ImageDraw({image:image,sx:sx,sy:sy,sWidth:sWidth,sHeight:sHeight, dx:dx, dy:dy ,dWidth:dWidth,dHeight:dHeight});

this.renderArr.push(img);

this.reStartObj=img;

}

创建雷和显示对应的图片


**1.随机row 和 col,并从二维数组中获取到这个对象;

2.判断他是否是雷,如果是则跳过当前;

3.如果当前不是雷,则标记当前对象为雷对象,并且更改图片;

4.递归,当达到设定的数量时跳出。**

//创建被遮盖

Saolei.prototype.createUnder=function(){

var image,img,sx=0,sy=0,sWidth=79,sHeight=79,dx=0,dy=0,dWidth=32,dHeight=32;

var rows = this.rows;//行

var cols = this.cols;//列

image = this.imgObj[‘common’][9];

//二维网格数组

var gridArr=[];

var arr = this.gridArr,cell;

for(var i=0;i<rows;i++){//行

dy = 45+i*dHeight;

gridArr[i]=[];

for(var j=0;j<cols;j++){//列

dx = 25+j*dWidth;

img = new _.ImageDraw({image:image,sx:sx,sy:sy,sWidth:sWidth,sHeight:sHeight, dx:dx, dy:dy ,dWidth:dWidth,dHeight:dHeight});

img.type=0;

this.renderArr.push(img);

gridArr[i][j]=img;

}

}

this.gridArr=gridArr;

//创建雷

this.createLei();

}

//创建雷

Saolei.prototype.createLei=function(){

//当达到设定的数量时跳出

if(this.leiMaxCount<=0) {

return ;

}

var arr = this.gridArr;

/*

1.随机row 和 col,并从二维数组中获取到这个对象

2.判断他是否是雷,如果是则跳过当前

3.如果当前不是雷,则标记当前对象为雷对象,并且更改图片

4.递归,当达到设定的数量时跳出

*/

var row = _.getRandom(0,this.rows);

var col = _.getRandom(0,this.cols);

var cell = arr[row][col];

if(cell.type==0){

//标记为雷

cell.type=1;

cell.image = this.imgObj[‘common’][18];

this.leiMaxCount–;

console.log(row,col);

}

//递归

this.createLei();

}

计算周围雷的数量并显示


1.循环之前定义的二维数组

2.如果当前元素的下标是(i,j),则左上为(i-1,j-1),上为(i-1,j ),右上为(i-1,j+1),以此类推,如下图所示:

3.分别取出这些元素,并判断他们是不是雷,如果是则计数累加,最后将计数对应到相应的图片,然后显示出来。

//计算周边雷的数量并更改对象的相关参数

Saolei.prototype.computedLei=function(){

var arr = this.gridArr,cell;

for(var i=0;i<arr.length;i++){//行

for(var j=0;j<arr[i].length;j++){//列

cell = arr[i][j];

if(cell.type==1){//当前是雷则直接跳过

continue;

}

var count=0;

//左上

var ci = i-1,cj = j-1,ccell;

if(ci>=0 && cj>=0){

ccell = arr[ci][cj];

if(ccell.type==1){

count++;

}

}

//上

ci = i-1,cj = j,ccell;

if(ci>=0 && cj>=0){

ccell = arr[ci][cj];

if(ccell.type==1){

count++;

}

}

//右上

ci = i-1,cj = j+1,ccell;

if(ci>=0 && cj<this.cols){

ccell = arr[ci][cj];

if(ccell.type==1){

count++;

}

}

//右

ci = i,cj = j+1,ccell;

if(cj<this.cols){

ccell = arr[ci][cj];

if(ccell.type==1){

count++;

}

}

//右下

ci = i+1,cj = j+1,ccell;

if(ci<this.rows && cj<this.cols){

ccell = arr[ci][cj];

if(ccell.type==1){

count++;

}

}

//下

ci = i+1,cj = j,ccell;

if(ci<this.rows){

ccell = arr[ci][cj];

if(ccell.type==1){

count++;

}

}

//左下

ci = i+1,cj = j-1,ccell;

if(ci<this.rows && cj >=0){

ccell = arr[ci][cj];

if(ccell.type==1){

count++;

}

}

//左

ci = i,cj = j-1,ccell;

if(cj >= 0){

ccell = arr[ci][cj];

if(ccell.type==1){

count++;

}

}

//设定周围雷的数量

cell.count=count;

if(count==0){//因为0那张图片下标用的9

count=9;

}

//更换图片

cell.image = this.imgObj[‘common’][count];

}

}

}

创建遮罩


//创建遮盖

Saolei.prototype.createOver=function(){

var image,img,sx=0,sy=0,sWidth=79,sHeight=79,dx=0,dy=0,dWidth=32,dHeight=32;

image = this.imgObj[‘common’][10];

var arr = this.gridArr;

for(var i=0;i<arr.length;i++){//行

this.overArr[i]=[];

for(var j=0;j<arr[i].length;j++){//列

dy = 45+i*dHeight;

dx = 25+j*dWidth;

img = new _.ImageDraw({image:image,sx:sx,sy:sy,sWidth:sWidth,sHeight:sHeight, dx:dx, dy:dy ,dWidth:dWidth,dHeight:dHeight});

img.i=i,img.j=j;

this.renderArr.push(img);

this.overArr[i][j]=img;

}

}

}

创建计时和计数器


//创建计数和计时器

Saolei.prototype.createCount=function(){

//计时器

var x=115,y=382,content=0;

var text = new _.Text({

x:x,

y:y,

text:content,

font:‘26px ans-serif’,

textAlign:‘center’,

fill:true,

fillStyle:‘white’

});

this.renderArr.push(text);

this.timeCountObj=text;

x=222,y=382,content=this.leiCount;

var text = new _.Text({

x:x,

y:y,

text:content,

font:‘26px ans-serif’,

textAlign:‘center’,

fill:true,

fillStyle:‘white’

});

this.renderArr.push(text);

this.leiCountObj=text;

}

加入鼠标移动事件


//鼠标移动事件

Saolei.prototype.mouseMove=function(e){

if(this.endAnimate)return ;

var pos = _.getOffset(e);//获取鼠标位置

var isCatch=false;

if(this.reStartObj.isPoint(pos)){

this.el.style.cursor = ‘pointer’;//改为手状形态

}else{

this.el.style.cursor = ‘’;//改为普通形态

}

if(this.end)return ;//结束了已经

if(!isCatch){

//循环遮罩数组

var arr = this.overArr,cell;

for(var i=0;i<arr.length;i++){//行

for(var j=0;j<arr[i].length;j++){//列

cell = arr[i][j];

if(cell.isPoint(pos)&& !cell.open){//鼠标捕捉,被打开的同样不捕获

if(!cell.state){//打上标记的不做处理

cell.image= this.imgObj[‘common’][11];

}

}else{

if(!cell.state){//打上标记的不做处理

cell.image= this.imgObj[‘common’][10];

}

}

}

}

this.render();

}

}

加入鼠标点击事件


//鼠标点击事件

Saolei.prototype.mouseClick=function(e){

if(this.endAnimate)return ;//结束动画的时候不许点击

var pos = _.getOffset(e);//获取鼠标位置

if(this.reStartObj.isPoint(pos)){//重新开始被点击

this.restart();

return ;

}

if(this.end)return ;//结束了已经

//循环遮罩数组

var arr = this.overArr,cell,cellArr=this.gridArr;

for(var i=0;i<arr.length;i++){//行

HTTP

  • HTTP 报文结构是怎样的?

  • HTTP有哪些请求方法?

  • GET 和 POST 有什么区别?

  • 如何理解 URI?

  • 如何理解 HTTP 状态码?

  • 简要概括一下 HTTP 的特点?HTTP 有哪些缺点?

  • 对 Accept 系列字段了解多少?

  • 对于定长和不定长的数据,HTTP 是怎么传输的?

  • HTTP 如何处理大文件的传输?

  • HTTP 中如何处理表单数据的提交?

  • HTTP1.1 如何解决 HTTP 的队头阻塞问题?

  • 对 Cookie 了解多少?

  • 如何理解 HTTP 代理?

  • 如何理解 HTTP 缓存及缓存代理?

  • 为什么产生代理缓存?

  • 源服务器的缓存控制

  • 客户端的缓存控制

  • 什么是跨域?浏览器如何拦截响应?如何解决?

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注前端)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • HTTP有哪些请求方法?

  • GET 和 POST 有什么区别?

  • 如何理解 URI?

  • 如何理解 HTTP 状态码?

  • 简要概括一下 HTTP 的特点?HTTP 有哪些缺点?

  • 对 Accept 系列字段了解多少?

  • 对于定长和不定长的数据,HTTP 是怎么传输的?

  • HTTP 如何处理大文件的传输?

  • HTTP 中如何处理表单数据的提交?

  • HTTP1.1 如何解决 HTTP 的队头阻塞问题?

  • 对 Cookie 了解多少?

  • 如何理解 HTTP 代理?

  • 如何理解 HTTP 缓存及缓存代理?

  • 为什么产生代理缓存?

  • 源服务器的缓存控制

  • 客户端的缓存控制

  • 什么是跨域?浏览器如何拦截响应?如何解决?

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注前端)
[外链图片转存中…(img-LwMArPwv-1713540464909)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 24
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值