{"id":28471819,"url":"https://github.com/ptpt/slidingpuzzle","last_synced_at":"2026-03-08T04:32:35.913Z","repository":{"id":138551233,"uuid":"1840443","full_name":"ptpt/SlidingPuzzle","owner":"ptpt","description":"A sliding puzzle game written in CoffeeScript https://taopeng.me/SlidingPuzzle/","archived":false,"fork":false,"pushed_at":"2022-10-16T21:16:18.000Z","size":357,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-07-01T22:35:59.495Z","etag":null,"topics":["coffeescript","game","puzzle"],"latest_commit_sha":null,"homepage":"","language":"CoffeeScript","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/ptpt.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,"zenodo":null}},"created_at":"2011-06-03T02:05:02.000Z","updated_at":"2022-10-16T21:13:47.000Z","dependencies_parsed_at":"2023-05-24T17:30:42.678Z","dependency_job_id":null,"html_url":"https://github.com/ptpt/SlidingPuzzle","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ptpt/SlidingPuzzle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptpt%2FSlidingPuzzle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptpt%2FSlidingPuzzle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptpt%2FSlidingPuzzle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptpt%2FSlidingPuzzle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ptpt","download_url":"https://codeload.github.com/ptpt/SlidingPuzzle/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptpt%2FSlidingPuzzle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30245241,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T00:58:18.660Z","status":"online","status_checked_at":"2026-03-08T02:00:06.215Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["coffeescript","game","puzzle"],"created_at":"2025-06-07T11:08:56.825Z","updated_at":"2026-03-08T04:32:35.894Z","avatar_url":"https://github.com/ptpt.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Sliding Puzzle\n\nA [sliding puzzle](http://en.wikipedia.org/wiki/Sliding_puzzle) game\nwritten in CoffeeScript. View the demo [here](https://taopeng.me/SlidingPuzzle/).\n\n## How to use\n\n1. Copy [puzzle.js](https://taopeng.me/SlidingPuzzle//js/puzzle.js) to your site folder.\n\n2. HTML setup.\n\n    Add a container element to your HTML file. For example:\n    ````html\n    \u003cdiv id=\"puzzle\" style=\"width: 100px; height: 100px\"\u003epuzzle shows here\u003c/div\u003e\n    ````\n\n    Include `puzzle.js` in your HTML file:\n    ````html\n    \u003cscript type=\"text/javascript\" src=\"puzzle.js\"\u003e\u003c/script\u003e\n    ````\n\n3. Initialize the game.\n\n    ````javascript\n    var sliding = new SimpleSliding(3, 3),\n        container = document.getElementbyid('puzzle');\n\n    sliding.render(container, 2);\n    sliding.shuffle();\n    ````\n\n4. Show the number on each square.\n    ```javascript\n    $(sliding.squares).each(function () {\n        var id = $(this).data('id');\n        $(this).text(id + 1);\n    });\n    ```\n\n    Or specify the background image, which looks better than numbers:\n    ```javascript\n    $(sliding.squares).css({'background-image': 'url(PATH/TO/GAME-BACKGROUND.jpg)'});\n    ```\n\n5. Let the game know how to move, and how to react when you win.\n    ````javascript\n    $(sliding.squares).click(function () {\n        var id = $(this).data('id');\n        sliding.slide(id);\n        if (sliding.completed()) {\n            alert('Well done!');\n            sliding.shuffle(); // Restart again\n        }\n    });\n    ````\n\n## API\n\n```coffeescript\nclass SimpleSliding\n    # initialize a game with the number of rows and cols\n    constructor(rows, cols)\n\n    # render the game on the element with specified spacing between squares\n    render(element, spacing)\n\n    # rerender the game on current element\n    render()\n\n    # test if current game state is solvable\n    solvable()\n\n    # test if current game state is completed\n    completed()\n\n    # test if the square is slidable (movable)\n    slidable(squareID) or slidable([row, col])\n\n    # shuffle all squares (solvability is guaranteed after shuffling)\n    shuffle(callback)\n\n    # slide a square\n    slide(squareID) or slide([row, col])\n\n    # swap arbitrary two squares (after swap you have to check solvability yourself)\n    swap(squareID1, squareID2) or swap([row1, col1], [row2, col2])\n```\n\n## History\n\nThis was originally part of our\n[final project](http://gavleslidingpuzzle.appspot.com/) of the\nSoftware Development course in 2011.\n\nIn March 2013, it was rewritten in CoffeeScript.\n\nIn December 2014, it was rewritten with following improvements:\n\n1. simplification: shorter code, easier usage\n2. split game logic and UI logic\n3. remove jQuery dependency\n\n## License\n\npuzzle.js is under the MIT License. See LICENSE file for full license\ntext.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fptpt%2Fslidingpuzzle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fptpt%2Fslidingpuzzle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fptpt%2Fslidingpuzzle/lists"}