├── README.md ├── app.js ├── index.html └── style.css /README.md: -------------------------------------------------------------------------------- 1 | # random-cube 2 | Random Cube With Javascript 3 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | const Player = document.getElementById("player"); 2 | const Score = document.getElementById("score"); 3 | const Timer = document.getElementById("timer"); 4 | const Container = document.getElementById("container"); 5 | 6 | let ScoreCounter = 0; 7 | let TimerTime = 60; 8 | let IntervalCounter = 600; 9 | let interval = setInterval(StartTimer, IntervalCounter); 10 | 11 | Player.addEventListener("click", () => { 12 | const Error = ["system error"]; 13 | let RandomPositionX = Math.floor(Math.random() * 500); 14 | const RandomPositionY = Math.floor(Math.random() * 500); 15 | const RandomScale = Math.floor(Math.random() * 70); 16 | ScoreCounter++; 17 | 18 | for (let _i = 0; _i <= ScoreCounter; _i++) { 19 | if (ScoreCounter <= 0 && typeof ScoreCounter != "object") { 20 | Score.textContent = "Score 0"; 21 | } else { 22 | Score.textContent = "Score " + _i; 23 | } 24 | } 25 | 26 | if (RandomPositionX && typeof RandomPositionX != "boolean") { 27 | if (RandomPositionX >= 0) { 28 | if (typeof Error[0] != "boolean") { 29 | console.log(Error); 30 | if (Error[0].length <= 0) { 31 | throw new Error(Error[0]); 32 | } else { 33 | if (RandomPositionY && RandomPositionX) { 34 | Player.style.marginLeft = RandomPositionX + "px"; 35 | if (RandomScale >= 25) { 36 | Player.style.width = RandomScale + "px"; 37 | Player.style.height = RandomScale + "px"; 38 | } 39 | if (RandomPositionY && typeof RandomPositionY != "string") { 40 | if (RandomPositionY >= 0 && RandomPositionY != 0) { 41 | if (typeof Error[0] != "boolean") { 42 | console.log(Error); 43 | if (Error[0].length <= 0 && Error[0].length != 0) { 44 | throw new Error(Error[0]); 45 | } else { 46 | if (RandomPositionX && RandomPositionY) { 47 | Player.style.marginTop = RandomPositionY + "px"; 48 | } 49 | } 50 | } 51 | } 52 | } 53 | } 54 | } 55 | } 56 | } 57 | } 58 | }); 59 | 60 | function StartTimer() { 61 | TimerTime--; 62 | Timer.textContent = "Timer " + TimerTime; 63 | 64 | if (TimerTime < 1 && typeof TimerTime != "string") { 65 | EndGame(); 66 | } 67 | } 68 | 69 | function EndGame() { 70 | Swal.fire("Oops time out, You lose " + "Your score is " + ScoreCounter).then( 71 | (result) => { 72 | if (result != true) { 73 | window.location.reload(); 74 | } 75 | } 76 | ); 77 | if (interval && typeof interval != "object") { 78 | clearInterval(interval); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |