(interval1, interval2)
| 37 | |
| 38 | // Function to handle pixel creating and related events |
| 39 | function Pixel(interval1, interval2) { |
| 40 | const pixel = document.createElement("div"); |
| 41 | pixel.classList.add("pixel"); |
| 42 | pixel.style.left = Math.random() * (window.innerWidth - 50) + "px"; |
| 43 | pixel.style.animationDuration = fallingSpeed + "s"; |
| 44 | document.body.appendChild(pixel); |
| 45 | |
| 46 | // When the player clicks on a pixel |
| 47 | pixel.addEventListener("click", function () { |
| 48 | pixel.classList.add("clicked"); |
| 49 | pixel.style.scale = "0"; |
| 50 | currentScore += 10; // update player score with 10 |
| 51 | document.getElementById("score-count").innerText = currentScore; |
| 52 | setTimeout(() => { |
| 53 | pixel.remove(); |
| 54 | }, 500); |
| 55 | }); |
| 56 | |
| 57 | |
| 58 | //Check if reaches bottom of screen |
| 59 | setTimeout( () => { |
| 60 | pixel.remove(); |
| 61 | |
| 62 | if (!pixel.classList.contains("clicked")) { |
| 63 | currentLives = currentLives > 0 ? currentLives -=1 : currentLives; |
| 64 | document.getElementById("lives-count").innerText = currentLives; |
| 65 | if(currentLives === 0) |
| 66 | { |
| 67 | document.getElementById('game-over-msg').style.display = 'block'; |
| 68 | clearInterval(interval1); |
| 69 | clearInterval(interval2); |
| 70 | deletePixels(); |
| 71 | |
| 72 | } |
| 73 | } |
| 74 | }, fallingSpeed * 1000); |
| 75 | } |
| 76 | |
| 77 | |
| 78 |
no test coverage detected