├── 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 | Random Cube 7 | 8 | 9 | 10 |
11 |

Timer 0

12 |

Score 0

13 |
14 |
15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | * { 2 | margin: 0; 3 | padding: 0; 4 | box-sizing: border-box; 5 | } 6 | 7 | html { 8 | font-family: sans-serif; 9 | background-color: rgb(42, 42, 42); 10 | } 11 | 12 | body { 13 | padding: 25px; 14 | } 15 | 16 | #container { 17 | width: 600px; 18 | max-width: 100%; 19 | height: 700px; 20 | background: rgb(255, 179, 0); 21 | border: 2px solid black; 22 | margin-top: 40px; 23 | } 24 | 25 | #player { 26 | width: 40px; 27 | height: 40px; 28 | background-color: rgb(255, 0, 0); 29 | margin-top: 40px; 30 | cursor: pointer; 31 | border-radius: 2px; 32 | } 33 | 34 | #timer { 35 | font-weight: bold; 36 | font-size: 40px; 37 | } 38 | 39 | @media (max-width: 1000px) { 40 | #container { 41 | height: 400px; 42 | border-radius: 5px; 43 | } 44 | } 45 | --------------------------------------------------------------------------------