commit 067527e47ec92a7df3a4ab80e4d24a1298248c79
Author: root <root@hub.scroll.pub> Date: 2024-12-28 20:52:51 +0000 Subject: Initial commit diff --git a/body.html b/body.html new file mode 100644 index 0000000..670d345 --- /dev/null +++ b/body.html @@ -0,0 +1,18 @@ +<header> + <h1>Classic 9-Puzzle Game</h1> + <button id="resetButton">Reset Game</button> +</header> +<main> + <div id="puzzleContainer"> + <div class="puzzlePiece" data-index="0">1</div> + <div class="puzzlePiece" data-index="1">2</div> + <div class="puzzlePiece" data-index="2">3</div> + <div class="puzzlePiece" data-index="3">4</div> + <div class="puzzlePiece" data-index="4">5</div> + <div class="puzzlePiece" data-index="5">6</div> + <div class="puzzlePiece" data-index="6">7</div> + <div class="puzzlePiece" data-index="7">8</div> + <div class="puzzlePiece empty" data-index="8"></div> + </div> + <div id="victoryMessage" class="hidden">Congratulations! You solved the puzzle!</div> +</main> \ No newline at end of file diff --git a/index.scroll b/index.scroll new file mode 100644 index 0000000..3394baf --- /dev/null +++ b/index.scroll @@ -0,0 +1,8 @@ +buildHtml +baseUrl https://puzzle9.scroll.pub +metaTags +editButton /edit.html +title Classic 9-Puzzle Game +style.css +body.html +script.js \ No newline at end of file diff --git a/prompt.json b/prompt.json new file mode 100644 index 0000000..d321a50 --- /dev/null +++ b/prompt.json @@ -0,0 +1,25 @@ +{ + "id": "696a7f83-c07b-4dec-8193-bf27d7651c9b", + "object": "chat.completion", + "created": 1735419155, + "model": "deepseek-chat", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "---domain---\npuzzle9.scroll.pub\n---index.scroll---\nbuildHtml\nbaseUrl https://puzzle9.scroll.pub\nmetaTags\neditButton /edit.html\ntitle Classic 9-Puzzle Game\nstyle.css\nbody.html\nscript.js\n---body.html---\n<header>\n <h1>Classic 9-Puzzle Game</h1>\n <button id=\"resetButton\">Reset Game</button>\n</header>\n<main>\n <div id=\"puzzleContainer\">\n <div class=\"puzzlePiece\" data-index=\"0\">1</div>\n <div class=\"puzzlePiece\" data-index=\"1\">2</div>\n <div class=\"puzzlePiece\" data-index=\"2\">3</div>\n <div class=\"puzzlePiece\" data-index=\"3\">4</div>\n <div class=\"puzzlePiece\" data-index=\"4\">5</div>\n <div class=\"puzzlePiece\" data-index=\"5\">6</div>\n <div class=\"puzzlePiece\" data-index=\"6\">7</div>\n <div class=\"puzzlePiece\" data-index=\"7\">8</div>\n <div class=\"puzzlePiece empty\" data-index=\"8\"></div>\n </div>\n <div id=\"victoryMessage\" class=\"hidden\">Congratulations! You solved the puzzle!</div>\n</main>\n---style.css---\n:root {\n --primary-color: hsl(200, 50%, 50%);\n --secondary-color: hsl(200, 70%, 70%);\n --background-color: hsl(200, 10%, 10%);\n --text-color: hsl(200, 10%, 90%);\n}\n\nbody {\n font-family: 'Arial', sans-serif;\n background-color: var(--background-color);\n color: var(--text-color);\n margin: 0;\n padding: 20px;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n min-height: 100vh;\n}\n\nheader {\n text-align: center;\n margin-bottom: 20px;\n}\n\nh1 {\n font-size: 2.5rem;\n margin: 0;\n}\n\n#resetButton {\n background-color: var(--primary-color);\n color: var(--text-color);\n border: none;\n padding: 10px 20px;\n border-radius: 5px;\n cursor: pointer;\n font-size: 1rem;\n margin-top: 10px;\n}\n\n#resetButton:hover {\n background-color: var(--secondary-color);\n}\n\n#puzzleContainer {\n display: grid;\n grid-template-columns: repeat(3, 100px);\n grid-template-rows: repeat(3, 100px);\n gap: 10px;\n margin: 20px auto;\n}\n\n.puzzlePiece {\n background-color: var(--primary-color);\n color: var(--text-color);\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: 2rem;\n border-radius: 10px;\n cursor: pointer;\n transition: background-color 0.3s ease;\n}\n\n.puzzlePiece:hover {\n background-color: var(--secondary-color);\n}\n\n.puzzlePiece.empty {\n background-color: transparent;\n cursor: default;\n}\n\n#victoryMessage {\n font-size: 1.5rem;\n color: hsl(120, 50%, 50%);\n margin-top: 20px;\n display: none;\n}\n\n#victoryMessage.show {\n display: block;\n}\n\n@media (max-width: 400px) {\n #puzzleContainer {\n grid-template-columns: repeat(3, 80px);\n grid-template-rows: repeat(3, 80px);\n }\n\n .puzzlePiece {\n font-size: 1.5rem;\n }\n}\n---script.js---\nconst puzzleContainer = document.getElementById('puzzleContainer');\nconst resetButton = document.getElementById('resetButton');\nconst victoryMessage = document.getElementById('victoryMessage');\nlet emptyIndex = 8;\n\nconst pieces = Array.from(puzzleContainer.children);\n\nconst shufflePuzzle = () => {\n pieces.sort(() => Math.random() - 0.5);\n pieces.forEach((piece, index) => {\n piece.style.order = index;\n piece.dataset.index = index;\n if (!piece.textContent) {\n emptyIndex = index;\n }\n });\n};\n\nconst checkWin = () => {\n const isWin = pieces.every((piece, index) => piece.textContent == index + 1 || index === 8);\n if (isWin) {\n victoryMessage.classList.add('show');\n }\n};\n\nconst movePiece = (index) => {\n const piece = pieces[index];\n const emptyPiece = pieces[emptyIndex];\n if (Math.abs(index - emptyIndex) === 1 || Math.abs(index - emptyIndex) === 3) {\n [piece.style.order, emptyPiece.style.order] = [emptyPiece.style.order, piece.style.order];\n [pieces[index], pieces[emptyIndex]] = [pieces[emptyIndex], pieces[index]];\n emptyIndex = index;\n checkWin();\n }\n};\n\npieces.forEach((piece, index) => {\n piece.addEventListener('click', () => movePiece(index));\n});\n\nresetButton.addEventListener('click', () => {\n shufflePuzzle();\n victoryMessage.classList.remove('show');\n});\n\nshufflePuzzle();\n---end---" + }, + "logprobs": null, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 461, + "completion_tokens": 1173, + "total_tokens": 1634, + "prompt_cache_hit_tokens": 192, + "prompt_cache_miss_tokens": 269 + }, + "system_fingerprint": "fp_f1afce2943" +} \ No newline at end of file diff --git a/readme.scroll b/readme.scroll new file mode 100644 index 0000000..fbfaf03 --- /dev/null +++ b/readme.scroll @@ -0,0 +1,2 @@ +# puzzle93.scroll.pub +Website generated by DeepSeek from prompt: Design a classic 9-puzzle game using HTML, CSS, and JavaScript. The game should include the following features: 1. **Game Interface**: - Use CSS Grid to create a 3x3 puzzle container. - Each puzzle piece is a div with a background color and a foreground number. - Puzzle pieces should have rounded corners, and the container should have a rounded border. 2. **Game Functionality**: - **Randomize Puzzle**: At the start of the game, the puzzle pieces should be randomized with one empty spot. - **Piece Movement Logic**: When a movable puzzle piece (adjacent to the empty spot) is clicked, it should swap places with the empty spot. - **Win Condition Check**: When the pieces are in the correct order, display a victory message. - **Reset Game Button**: When clicked, it should randomize the puzzle again. 3. **Visual Enhancements**: - Use HSL color values to create a gradient effect for the puzzle pieces. - Provide multiple color themes and randomly select one for each game session. - Ens \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..0273c74 --- /dev/null +++ b/script.js @@ -0,0 +1,46 @@ +const puzzleContainer = document.getElementById('puzzleContainer'); +const resetButton = document.getElementById('resetButton'); +const victoryMessage = document.getElementById('victoryMessage'); +let emptyIndex = 8; + +const pieces = Array.from(puzzleContainer.children); + +const shufflePuzzle = () => { + pieces.sort(() => Math.random() - 0.5); + pieces.forEach((piece, index) => { + piece.style.order = index; + piece.dataset.index = index; + if (!piece.textContent) { + emptyIndex = index; + } + }); +}; + +const checkWin = () => { + const isWin = pieces.every((piece, index) => piece.textContent == index + 1 || index === 8); + if (isWin) { + victoryMessage.classList.add('show'); + } +}; + +const movePiece = (index) => { + const piece = pieces[index]; + const emptyPiece = pieces[emptyIndex]; + if (Math.abs(index - emptyIndex) === 1 || Math.abs(index - emptyIndex) === 3) { + [piece.style.order, emptyPiece.style.order] = [emptyPiece.style.order, piece.style.order]; + [pieces[index], pieces[emptyIndex]] = [pieces[emptyIndex], pieces[index]]; + emptyIndex = index; + checkWin(); + } +}; + +pieces.forEach((piece, index) => { + piece.addEventListener('click', () => movePiece(index)); +}); + +resetButton.addEventListener('click', () => { + shufflePuzzle(); + victoryMessage.classList.remove('show'); +}); + +shufflePuzzle(); \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..f1a52b2 --- /dev/null +++ b/style.css @@ -0,0 +1,95 @@ +:root { + --primary-color: hsl(200, 50%, 50%); + --secondary-color: hsl(200, 70%, 70%); + --background-color: hsl(200, 10%, 10%); + --text-color: hsl(200, 10%, 90%); +} + +body { + font-family: 'Arial', sans-serif; + background-color: var(--background-color); + color: var(--text-color); + margin: 0; + padding: 20px; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + min-height: 100vh; +} + +header { + text-align: center; + margin-bottom: 20px; +} + +h1 { + font-size: 2.5rem; + margin: 0; +} + +#resetButton { + background-color: var(--primary-color); + color: var(--text-color); + border: none; + padding: 10px 20px; + border-radius: 5px; + cursor: pointer; + font-size: 1rem; + margin-top: 10px; +} + +#resetButton:hover { + background-color: var(--secondary-color); +} + +#puzzleContainer { + display: grid; + grid-template-columns: repeat(3, 100px); + grid-template-rows: repeat(3, 100px); + gap: 10px; + margin: 20px auto; +} + +.puzzlePiece { + background-color: var(--primary-color); + color: var(--text-color); + display: flex; + align-items: center; + justify-content: center; + font-size: 2rem; + border-radius: 10px; + cursor: pointer; + transition: background-color 0.3s ease; +} + +.puzzlePiece:hover { + background-color: var(--secondary-color); +} + +.puzzlePiece.empty { + background-color: transparent; + cursor: default; +} + +#victoryMessage { + font-size: 1.5rem; + color: hsl(120, 50%, 50%); + margin-top: 20px; + display: none; +} + +#victoryMessage.show { + display: block; +} + +@media (max-width: 400px) { + #puzzleContainer { + grid-template-columns: repeat(3, 80px); + grid-template-rows: repeat(3, 80px); + } + + .puzzlePiece { + font-size: 1.5rem; + } +} \ No newline at end of file