From e8e27d26a033e2d206a9dbee88a792c7b27376b4 Mon Sep 17 00:00:00 2001 From: Aditi Bansal <142652964+Aditi22Bansal@users.noreply.github.com> Date: Thu, 11 Jul 2024 17:35:49 +0530 Subject: [PATCH 1/4] Create manifest.json --- Hexquest game/manifest.json | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Hexquest game/manifest.json diff --git a/Hexquest game/manifest.json b/Hexquest game/manifest.json new file mode 100644 index 00000000..528efe5e --- /dev/null +++ b/Hexquest game/manifest.json @@ -0,0 +1,23 @@ +{ + "manifest_version": 3, + "name": "HexQuest", + "version": "1.0", + "description": "A hexagonal grid-based adventure game.", + "permissions": [], + "background": { + "service_worker": "script.js" + }, + "action": { + "default_popup": "index.html", + "default_icon": { + "16": "icons/icon16.png", + "48": "icons/icon48.png", + "128": "icons/icon128.png" + } + }, + "icons": { + "16": "icons/icon16.png", + "48": "icons/icon48.png", + "128": "icons/icon128.png" + } +} From 4a2a712f24592a16776421560a0b339929907a0c Mon Sep 17 00:00:00 2001 From: Aditi Bansal <142652964+Aditi22Bansal@users.noreply.github.com> Date: Thu, 11 Jul 2024 17:37:18 +0530 Subject: [PATCH 2/4] Create index.html --- Hexquest game/index.html | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Hexquest game/index.html diff --git a/Hexquest game/index.html b/Hexquest game/index.html new file mode 100644 index 00000000..922001f9 --- /dev/null +++ b/Hexquest game/index.html @@ -0,0 +1,18 @@ + + + + + + HexQuest + + + +

HexQuest

+
+
+

+ +
+ + + From 362b06d7a239557f2430e6213c0318a8f9c34024 Mon Sep 17 00:00:00 2001 From: Aditi Bansal <142652964+Aditi22Bansal@users.noreply.github.com> Date: Thu, 11 Jul 2024 17:37:38 +0530 Subject: [PATCH 3/4] Create styles.css --- Hexquest game/styles.css | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Hexquest game/styles.css diff --git a/Hexquest game/styles.css b/Hexquest game/styles.css new file mode 100644 index 00000000..33f57190 --- /dev/null +++ b/Hexquest game/styles.css @@ -0,0 +1,57 @@ +body { + font-family: Arial, sans-serif; + display: flex; + flex-direction: column; + align-items: center; + height: 100vh; + margin: 0; + background-color: #f0f0f0; +} + +h1 { + text-align: center; + margin-bottom: 20px; +} + +#game-board { + display: grid; + grid-template-columns: repeat(10, 50px); + gap: 5px; + justify-content: center; +} + +.hex { + width: 50px; + height: 50px; + background-color: #fff; + border: 1px solid #ccc; + clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%); + display: flex; + justify-content: center; + align-items: center; + font-size: 14px; + cursor: pointer; +} + +.hex.character { + background-color: #4caf50; +} + +.hex.obstacle { + background-color: #f44336; +} + +.hex.goal { + background-color: #ffeb3b; +} + +#info { + margin-top: 20px; + text-align: center; +} + +button { + padding: 10px 20px; + font-size: 16px; + cursor: pointer; +} From 5f49eda53205e06d8befa72a851532a0563d5e54 Mon Sep 17 00:00:00 2001 From: Aditi Bansal <142652964+Aditi22Bansal@users.noreply.github.com> Date: Thu, 11 Jul 2024 17:37:55 +0530 Subject: [PATCH 4/4] Create script.js --- Hexquest game/script.js | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Hexquest game/script.js diff --git a/Hexquest game/script.js b/Hexquest game/script.js new file mode 100644 index 00000000..80e541c1 --- /dev/null +++ b/Hexquest game/script.js @@ -0,0 +1,55 @@ +document.addEventListener("DOMContentLoaded", () => { + const gameBoard = document.getElementById("game-board"); + const message = document.getElementById("message"); + const restartButton = document.getElementById("restart"); + const rows = 10; + const cols = 10; + let characterPosition = 0; + let goalPosition = 99; + + // Initialize game board + function initBoard() { + gameBoard.innerHTML = ""; + characterPosition = 0; + goalPosition = 99; + for (let i = 0; i < rows * cols; i++) { + const hex = document.createElement("div"); + hex.classList.add("hex"); + if (i === characterPosition) hex.classList.add("character"); + if (i === goalPosition) hex.classList.add("goal"); + if (Math.random() < 0.1 && i !== characterPosition && i !== goalPosition) hex.classList.add("obstacle"); + hex.addEventListener("click", () => moveCharacter(i)); + gameBoard.appendChild(hex); + } + updateMessage("Find the goal!"); + } + + // Move character + function moveCharacter(position) { + const distance = Math.abs(position - characterPosition); + if (distance === 1 || distance === cols) { + const hexes = document.querySelectorAll(".hex"); + hexes[characterPosition].classList.remove("character"); + characterPosition = position; + hexes[characterPosition].classList.add("character"); + + if (characterPosition === goalPosition) { + updateMessage("You found the goal! Click Restart to play again."); + } else if (hexes[characterPosition].classList.contains("obstacle")) { + updateMessage("You hit an obstacle! Click Restart to try again."); + } else { + updateMessage("Keep going!"); + } + } + } + + // Update message + function updateMessage(text) { + message.textContent = text; + } + + // Restart game + restartButton.addEventListener("click", initBoard); + + initBoard(); +});