{"id":18655074,"url":"https://github.com/hacker1024/snake.dart","last_synced_at":"2026-04-22T21:35:09.711Z","repository":{"id":56839976,"uuid":"355570689","full_name":"hacker1024/snake.dart","owner":"hacker1024","description":"A flexible snake implementation in Dart.","archived":false,"fork":false,"pushed_at":"2021-04-07T14:20:26.000Z","size":10371,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-17T23:39:08.955Z","etag":null,"topics":["dart","snake","snake-game"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/snake","language":"Dart","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/hacker1024.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-07T14:15:02.000Z","updated_at":"2024-04-17T16:12:58.000Z","dependencies_parsed_at":"2022-08-29T05:01:24.752Z","dependency_job_id":null,"html_url":"https://github.com/hacker1024/snake.dart","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/hacker1024/snake.dart","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hacker1024%2Fsnake.dart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hacker1024%2Fsnake.dart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hacker1024%2Fsnake.dart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hacker1024%2Fsnake.dart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hacker1024","download_url":"https://codeload.github.com/hacker1024/snake.dart/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hacker1024%2Fsnake.dart/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262598162,"owners_count":23334668,"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":["dart","snake","snake-game"],"created_at":"2024-11-07T07:17:43.461Z","updated_at":"2026-04-22T21:35:04.676Z","avatar_url":"https://github.com/hacker1024.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Snake for Dart\nA flexible Snake package for Dart.\n\n## Usage\n1) Create a `SnakeGame`\n```dart\nfinal snakeGame = SnakeGame(\n  renderer: render,\n  boardWidth: 16,\n  boardHeight: 16,\n  initialSnakeX: 3,\n  initialSnakeY: 0,\n  initialSnakeDirection: SnakeDirection.right,\n  initialSnakeSize: 3,\n  maxTicksBeforeFood: 20,\n  minTicksBeforeFood: 5,\n  startWithFood: false,\n);\n```\n\n2) Set up a clock\n```dart\nfinal clock = Timer.periodic(\n  const Duration(milliseconds: 250),\n  (clock) {\n    if (_snakeGame.completed) {\n      clock.cancel();\n    } else {\n      snakeGame.tick();\n    }\n  },\n);\n```\n\n3) Handle the render callback\n```dart\n/// With Flutter, for example.\nclass _SnakeGameWidgetState extends State\u003cSnakeGameWidget\u003e {\n  late final SnakeGame _snakeGame;\n  late final List\u003cList\u003cSnakeItem\u003e\u003e _board;\n  \n  void _render() =\u003e setState(() =\u003e _board = _snakeGame.getBoardWithSnake());\n  \n  @overide\n  void initState() {\n    super.initState();\n    _snakeGame = SnakeGame(\n       renderer: _render,\n      /* ... */\n    );\n    _board = _snakeGame.getBoardWithSnake();\n  }\n  \n  @override\n  Widget build(BuildContext context) =\u003e SnakeGameBoardDisplay(board: _board);\n}\n```\n\n4) Add controls\n```dart\nfinal key = getPressedKey();\nswitch (key) {\n  case Key.upArrow:\n    snakeGame.directionNextTick = SnakeDirection.up;\n    break;\n  case Key.downArrow:\n    snakeGame.directionNextTick = SnakeDirection.down;\n    break;\n  case Key.leftArrow:\n    snakeGame.directionNextTick = SnakeDirection.left;\n    break;\n  case Key.rightArrow:\n    snakeGame.directionNextTick = SnakeDirection.right;\n    break;\n}\n```\n\n5) Wait for the game to end\n```dart\nawait snakeGame.gameFuture;\nalert('Game over! Score: ${snakeGame.score}');\n```\n\n6) Profit!\n\n    \u003csup\u003e_Low framerate is a gif limitation_\u003c/sup\u003e\n\n   ![Flutter example preview](flake.gif)\n\n## License\n```\nMIT License\n\nCopyright (c) 2021 hacker1024\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhacker1024%2Fsnake.dart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhacker1024%2Fsnake.dart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhacker1024%2Fsnake.dart/lists"}