先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7
深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Web前端全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上前端开发知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
如果你需要这些资料,可以添加V获取:vip1024c (备注前端)
正文
}
//根据行列的大小重新赋值总宽高
static setStyle(el, attr, val) {
el.style[attr] = val + “px”;
}
//设置数据
setData(newData) {
this.data = this.data.concat(newData);
}
//清除数据
clearData() {
this.data.length = 0;
}
//判断指定位置,是否包含数据
include({ x, y }) {
return this.data.some(item => (item.x == x && item.y == y))
}
//通过数据渲染页面
render() {
this.el.innerHTML = this.data.map(item => {
return `<span style="position:absolute; left: i t e m . x ∗ t h i s . r e c t p x ; t o p : {item.x * this.rect}px; top: item.x∗this.rectpx;top:{item.y * this.rect}px;
width: t h i s . r e c t p x ; h e i g h t : {this.rect}px; height: this.rectpx;height:{this.rect}px; background:${item.color};">`
}).join(“”);
}
}
=============================================================
export default class Food {
constructor(cells, rows, colors = [“yellow”, “orange”, “blue”, “pink”]) {
this.cells = cells;
this.rows = rows;
this.data = null;
this.colors = colors;
this.create();
}
//创建食物
create() {
let x = Math.floor(Math.random() * this.cells);
let y = Math.floor(Math.random() * this.rows);
let color = this.colors[parseInt(Math.random() * this.colors.length)];
this.data = { x, y, color };
}
}
============================================================
export default class Snake {
constructor() { //先传入地图类和食物类,继承里边的方法
this.data = [
{ x: 6, y: 4, color: “red” },
{ x: 6, y: 3, color: “blue” },
{ x: 6, y: 2, color: “blue” },
{ x: 6, y: 1, color: “blue” }
];
this.direction = “right”; //默认的方向
this.lastData = {};
}
//移动
move() {
let i = this.data.length - 1; //声明一个变量,是他的值为this.data这个数组的长度
//存储蛇尾巴的位置与颜色
this.lastData = {
x: this.data[i].x,
y: this.data[i].y,
color: this.data[i].color
}
//让后边每一格走到前一格的位置上
for (i; i > 0; i–) {
this.data[i].x = this.data[i - 1].x;
this.data[i].y = this.data[i - 1].y;
}
//根据方向,移动蛇头
switch (this.direction) {
case “left”:
this.data[0].x–;
break;
case “right”:
this.data[0].x++;
break;
case “top”:
this.data[0].y–;
break;
case “bottom”:
this.data[0].y++;
break;
}
}
//安全判断
changeDir(dir) {
//当方向是左或者右时
if (this.direction === “left” || this.direction === “right”) {
//且 传入的方向为左或者右
if (dir === “left” || dir === “right”) {
//不能修改方向
return false;
}
}
//当方向是上或者下时
if (this.direction === “top” || this.direction === “bottom”) {
//且 传入的方向为上或者下
if (dir === “top” || dir === “bottom”) {
//不能修改方向
return false;
}
}
//经过安全判断后,把新方向赋值给当前方向
this.direction = dir;
return true;
}
//吃到食物后,蛇应该变大一格
eatFood() {
this.data.push(this.lastData)
}
}
==================================================================
export default class Event {
events = {};
on(eventName, fn) {
if (!this.events[eventName]) {
this.events[eventName] = [];
}
if (!this.events[eventName].includes(fn)) {
this.events[eventName].push(fn);
}
}
off(eventName, fn) {
if (!this.events[eventName]) {
return
}
this.events[eventName] = this.events[eventName].filter(item => item != fn);
}
dispatch(eventName, …arg) {
if (!this.events[eventName]) {
return;
}
this.events[eventName].forEach(item => {
item.call(this, …arg)
});
}
}
=============================================================
import Map from “./map.js”;
import Event from “./event.js”;
import Snake from “./snake.js”;
import Food from “./food.js”;
export default class Game extends Event {
constructor(el, rect) {
super();
this.map = new Map(el, rect);
this.food = new Food(this.map.cells, this.map.rows);
this.snake = new Snake(this.map);
this.map.setData(this.snake.data);
this.createFood();
this.render(); //绘制初始化地图
this.timer = null; //定时器
this.interval = 200; //定时器时间设置为一个变量,可以改变速率
this.keyDown = this.keyDown.bind(this); //保存this
this.grade = 0; //保存分数
this.control(); //调用控制器(可以没有)
}
//将食物渲染到地图中
createFood() {
this.food.create();
if (this.map.include(this.food.data)) {
this.createFood();
}
this.map.setData(this.food.data);
}
//开始游戏
start() {
this.move();//调用移动
}
//暂停游戏
stop() {
clearInterval(this.timer);//清除定时器,已达到暂停的效果
}
//给地图渲染数据
render() {
this.map.clearData(); //清除旧数据
this.map.setData(this.snake.data); //设置蛇身数据
this.map.setData(this.food.data); //设置食物数据
this.map.render(); //绘制
}
//控制移动
move() {
this.timer = setInterval(() => {
this.snake.move(); //让蛇开始移动
if (this.isEat()) {
this.grade++; //每吃到一次,分数自加1
this.snake.eatFood(); //每吃到一次,变大一格
this.createFood(); //每吃到一次,创建新食物
this.changeGrade(this.grade); //每吃到一次,改变分数
this.interval *= 0.9999; //每吃到一次,改变速率
this.stop();
this.start(); //这两步为————每吃到一次,就暂停再开始一下,实现速率的刷新
最后
文章到这里就结束了,如果觉得对你有帮助可以点个赞哦
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注前端)
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
到一次,创建新食物
this.changeGrade(this.grade); //每吃到一次,改变分数
this.interval *= 0.9999; //每吃到一次,改变速率
this.stop();
this.start(); //这两步为————每吃到一次,就暂停再开始一下,实现速率的刷新
最后
文章到这里就结束了,如果觉得对你有帮助可以点个赞哦
[外链图片转存中…(img-FWtCeThN-1713097885839)]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注前端)
[外链图片转存中…(img-FHh619Lf-1713097885839)]
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!