From 67a7e5e68c7ce39a344f61e290dc7f7f35c30255 Mon Sep 17 00:00:00 2001 From: Aditi Bansal <142652964+Aditi22Bansal@users.noreply.github.com> Date: Wed, 3 Jul 2024 00:03:11 +0530 Subject: [PATCH 1/4] Create manifest.json --- Hexsweep Game/manifest.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Hexsweep Game/manifest.json diff --git a/Hexsweep Game/manifest.json b/Hexsweep Game/manifest.json new file mode 100644 index 00000000..a8348b1e --- /dev/null +++ b/Hexsweep Game/manifest.json @@ -0,0 +1,20 @@ +{ + "name": "Hexsweep Game", + "version": "1.0", + "description": "A hexagonal version of Minesweeper.", + "manifest_version": 2, + "icons": { + "48": "icon48.png", + "128": "icon128.png" + }, + "browser_action": { + "default_popup": "index.html", + "default_icon": { + "48": "icon48.png", + "128": "icon128.png" + } + }, + "permissions": [ + "storage" + ] +} From 0f2a3535943b1015d69bbccaba4a7280a03fa35a Mon Sep 17 00:00:00 2001 From: Aditi Bansal <142652964+Aditi22Bansal@users.noreply.github.com> Date: Wed, 3 Jul 2024 00:03:27 +0530 Subject: [PATCH 2/4] Create index.html --- Hexsweep Game/index.html | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Hexsweep Game/index.html diff --git a/Hexsweep Game/index.html b/Hexsweep Game/index.html new file mode 100644 index 00000000..56a35099 --- /dev/null +++ b/Hexsweep Game/index.html @@ -0,0 +1,17 @@ + + + + + + Hexsweep Game + + + +
+

Hexsweep

+
+ +
+ + + From 50012a82569c89c6b3ddccdcb6dfe4090598eeae Mon Sep 17 00:00:00 2001 From: Aditi Bansal <142652964+Aditi22Bansal@users.noreply.github.com> Date: Wed, 3 Jul 2024 00:03:48 +0530 Subject: [PATCH 3/4] Create styles.css --- Hexsweep Game/styles.css | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Hexsweep Game/styles.css diff --git a/Hexsweep Game/styles.css b/Hexsweep Game/styles.css new file mode 100644 index 00000000..0b19938f --- /dev/null +++ b/Hexsweep Game/styles.css @@ -0,0 +1,46 @@ +body { + font-family: Arial, sans-serif; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + margin: 0; + background-color: #f0f0f0; +} + +#game-container { + text-align: center; +} + +#game-board { + display: flex; + flex-wrap: wrap; + justify-content: center; + margin-top: 20px; +} + +.hex { + width: 40px; + height: 40px; + background-color: #ddd; + margin: 2px; + clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%); + display: flex; + justify-content: center; + align-items: center; + cursor: pointer; +} + +.hex.mine { + background-color: red; +} + +.hex.flagged { + background-color: yellow; +} + +#reset-button { + margin-top: 20px; + padding: 10px 20px; + font-size: 16px; +} From 1ea4a0b9fd2a0df20fcd2a9e77f902c44a06ff0f Mon Sep 17 00:00:00 2001 From: Aditi Bansal <142652964+Aditi22Bansal@users.noreply.github.com> Date: Wed, 3 Jul 2024 00:04:08 +0530 Subject: [PATCH 4/4] Create script.js --- Hexsweep Game/script.js | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Hexsweep Game/script.js diff --git a/Hexsweep Game/script.js b/Hexsweep Game/script.js new file mode 100644 index 00000000..d0306971 --- /dev/null +++ b/Hexsweep Game/script.js @@ -0,0 +1,64 @@ +document.addEventListener('DOMContentLoaded', () => { + const boardSize = 10; + const mineCount = 15; + let gameBoard = []; + let mines = []; + const gameBoardElement = document.getElementById('game-board'); + const resetButton = document.getElementById('reset-button'); + + function initGame() { + gameBoard = []; + mines = []; + gameBoardElement.innerHTML = ''; + createBoard(); + placeMines(); + addEventListeners(); + } + + function createBoard() { + for (let i = 0; i < boardSize * boardSize; i++) { + const hex = document.createElement('div'); + hex.classList.add('hex'); + gameBoardElement.appendChild(hex); + gameBoard.push(hex); + } + } + + function placeMines() { + while (mines.length < mineCount) { + const randomIndex = Math.floor(Math.random() * gameBoard.length); + if (!mines.includes(randomIndex)) { + mines.push(randomIndex); + gameBoard[randomIndex].classList.add('mine'); + } + } + } + + function addEventListeners() { + gameBoard.forEach((hex, index) => { + hex.addEventListener('click', () => { + if (hex.classList.contains('mine')) { + alert('Game Over!'); + revealMines(); + } else { + hex.classList.add('safe'); + } + }); + + hex.addEventListener('contextmenu', (e) => { + e.preventDefault(); + hex.classList.toggle('flagged'); + }); + }); + + resetButton.addEventListener('click', initGame); + } + + function revealMines() { + mines.forEach(index => { + gameBoard[index].classList.add('revealed'); + }); + } + + initGame(); +});