<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>贪吃蛇</title>
<style>
#map {
width: 400px;
height: 400px;
border: 1px solid black;
}
/*地图的样式*/
.divMap {
width: 18px;
height: 18px;
margin: 1px;
background-color: yellow;
float: left;
}
/*//蛇身的样式*/
.divSnake {
width: 18px;
height: 18px;
margin: 1px;
background-color: red;
float: left;
}
/*//食物的样式*/
.divFood {
width: 18px;
height: 18px;
margin: 1px;
background-color: green;
float: left;
}
</style>
<script>
var mapX = 20,
mapY = 20; //地图边界,横向和纵向的div小格数量
var arrMap = new Array(); //地图数组
var snakeX = [4, 5, 6],
snakeY = [2, 2, 2]; //蛇身
var foodX = 9,
foodY = 3; //食物
var keyCode = 39; //蛇身移动方向,默认向右
//创建地图
function createMap() {
HTML贪吃蛇小游戏源码
最新推荐文章于 2024-07-30 10:31:44 发布