Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved #2287- Hexquest game extension #2322

Merged
merged 6 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Hexquest game/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HexQuest</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>HexQuest</h1>
<div id="game-board"></div>
<div id="info">
<p id="message"></p>
<button id="restart">Restart Game</button>
</div>
<script src="script.js"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions Hexquest game/manifest.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
55 changes: 55 additions & 0 deletions Hexquest game/script.js
Original file line number Diff line number Diff line change
@@ -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();
});
57 changes: 57 additions & 0 deletions Hexquest game/styles.css
Original file line number Diff line number Diff line change
@@ -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;
}
Loading