JS实现贪吃蛇自动寻路算法,使用JS完成的贪吃蛇游戏,在此基础上增加了寻路算法自动寻找食物
JS实现贪吃蛇自动寻路算法
使用JS完成的贪吃蛇游戏,在此基础上增加了寻路算法自动寻找食物。
index.html
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <style> #map{ height: 100%; width: 100%; } .content{ border: 1px solid red; height: 200px; width: 200px; } #msg{ color: red; } </style> <body> <div class="content"> <div id="map"></div> </div> <div> <span>得分:</span> <span id="num1"></span> <span id="msg"></span> </div> <div class="buttom"> <button onclick="refresh()">重新开始</button> </div> </body> <script src="js/index.js"></script> <script> var wayFinding = new wayFinding(game); function refresh() { game.refresh(); // 启用自动寻路 wayFinding.init(); } wayFinding.init(); </script> </html> 完整代码下载地址: