{"id":16347373,"url":"https://github.com/hsiangleev/game-snake","last_synced_at":"2025-07-07T15:40:22.769Z","repository":{"id":112079887,"uuid":"103798273","full_name":"hsiangleev/game-snake","owner":"hsiangleev","description":"贪吃蛇","archived":false,"fork":false,"pushed_at":"2017-09-17T03:28:56.000Z","size":32,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-28T06:10:32.714Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://hsiangleev.github.io/game-snake/index.html","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hsiangleev.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-17T02:45:31.000Z","updated_at":"2017-09-17T03:14:41.000Z","dependencies_parsed_at":"2023-07-31T12:15:27.060Z","dependency_job_id":null,"html_url":"https://github.com/hsiangleev/game-snake","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsiangleev%2Fgame-snake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsiangleev%2Fgame-snake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsiangleev%2Fgame-snake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsiangleev%2Fgame-snake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hsiangleev","download_url":"https://codeload.github.com/hsiangleev/game-snake/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239565663,"owners_count":19660158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T00:41:51.551Z","updated_at":"2025-02-18T23:16:39.058Z","avatar_url":"https://github.com/hsiangleev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 简易贪吃蛇\u003cbr\u003e\r\n[链接地址](https://hsiangleev.github.io/game-snake/index.html)\r\n* 沙箱模式封装图片加载函数，对外暴露loadImg(imgUrl,Fn)函数，\r\n其中imgUrl为图片地址（对象），Fn为回调函数。\u003cbr\u003e\r\n* 创建整个游戏函数，封装为DrawSnake，单例模式对外暴露DrawSnake（）\u003cbr\u003e\r\n  * 原型中创建随机生成食物函数food，思路为把20（整个游戏以20为一个单位）的倍数放入数组，随机取出其中一个。\r\n  * 初始化蛇身\r\n  * 蛇头移动（headMove（））\u003cbr\u003e\r\n    * 每次移动之前获取当前的蛇头坐标\u003cbr\u003e\r\n    * 重新获取蛇身节点\u003cbr\u003e\r\n    * 若屏幕宽度小于768，则认为是手机端，显示控制按钮，否则为键盘控制\u003cbr\u003e\r\n    * 初始化四个方向布尔值，按钮或键盘改变的是布尔值真假，每次只有一个为真\u003cbr\u003e\r\n    * 若蛇头碰撞到四周，则over为true；若蛇头碰到蛇身，则over为true。\u003cbr\u003e\r\n  * 蛇身移动\u003cbr\u003e\r\n    * bodyMoveDelete（），未吃到食物，则删除蛇尾，并把蛇尾添加到蛇头\u003cbr\u003e\r\n    * bodyMoveClone（），吃到食物，则复制蛇头节点为新节点，修改坐标为原蛇头坐标，添加到蛇头，并重新生成食物\u003cbr\u003e\r\n  * bodyArr（）\u003cbr\u003e\r\n    * 所有蛇身坐标存入数组，用以判断蛇头是否撞到蛇身，即蛇头坐标等于数组其中的一个\u003cbr\u003e\r\n    * 用蛇身的长度来确定得分\u003cbr\u003e\r\n* 设置游戏难度\u003cbr\u003e\r\n   通过点击难度按钮修改定时器执行时间\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhsiangleev%2Fgame-snake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhsiangleev%2Fgame-snake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhsiangleev%2Fgame-snake/lists"}