awacke1 commited on
Commit
adff28c
Β·
verified Β·
1 Parent(s): c371d92

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +74 -56
index.html CHANGED
@@ -1,67 +1,85 @@
1
- const canvas = document.getElementById("gameCanvas");
2
- const ctx = canvas.getContext("2d");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- // Hexagon properties
5
- const hexSize = 50; // Size of each hexagon
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
- for (let row = 0; row < rows; row++) {
19
- for (let col = 0; col < cols; col++) {
20
- let x = col * offsetX;
21
- let y = row * hexHeight + (col % 2 ? offsetY : 0);
22
- hexGrid.push({ x, y, type: getRandomTerrain() });
 
 
23
  }
24
- }
25
- }
26
 
27
- // Function to draw hexagons
28
- function drawHex(x, y, type) {
29
- ctx.beginPath();
30
- for (let i = 0; i < 6; i++) {
31
- let angle = (Math.PI / 3) * i;
32
- let px = x + hexSize * Math.cos(angle);
33
- let py = y + hexSize * Math.sin(angle);
34
- ctx.lineTo(px, py);
35
- }
36
- ctx.closePath();
37
- ctx.fillStyle = getTerrainColor(type);
38
- ctx.fill();
39
- ctx.stroke();
40
- }
41
 
42
- // Function to assign random terrain types
43
- function getRandomTerrain() {
44
- const terrains = ["water", "plains", "forest", "mountain"];
45
- return terrains[Math.floor(Math.random() * terrains.length)];
46
- }
47
 
48
- // Function to get terrain color
49
- function getTerrainColor(type) {
50
- switch (type) {
51
- case "water": return "#3A80BA";
52
- case "plains": return "#C2B280";
53
- case "forest": return "#228B22";
54
- case "mountain": return "#A9A9A9";
55
- default: return "#FFFFFF";
56
- }
57
- }
58
 
59
- // Function to render the map
60
- function renderMap() {
61
- ctx.clearRect(0, 0, canvas.width, canvas.height);
62
- hexGrid.forEach(hex => drawHex(hex.x, hex.y, hex.type));
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>