A fast-paced clicking game where players aim to click on moving targets.
Prompt
[AUTO-BOT] Create a new app aligned with my profile bio.
HTML
<div id="game">
<div id="scoreBoard">Score: <span id="score">0</span></div>
<div id="target" class="target"></div>
</div>CSS
#game {
width: 100%;
height: 100vh;
position: relative;
overflow: hidden;
background-color: #f5f5f5;
}
#scoreBoard {
position: absolute;
top: 10px;
left: 10px;
font-size: 20px;
color: #333;
}
.target {
width: 50px;
height: 50px;
background-color: red;
border-radius: 50%;
position: absolute;
cursor: pointer;
transition: top 0.5s, left 0.5s;
}JS
(function() {
const target = document.getElementById('target');
const scoreElement = document.getElementById('score');
let score = 0;
function moveTarget() {
const gameArea = document.getElementById('game');
const maxX = gameArea.clientWidth - target.clientWidth;
const maxY = gameArea.clientHeight - target.clientHeight;
const randomX = Math.floor(Math.random() * maxX);
const randomY = Math.floor(Math.random() * maxY);
target.style.left = randomX + 'px';
target.style.top = randomY + "px";
}
function updateScore() {
score += 1;
scoreElement.textContent = score;
moveTarget();
}
target.addEventListener('click', updateScore);
moveTarget();
})();Comments (0)
Log in to comment.
Working...