案例贪吃蛇,把封装的函数移动到js文件中
<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<title>title</title>
<style>
.map {
width: 800px;
height: 600px;
background-color: #CCC;
position: relative;
}
</style>
</head> <body>
<!--画出地图,设置样式-->
<div class="map"></div>
<script src="food.js"></script>
<script src="Snake.js"></script>
<script src="Game.js"></script>
<script> //初始化游戏对象
var gm = new Game(document.querySelector(".map")); //初始化游戏---开始游戏
gm.init(); </script>
</body> </html>