JS膏集02

JS膏集02

1、复习
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
函数也是对象
2、贪食蛇案例

<!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();


  //外部测试代码
  //  var fd = new Food();
  //  fd.init(document.querySelector(".map"));
  //  //创建小蛇
  //  var snake = new Snake();
  //  snake.init(document.querySelector(".map"));//先在地图上看到小蛇
  //
  //
  //
  //  setInterval(function () {
  //    snake.move(fd, document.querySelector(".map"));
  //    snake.init(document.querySelector(".map"));
  //  }, 150);


  //  snake.move(fd, document.querySelector(".map"));//走一步
  //  snake.init(document.querySelector(".map"));//初始化---重新画一条小蛇(先删除之前的小蛇,把现在的小蛇显示出来)

  //  snake.move(fd, document.querySelector(".map"));
  //  snake.init(document.querySelector(".map"));
  //  snake.move(fd, document.querySelector(".map"));
  //  snake.init(document.querySelector(".map"));
  //  snake.move(fd, document.querySelector(".map"));
  //  snake.init(document.querySelector(".map"));
  //  snake.move(fd, document.querySelector(".map"));
  //  snake.init(document.querySelector(".map"));
  //  snake.move(fd, document.querySelector(".map"));
  //  snake.init(document.querySelector(".map"));
  //
  //  snake.move(fd, document.querySelector(".map"));
  //  snake.init(document.querySelector(".map"));


  //  fd.init(document.querySelector(".map"));
  //  fd.init(document.querySelector(".map"));
  //  fd.init(document.querySelector(".map"));
  //  fd.init(document.querySelector(".map"));
  //console.log(fd.x+"====>"+fd.y);

  //console.log(fd.width);

</script>
</body>
</html>
posted on 2018-10-04 18:06  Tanqurey  阅读(68)  评论(0编辑  收藏  举报