Spaces:
Running
Running
Create index.html
Browse files- index.html +101 -0
index.html
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
canvas { background-color: #1e1e1e; }
|
10 |
+
#timer { font-size: 20px; margin-top: 10px; }
|
11 |
+
</style>
|
12 |
+
</head>
|
13 |
+
<body>
|
14 |
+
<h1>🌱 Hexagon Evolution Game 🌿</h1>
|
15 |
+
<div id="timer">Time Left: 5:00</div>
|
16 |
+
<canvas id="gameCanvas" width="800" height="600"></canvas>
|
17 |
+
<script>
|
18 |
+
const canvas = document.getElementById("gameCanvas");
|
19 |
+
const ctx = canvas.getContext("2d");
|
20 |
+
|
21 |
+
const hexSize = 40;
|
22 |
+
const hexWidth = Math.sqrt(3) * hexSize;
|
23 |
+
const hexHeight = 2 * hexSize;
|
24 |
+
const offsetX = hexWidth * 0.75;
|
25 |
+
const offsetY = hexHeight * 0.5;
|
26 |
+
const rows = 10;
|
27 |
+
const cols = 10;
|
28 |
+
|
29 |
+
let hexGrid = [];
|
30 |
+
let timer = 300; // 5 minutes
|
31 |
+
let phase = 0;
|
32 |
+
|
33 |
+
function generateHexGrid() {
|
34 |
+
for (let row = 0; row < rows; row++) {
|
35 |
+
for (let col = 0; col < cols; col++) {
|
36 |
+
let x = col * offsetX;
|
37 |
+
let y = row * hexHeight + (col % 2 ? offsetY : 0);
|
38 |
+
hexGrid.push({ x, y, type: "empty", lifeStage: 0 });
|
39 |
+
}
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
+
function drawHex(x, y, type) {
|
44 |
+
ctx.beginPath();
|
45 |
+
for (let i = 0; i < 6; i++) {
|
46 |
+
let angle = (Math.PI / 3) * i;
|
47 |
+
let px = x + hexSize * Math.cos(angle);
|
48 |
+
let py = y + hexSize * Math.sin(angle);
|
49 |
+
ctx.lineTo(px, py);
|
50 |
+
}
|
51 |
+
ctx.closePath();
|
52 |
+
ctx.fillStyle = getTerrainColor(type);
|
53 |
+
ctx.fill();
|
54 |
+
ctx.stroke();
|
55 |
+
}
|
56 |
+
|
57 |
+
function getTerrainColor(type) {
|
58 |
+
switch (type) {
|
59 |
+
case "empty": return "#C2B280";
|
60 |
+
case "seed": return "#FFD700";
|
61 |
+
case "stem": return "#8B4513";
|
62 |
+
case "leaf": return "#228B22";
|
63 |
+
case "bud": return "#FF69B4";
|
64 |
+
case "flower": return "#FFA500";
|
65 |
+
default: return "#FFFFFF";
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
function evolveGrid() {
|
70 |
+
hexGrid.forEach(hex => {
|
71 |
+
if (Math.random() < 0.1 && hex.lifeStage < 5) {
|
72 |
+
hex.lifeStage++;
|
73 |
+
hex.type = ["empty", "seed", "stem", "leaf", "bud", "flower"][hex.lifeStage];
|
74 |
+
}
|
75 |
+
});
|
76 |
+
}
|
77 |
+
|
78 |
+
function renderMap() {
|
79 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
80 |
+
hexGrid.forEach(hex => drawHex(hex.x, hex.y, hex.type));
|
81 |
+
}
|
82 |
+
|
83 |
+
function updateTimer() {
|
84 |
+
timer--;
|
85 |
+
document.getElementById("timer").innerText = `Time Left: ${Math.floor(timer / 60)}:${(timer % 60).toString().padStart(2, '0')}`;
|
86 |
+
if (timer % 15 === 0) {
|
87 |
+
evolveGrid();
|
88 |
+
}
|
89 |
+
renderMap();
|
90 |
+
if (timer <= 0) {
|
91 |
+
clearInterval(gameLoop);
|
92 |
+
alert("Game Over! Score: " + hexGrid.filter(h => h.type === "flower").length);
|
93 |
+
}
|
94 |
+
}
|
95 |
+
|
96 |
+
generateHexGrid();
|
97 |
+
renderMap();
|
98 |
+
let gameLoop = setInterval(updateTimer, 1000);
|
99 |
+
</script>
|
100 |
+
</body>
|
101 |
+
</html>
|