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