这里贪吃蛇游戏是通过javascript面向对象编程的方法编写,代码结构分为游戏类(Game.js),
蛇行为类(Snake.js),食物类(Food.js),话不多说,直接源码了。(粘贴源码,引入正确路径即可运行)
贪吃蛇:链接:https://pan.baidu.com/s/1_gfxQOWZ5ktZXLARzcn6fA
提取码:672a
其他游戏源码:俄罗斯方块https://blog.csdn.net/weixin_45851686/article/details/120242677https://blog.csdn.net/weixin_45851686/article/details/120242677
游戏页面:
目录
1.html&css页面搭建:
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
#app {
position: relative;
}
table {
border-collapse: collapse;
margin: auto;
}
td {
width: 25px;
height: 25px;
border: 1px solid #aaa;
}
.fen {
position: relative;
width: 300px;
height: 100px;
margin: 0 auto 10px;
background-color: #ccc;
font-size: 14px;
}
p {
display: block;
width: