Spaces:
Running
Running
Create index.html
Browse files- index.html +139 -0
index.html
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Hexagon Evolution Game</title>
|
7 |
+
<style>
|
8 |
+
body { text-align: center; background-color: #282c34; color: white; }
|
9 |
+
#gameContainer { display: flex; justify-content: space-between; }
|
10 |
+
#sidebar { width: 250px; text-align: left; padding: 10px; }
|
11 |
+
canvas { background-color: #1e1e1e; cursor: pointer; }
|
12 |
+
#timer, #resources, #seedSelection, #scoreboard { font-size: 20px; margin-top: 10px; }
|
13 |
+
button { margin: 5px; padding: 10px; font-size: 16px; cursor: pointer; }
|
14 |
+
</style>
|
15 |
+
</head>
|
16 |
+
<body>
|
17 |
+
<h1>π± Hexagon Evolution Game πΏ</h1>
|
18 |
+
<div id="gameContainer">
|
19 |
+
<div id="sidebar">
|
20 |
+
<div id="timer">Time Left: 5:00</div>
|
21 |
+
<div id="resources">Seeds: πΏ5 π5 πΊ5 πΎ5 π5</div>
|
22 |
+
<div id="seedSelection">
|
23 |
+
<button onclick="selectPlant('πΏ')">πΏ</button>
|
24 |
+
<button onclick="selectPlant('π')">π</button>
|
25 |
+
<button onclick="selectPlant('πΊ')">πΊ</button>
|
26 |
+
<button onclick="selectPlant('πΎ')">πΎ</button>
|
27 |
+
<button onclick="selectPlant('π')">π</button>
|
28 |
+
</div>
|
29 |
+
<div id="scoreboard">Total Score: 0</div>
|
30 |
+
</div>
|
31 |
+
<canvas id="gameCanvas" width="800" height="600"></canvas>
|
32 |
+
</div>
|
33 |
+
<script>
|
34 |
+
const canvas = document.getElementById("gameCanvas");
|
35 |
+
const ctx = canvas.getContext("2d");
|
36 |
+
|
37 |
+
const hexSize = 40;
|
38 |
+
const hexWidth = Math.sqrt(3) * hexSize;
|
39 |
+
const hexHeight = 2 * hexSize;
|
40 |
+
const offsetX = hexWidth;
|
41 |
+
const offsetY = hexHeight * 0.75;
|
42 |
+
const rows = 10;
|
43 |
+
const cols = 10;
|
44 |
+
let hexGrid = [];
|
45 |
+
let timer = 300;
|
46 |
+
let selectedPlant = null;
|
47 |
+
let resources = { "πΏ": 5, "π": 5, "πΊ": 5, "πΎ": 5, "π": 5 };
|
48 |
+
let totalScore = 0;
|
49 |
+
|
50 |
+
function generateHexGrid() {
|
51 |
+
for (let row = 0; row < rows; row++) {
|
52 |
+
for (let col = 0; col < cols; col++) {
|
53 |
+
let x = col * offsetX + 150;
|
54 |
+
let y = row * hexHeight + (col % 2 ? offsetY : 0) + 50;
|
55 |
+
hexGrid.push({ x, y, type: "empty", lifeStage: 0, score: 0, emoji: "" });
|
56 |
+
}
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
function selectPlant(plant) {
|
61 |
+
selectedPlant = plant;
|
62 |
+
}
|
63 |
+
|
64 |
+
function drawHex(hex) {
|
65 |
+
const { x, y, type, emoji } = hex;
|
66 |
+
ctx.beginPath();
|
67 |
+
for (let i = 0; i < 6; i++) {
|
68 |
+
let angle = (Math.PI / 3) * i;
|
69 |
+
let px = x + hexSize * Math.cos(angle);
|
70 |
+
let py = y + hexSize * Math.sin(angle);
|
71 |
+
ctx.lineTo(px, py);
|
72 |
+
}
|
73 |
+
ctx.closePath();
|
74 |
+
ctx.fillStyle = getTerrainColor(type);
|
75 |
+
ctx.fill();
|
76 |
+
ctx.stroke();
|
77 |
+
ctx.fillStyle = "white";
|
78 |
+
ctx.font = "20px Arial";
|
79 |
+
ctx.fillText(emoji, x - 10, y + 5);
|
80 |
+
}
|
81 |
+
|
82 |
+
function getTerrainColor(type) {
|
83 |
+
return type === "empty" ? "#C2B280" : "#90EE90";
|
84 |
+
}
|
85 |
+
|
86 |
+
function evolveGrid() {
|
87 |
+
hexGrid.forEach(hex => {
|
88 |
+
if (hex.type !== "empty") {
|
89 |
+
hex.lifeStage++;
|
90 |
+
hex.score += hex.lifeStage * 5;
|
91 |
+
totalScore += hex.lifeStage * 5;
|
92 |
+
document.getElementById("scoreboard").innerText = `Total Score: ${totalScore}`;
|
93 |
+
}
|
94 |
+
});
|
95 |
+
}
|
96 |
+
|
97 |
+
function renderMap() {
|
98 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
99 |
+
hexGrid.forEach(hex => drawHex(hex));
|
100 |
+
}
|
101 |
+
|
102 |
+
function updateTimer() {
|
103 |
+
timer--;
|
104 |
+
document.getElementById("timer").innerText = `Time Left: ${Math.floor(timer / 60)}:${(timer % 60).toString().padStart(2, '0')}`;
|
105 |
+
if (timer % 15 === 0) {
|
106 |
+
evolveGrid();
|
107 |
+
}
|
108 |
+
renderMap();
|
109 |
+
if (timer <= 0) {
|
110 |
+
clearInterval(gameLoop);
|
111 |
+
alert("Game Over! Final Score: " + totalScore);
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
canvas.addEventListener("click", (event) => {
|
116 |
+
const rect = canvas.getBoundingClientRect();
|
117 |
+
const mouseX = event.clientX - rect.left;
|
118 |
+
const mouseY = event.clientY - rect.top;
|
119 |
+
|
120 |
+
hexGrid.forEach(hex => {
|
121 |
+
if (Math.hypot(hex.x - mouseX, hex.y - mouseY) < hexSize) {
|
122 |
+
if (selectedPlant && resources[selectedPlant] > 0 && hex.type === "empty") {
|
123 |
+
hex.type = "seed";
|
124 |
+
hex.lifeStage = 1;
|
125 |
+
hex.emoji = selectedPlant;
|
126 |
+
resources[selectedPlant]--;
|
127 |
+
document.getElementById("resources").innerText = `Seeds: πΏ${resources["πΏ"]} π${resources["π"]} πΊ${resources["πΊ"]} πΎ${resources["πΎ"]} π${resources["π"]}`;
|
128 |
+
}
|
129 |
+
}
|
130 |
+
});
|
131 |
+
renderMap();
|
132 |
+
});
|
133 |
+
|
134 |
+
generateHexGrid();
|
135 |
+
renderMap();
|
136 |
+
let gameLoop = setInterval(updateTimer, 1000);
|
137 |
+
</script>
|
138 |
+
</body>
|
139 |
+
</html>
|