Compare commits
2 Commits
854a6135da
...
7c3e6851aa
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c3e6851aa | |||
| e7c73920d4 |
@ -241,7 +241,7 @@ body {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
/* === 8 GAMBAR (16 kartu) === */
|
|
||||||
const images = [
|
const images = [
|
||||||
"asset/alpukat.jpg",
|
"asset/alpukat.jpg",
|
||||||
"asset/anggur.jpg",
|
"asset/anggur.jpg",
|
||||||
@ -280,12 +280,32 @@ function showComboPopup(targetCard, combo, bonus) {
|
|||||||
setTimeout(() => popup.remove(), 1500);
|
setTimeout(() => popup.remove(), 1500);
|
||||||
}
|
}
|
||||||
|
|
||||||
function shuffleArray(array) {
|
|
||||||
for (let i = array.length - 1; i > 0; i--) {
|
function shuffleDistant(cards, minDistance = 5) {
|
||||||
const j = Math.floor(Math.random() * (i + 1));
|
let valid = false;
|
||||||
[array[i], array[j]] = [array[j], array[i]];
|
let result;
|
||||||
|
|
||||||
|
while (!valid) {
|
||||||
|
result = [...cards].sort(() => Math.random() - 0.5);
|
||||||
|
valid = true;
|
||||||
|
const checked = new Set();
|
||||||
|
|
||||||
|
for (let i = 0; i < result.length; i++) {
|
||||||
|
const value = result[i];
|
||||||
|
if (checked.has(value)) continue;
|
||||||
|
checked.add(value);
|
||||||
|
|
||||||
|
const firstIndex = result.indexOf(value);
|
||||||
|
const lastIndex = result.lastIndexOf(value);
|
||||||
|
const distance = Math.abs(lastIndex - firstIndex);
|
||||||
|
|
||||||
|
if (distance < minDistance) {
|
||||||
|
valid = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return array;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function startTimer() {
|
function startTimer() {
|
||||||
@ -359,7 +379,7 @@ function startGame() {
|
|||||||
const board = document.getElementById("game-board");
|
const board = document.getElementById("game-board");
|
||||||
board.innerHTML = "";
|
board.innerHTML = "";
|
||||||
|
|
||||||
shuffleArray([...cards]).forEach(image => {
|
shuffleDistant(cards, 4).forEach(image => {
|
||||||
const card = document.createElement("div");
|
const card = document.createElement("div");
|
||||||
card.className = "card";
|
card.className = "card";
|
||||||
card.innerHTML = `
|
card.innerHTML = `
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user