Spaces:
Running
Running
Update index.html
Browse files- index.html +74 -56
index.html
CHANGED
|
@@ -1,67 +1,85 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
// Hexagon properties
|
| 5 |
-
const hexSize =
|
| 6 |
-
const hexWidth = Math.sqrt(3) * hexSize;
|
| 7 |
-
const hexHeight = 2 * hexSize;
|
| 8 |
-
const offsetX = hexWidth * 0.75;
|
| 9 |
-
const offsetY = hexHeight * 0.5;
|
| 10 |
-
const rows = 10;
|
| 11 |
-
const cols = 10;
|
| 12 |
|
| 13 |
-
// Hex map storage
|
| 14 |
-
let hexGrid = [];
|
| 15 |
|
| 16 |
-
// Function to generate a hexagonal grid
|
| 17 |
-
function generateHexGrid() {
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
}
|
| 24 |
-
}
|
| 25 |
-
}
|
| 26 |
|
| 27 |
-
// Function to draw hexagons
|
| 28 |
-
function drawHex(x, y, type) {
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
}
|
| 41 |
|
| 42 |
-
// Function to assign random terrain types
|
| 43 |
-
function getRandomTerrain() {
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
}
|
| 47 |
|
| 48 |
-
// Function to get terrain color
|
| 49 |
-
function getTerrainColor(type) {
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
}
|
| 58 |
|
| 59 |
-
// Function to render the map
|
| 60 |
-
function renderMap() {
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
}
|
| 64 |
|
| 65 |
-
// Initialize and draw map
|
| 66 |
generateHexGrid();
|
| 67 |
renderMap();
|
|
|
|
|
|
|
|
|
|
|
|
| 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 Game</title>
|
| 7 |
+
<style>
|
| 8 |
+
body { text-align: center; background-color: #282c34; color: white; }
|
| 9 |
+
canvas { background-color: #1e1e1e; }
|
| 10 |
+
</style>
|
| 11 |
+
</head>
|
| 12 |
+
<body>
|
| 13 |
+
<h1>π‘οΈ Hexagon Strategy Game π²</h1>
|
| 14 |
+
<canvas id="gameCanvas" width="800" height="600"></canvas>
|
| 15 |
+
<script>
|
| 16 |
+
const canvas = document.getElementById("gameCanvas");
|
| 17 |
+
const ctx = canvas.getContext("2d");
|
| 18 |
|
| 19 |
+
// π οΈ Hexagon properties (Hexagons are like pizzas, but with 6 slices!)
|
| 20 |
+
const hexSize = 40;
|
| 21 |
+
const hexWidth = Math.sqrt(3) * hexSize;
|
| 22 |
+
const hexHeight = 2 * hexSize;
|
| 23 |
+
const offsetX = hexWidth * 0.75;
|
| 24 |
+
const offsetY = hexHeight * 0.5;
|
| 25 |
+
const rows = 10;
|
| 26 |
+
const cols = 10;
|
| 27 |
|
| 28 |
+
// π Hex map storage (Storing our mighty kingdom!)
|
| 29 |
+
let hexGrid = [];
|
| 30 |
|
| 31 |
+
// π² Function to generate a hexagonal grid
|
| 32 |
+
function generateHexGrid() {
|
| 33 |
+
for (let row = 0; row < rows; row++) {
|
| 34 |
+
for (let col = 0; col < cols; col++) {
|
| 35 |
+
let x = col * offsetX;
|
| 36 |
+
let y = row * hexHeight + (col % 2 ? offsetY : 0);
|
| 37 |
+
hexGrid.push({ x, y, type: getRandomTerrain() });
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
}
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
// π· Function to draw hexagons (Like drawing fancy stop signs)
|
| 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 to assign random terrain types (Nature is random, so is this!)
|
| 58 |
+
function getRandomTerrain() {
|
| 59 |
+
const terrains = ["water", "plains", "forest", "mountain"];
|
| 60 |
+
return terrains[Math.floor(Math.random() * terrains.length)];
|
| 61 |
+
}
|
| 62 |
|
| 63 |
+
// π¨ Function to get terrain color (Paint the world!)
|
| 64 |
+
function getTerrainColor(type) {
|
| 65 |
+
switch (type) {
|
| 66 |
+
case "water": return "#3A80BA"; // π¦ Blue for water
|
| 67 |
+
case "plains": return "#C2B280"; // πΎ Golden for plains
|
| 68 |
+
case "forest": return "#228B22"; // π² Green for forests
|
| 69 |
+
case "mountain": return "#A9A9A9"; // β°οΈ Gray for mountains
|
| 70 |
+
default: return "#FFFFFF"; // β If all else fails, white!
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
|
| 74 |
+
// ποΈ Function to render the map (A masterpiece in the making!)
|
| 75 |
+
function renderMap() {
|
| 76 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 77 |
+
hexGrid.forEach(hex => drawHex(hex.x, hex.y, hex.type));
|
| 78 |
+
}
|
| 79 |
|
| 80 |
+
// π Initialize and draw map
|
| 81 |
generateHexGrid();
|
| 82 |
renderMap();
|
| 83 |
+
</script>
|
| 84 |
+
</body>
|
| 85 |
+
</html>
|