From f7b67d3de3086adfcc3ca65e1445e90e758a222a Mon Sep 17 00:00:00 2001 From: GreeningSiren Date: Sun, 2 Jun 2024 18:44:17 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Hex=20Minesweeper=20v1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 3 +- mainznaaa/game.js | 111 +++++++++++++++ mainznaaa/index.html | 318 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 431 insertions(+), 1 deletion(-) create mode 100644 mainznaaa/game.js create mode 100644 mainznaaa/index.html diff --git a/index.html b/index.html index 5251e29..06fef4d 100644 --- a/index.html +++ b/index.html @@ -25,7 +25,8 @@ Sokoban Level Editor Hex Snake - + Hex Minesweeper +
GO TO MAIN PAGE! diff --git a/mainznaaa/game.js b/mainznaaa/game.js new file mode 100644 index 0000000..5303c06 --- /dev/null +++ b/mainznaaa/game.js @@ -0,0 +1,111 @@ +let mini = []; +let otvoreno = []; + +function drawHexagon(x, y, radius) { + context.moveTo( + Math.cos(Math.PI / 6), + -Math.sin(Math.PI / 6) + ); + context.beginPath(); + for (let i = 1; i <= 6; i++) { + let ugul = Math.PI / 6 + i * Math.PI / 3; + context.lineTo( + Math.cos(ugul) * radius + x, + -Math.sin(ugul) * radius + y + ); + } + context.fill(); +} + +function init() { + for (let i = 0; i < 10; i++) { + mini[i] = []; + otvoreno[i] = []; + for (let j = 0; j < 10; j++) { + mini[i][j] = randomInteger(2); + otvoreno[i][j] = false; + } + } +} +function update() { +} +function draw() { + context.fillStyle = "black"; + context.fillRect(0, 0, 800, 600); + context.fillStyle = "green"; + for (let kolona = 0; kolona < 10; kolona++) { + for (let red = 0; red < 10; red++) { + if (otvoreno[kolona][red]) { + if (mini[kolona][red]) { + context.fillStyle = "#FF0000"; + } else { + context.fillStyle = "#00FF00"; + } + } else { + context.fillStyle = "#FFFFFF"; + } + if (red % 2 === 0) { + drawHexagon( + 100 + kolona * (Math.cos(Math.PI / 6)) * 30 * 2, + 100 + red * 30 * 1.5, + 29 + ); + } else { + drawHexagon( + 100 + kolona * (Math.cos(Math.PI / 6)) * 30 * 2 + Math.cos(Math.PI / 6) * 30, + 100 + red * 30 * 1.5, + 29 + ); + } + } + } + // Tuk naprogramirai kakvo da se risuva + +} +function mouseup() { + // Pri klik s lqv buton - pokaji koordinatite na mishkata + console.log("Mouse clicked at", mouseX, mouseY); + for (let red = 0; red < 10; red++) { + for (let kolona = 0; kolona < 10; kolona++) { + let centurX; + let centurY = 100 + red * 30 * 1.5; + if (red % 2 === 1) { + centurX = 100 + kolona * (Math.cos(Math.PI / 6)) * 30 * 2 + Math.cos(Math.PI / 6) * 30; + } else { + centurX = 100 + kolona * (Math.cos(Math.PI / 6)) * 30 * 2; + } + let dist = Math.sqrt((mouseY - centurY) * (mouseY - centurY) + + (mouseX - centurX) * (mouseX - centurX)); + if (dist < Math.cos(Math.PI / 6) * 30 && red % 2 === 0) { + otvoreno[kolona][red] = true; + otvoreno[kolona + 1][red] = true; + otvoreno[kolona - 1][red] = true; + otvoreno[kolona][red + 1] = true; + otvoreno[kolona][red - 1] = true; + otvoreno[kolona ][red + 1] = true; + otvoreno[kolona][red - 1] = true; + otvoreno[kolona - 1][red + 1] = true; + otvoreno[kolona - 1][red - 1] = true; + + + } + if (dist < Math.cos(Math.PI / 6) * 30 && red % 2 === 1) { + otvoreno[kolona][red] = true; + otvoreno[kolona + 1][red] = true; + otvoreno[kolona - 1][red] = true; + otvoreno[kolona][red + 1] = true; + otvoreno[kolona][red - 1] = true; + otvoreno[kolona ][red + 2] = true; + otvoreno[kolona][red - 2] = true; + otvoreno[kolona - 1][red + 2] = true; + otvoreno[kolona - 1][red - 2] = true; + + + } + } + } +} +function keyup(key) { + // Pechatai koda na natisnatiq klavish + console.log("Pressed", key); +} diff --git a/mainznaaa/index.html b/mainznaaa/index.html new file mode 100644 index 0000000..555e8f2 --- /dev/null +++ b/mainznaaa/index.html @@ -0,0 +1,318 @@ + + + + + + + + + + + + + + + + + + + +