{"id":21721606,"url":"https://github.com/ccbp/charsnake","last_synced_at":"2026-05-13T05:42:50.960Z","repository":{"id":155687221,"uuid":"582839141","full_name":"CCBP/CharSnake","owner":"CCBP","description":"The character device driver snake game encapsulates the game logic as a Linux character device driver, allowing gameplay through reading and writing text. To better display the text and facilitate gameplay, the game is presented on a webpage, allowing it to be played not only through command line control but also online through the web.","archived":false,"fork":false,"pushed_at":"2023-03-20T16:00:05.000Z","size":14110,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-25T18:43:25.899Z","etag":null,"topics":["caddy","driver","game","linux","scull"],"latest_commit_sha":null,"homepage":"https://www.amrzs.net/2023/03/19/char_snake/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CCBP.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2022-12-28T02:25:04.000Z","updated_at":"2023-03-20T16:10:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"3e239788-1d59-4f8b-beef-98bcce1e851f","html_url":"https://github.com/CCBP/CharSnake","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/CCBP%2FCharSnake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CCBP%2FCharSnake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CCBP%2FCharSnake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CCBP%2FCharSnake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CCBP","download_url":"https://codeload.github.com/CCBP/CharSnake/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244694120,"owners_count":20494582,"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":["caddy","driver","game","linux","scull"],"created_at":"2024-11-26T02:18:02.133Z","updated_at":"2026-05-13T05:42:50.928Z","avatar_url":"https://github.com/CCBP.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"assets/image/char_snake.jpg\" alt=\"banner\" width=\"40%\"\u003e\n\u003c/div\u003e\u003cbr /\u003e\n\n# 🐍 Char Snake | Linux字符设备驱动贪吃蛇游戏 🕹️\n\n![Author](https://img.shields.io/badge/Author-CCBP-blue)\n![license](https://img.shields.io/badge/license-MIT-yellowgreen)\n\n该项目是一个经典的贪吃蛇游戏，使用 Linux 字符设备驱动来封装游戏逻辑，实现以读写文本的方式进行游玩。为了方便游玩，游戏使用网页通过字符呈现，使得该游戏不仅可以在命令行中使用进行控制，也可以在网页端在线游玩。\n\n更加详细的介绍以及游戏的试玩，欢迎前往[我的博客](https://www.amrzs.net/2023/03/19/char_snake/)体验。\n\n## 📖 说明\n该游戏以字符设备scull为原型实现的字符驱动设备为基础，提供了统一的接口可以使用echo与cat等命令在终端进行控制；并且可以通过脚本快速且简单的进行驱动的安装卸载、游戏的移动控制、网络服务器的运行启动等功能；配合Caddy服务器实现地图数据的请求与控制命令的响应。\n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"assets/image/char_snake_architecture.png\" alt=\"architecture\" width=\"50%\"\u003e\n    \u003cp\u003e贪吃蛇游戏架构\u003c/p\u003e\n\u003c/div\u003e\u003cbr /\u003e\n\n## 🛠️ 安装\n\n\u003e 下面步骤均以 Debian 系统为例\n\n安装开发用的源码和头文件包，克隆项目获取源码\n\n```\n$ sudo apt install linux-headers-$(uname -r)\n$ git clone https://github.com/CCBP/CharSnake.git\n```\n\n进入项目目录，使用脚本编译并安装驱动\n\n```\n$ cd CharSnake\n$ ./snake.sh build            # 编译驱动\n$ sudo ./snake.sh install     # 安装驱动\n```\n\n运行静态文件服务器，响应客户端对 `src/web/` 路径下文件的访问请求（脚本使用 `assets/caddy/` 目录下带有exec模块的caddy作为服务器后端）\n\n```\n$ ./snake.sh run\n```\n\n打开浏览器并输入 http://127.0.0.1:2019 即可开始游玩\n\n## 🎮 游戏操作\n\n### 网页端\n\n\u003e 下方游戏界面仅为演示，实际游玩请前往[我的博客](https://www.amrzs.net/2023/03/19/char_snake/)体验\n\n\u003chtml\u003e\n \u003chead\u003e\u003c/head\u003e\n \u003cbody\u003e\n  \u003ctable align=\"center\"\u003e \n   \u003ctbody\u003e\n    \u003ctr\u003e \n     \u003ctd rowspan=\"7\" width=\"20%\"\u003e \u003cpre id=\"map\"\u003e...........\u003cbr /\u003e...........\u003cbr /\u003e...........\u003cbr /\u003e....##*....\u003cbr /\u003e....#......\u003cbr /\u003e....@......\u003cbr /\u003e...........\u003cbr /\u003e...........\u003cbr /\u003e...........\u003cbr /\u003e....$......\u003cbr /\u003e...........\u003cbr /\u003e\u003c/pre\u003e \u003c/td\u003e \n     \u003cth colspan=\"6\" width=\"60%\"\u003e游戏玩法\u003c/th\u003e \n    \u003c/tr\u003e \n    \u003ctr\u003e \n     \u003ctd colspan=\"6\"\u003e\u003ccode\u003eW\u003c/code\u003e \u003ccode\u003eS\u003c/code\u003e \u003ccode\u003eA\u003c/code\u003e \u003ccode\u003eD\u003c/code\u003e 向上、下、左、右移动\u003c/td\u003e \n    \u003c/tr\u003e \n    \u003ctr\u003e \n     \u003ctd colspan=\"3\"\u003e\u003ccode\u003eSpace\u003c/code\u003e 暂停游戏\u003c/td\u003e \n     \u003ctd colspan=\"3\"\u003e\u003ccode\u003eR\u003c/code\u003e 重新开始\u003c/td\u003e \n    \u003c/tr\u003e \n    \u003ctr\u003e \n     \u003cth colspan=\"6\"\u003e游戏信息\u003c/th\u003e \n    \u003c/tr\u003e \n    \u003ctr\u003e \n     \u003ctd colspan=\"2\"\u003e\u003ccode\u003e@\u003c/code\u003e 蛇头\u003c/td\u003e \n     \u003ctd colspan=\"2\"\u003e\u003ccode\u003e#\u003c/code\u003e 蛇身\u003c/td\u003e \n     \u003ctd colspan=\"2\"\u003e\u003ccode\u003e*\u003c/code\u003e 蛇尾\u003c/td\u003e \n    \u003c/tr\u003e \n    \u003ctr\u003e \n     \u003ctd colspan=\"3\"\u003e\u003ccode\u003e$\u003c/code\u003e 食物\u003c/td\u003e \n     \u003ctd colspan=\"3\"\u003e\u003ccode\u003e.\u003c/code\u003e 空白地图\u003c/td\u003e \n    \u003c/tr\u003e \n    \u003ctr\u003e \n     \u003ctd colspan=\"3\"\u003e\u003ccode\u003eO\u003c/code\u003e 游戏成功\u003c/td\u003e \n     \u003ctd colspan=\"3\"\u003e\u003ccode\u003eX\u003c/code\u003e 游戏失败\u003c/td\u003e \n    \u003c/tr\u003e \n    \u003ctr\u003e \n     \u003ctd\u003e\u003c/td\u003e \n     \u003ctd width=\"10%\"\u003e\u003c/td\u003e \n     \u003ctd width=\"10%\"\u003e\u003c/td\u003e \n     \u003ctd width=\"10%\"\u003e\u003c/td\u003e \n     \u003ctd width=\"10%\"\u003e\u003c/td\u003e \n     \u003ctd width=\"10%\"\u003e\u003c/td\u003e \n     \u003ctd width=\"10%\"\u003e\u003c/td\u003e \n    \u003c/tr\u003e \n   \u003c/tbody\u003e\n  \u003c/table\u003e\n \u003c/body\u003e\n\u003c/html\u003e\n\n### 命令行\n\n```\n$ cat /dev/char_snake        # 打印地图\n...........\n.........$.\n...........\n...........\n...........\n.....@.....\n...........\n...........\n...........\n...........\n...........\n \n$ echo W \u003e /dev/char_snake   # 向上移动\n$ cat /dev/char_snake        # 打印地图\n...........\n.........$.\n...........\n...........\n.....@.....\n...........\n...........\n...........\n...........\n...........\n...........\n```\n\n## 📝 TODO\n\n这个项目只是我个人学习练手所建，目前只是完成了它的基本功能，还有很大的优化空间\n\n- 地图字符呈现方式优化\n- 定时器刷新地图数据\n- IoCtrl 接口实现游戏控制\n- 可变地图尺寸与获胜条件\n- 支持多人同时在线游玩\n- . . .","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccbp%2Fcharsnake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fccbp%2Fcharsnake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccbp%2Fcharsnake/lists"}