|
|
|
@ -1,3 +1,41 @@ |
|
|
|
function rand_in_range(from, to) { |
|
|
|
|
|
|
|
const rand = Math.floor(Math.random() * (to - from + 1)) + from |
|
|
|
const is_neg = Math.random() < 0.5 |
|
|
|
|
|
|
|
return is_neg ? -rand : rand |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function shuffle_cards() { |
|
|
|
|
|
|
|
const cards = document.querySelectorAll('.card') |
|
|
|
const random_index = Math.floor(Math.random() * cards.length); |
|
|
|
|
|
|
|
cards.forEach((card, index) => { |
|
|
|
if (index == random_index) { |
|
|
|
card.classList.add('active') |
|
|
|
card.style.zIndex = '1' |
|
|
|
card.style.transform = `none` |
|
|
|
} else { |
|
|
|
card.classList.remove('active') |
|
|
|
card.style.zIndex = 'auto' |
|
|
|
card.style.transform = `rotate(${rand_in_range(2,5)}deg) translate(${rand_in_range(2,5)}px, ${rand_in_range(2,5)}px)` |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
document.querySelectorAll('.button_shuffle_cards').forEach((item, index) => { |
|
|
|
item.addEventListener('click', (e) => { |
|
|
|
shuffle_cards() |
|
|
|
}) |
|
|
|
if (index == 0) |
|
|
|
shuffle_cards() |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// Choose language confirmation button
|
|
|
|
document.querySelectorAll('#confirm_btn').forEach((confirm_btn) => { |
|
|
|
confirm_btn.addEventListener('click', (e) => { |
|
|
|
@ -40,8 +78,10 @@ function unlockStartHandler() { |
|
|
|
function unlockEndHandler() { |
|
|
|
curr_value = +this.value; |
|
|
|
|
|
|
|
if (curr_value >= this.max) { |
|
|
|
alert('Unlocked'); |
|
|
|
if (curr_value >= this.max) { |
|
|
|
|
|
|
|
const card = document.querySelector('.card.active') |
|
|
|
window.location.href = card.parentNode.getAttribute('href') |
|
|
|
|
|
|
|
// reset
|
|
|
|
this.value = 0; |
|
|
|
|