Skip to content

Commit

Permalink
feat: 🎸 Hex Minesweeper v1
Browse files Browse the repository at this point in the history
  • Loading branch information
GreeningSiren committed Jun 2, 2024
1 parent c6cad27 commit f7b67d3
Show file tree
Hide file tree
Showing 3 changed files with 431 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
<a href="./sokoban" class="foldersender">Sokoban</a>
<a href="./leveleditor" class="foldersender">Level Editor</a>
<a href="./mnogulsnak" class="foldersender">Hex Snake</a>
<a href="./tupa googleplay igra/" class="foldersender"></a>
<a href="./mainznaaa" class="foldersender">Hex Minesweeper</a>
<!-- <a href="./tupa googleplay igra/" class="foldersender"></a>-->
</div>
<div class="maincontainer">
<a href="https://greeningsiren.github.io/" class="mainpagelink">GO TO MAIN PAGE!</a>
Expand Down
111 changes: 111 additions & 0 deletions mainznaaa/game.js
Original file line number Diff line number Diff line change
@@ -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);
}
Loading

0 comments on commit f7b67d3

Please sign in to comment.