0% found this document useful (0 votes)
8 views2 pages

Game Code

This document is an HTML code for a simple web game called 'Click the Circle'. The game consists of a red circle that moves randomly within a defined area, and players score points by clicking on the circle. The score is displayed on the screen and updates each time the circle is clicked.

Uploaded by

zubair malik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Game Code

This document is an HTML code for a simple web game called 'Click the Circle'. The game consists of a red circle that moves randomly within a defined area, and players score points by clicking on the circle. The score is displayed on the screen and updates each time the circle is clicked.

Uploaded by

zubair malik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

<!

DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Click the Circle Game</title>
<style>
body {
text-align: center;
font-family: Arial, sans-serif;
}
#gameArea {
width: 400px;
height: 400px;
border: 2px solid black;
margin: auto;
position: relative;
overflow: hidden;
}
#circle {
width: 50px;
height: 50px;
background-color: red;
border-radius: 50%;
position: absolute;
}
</style>
</head>
<body>

<h1>Click the Circle!</h1>


<p>Score: <span id="score">0</span></p>
<div id="gameArea">
<div id="circle"></div>
</div>

<script>
let score = 0;
const circle = document.getElementById("circle");
const scoreDisplay = document.getElementById("score");

function moveCircle() {
const x = Math.random() * 350;
const y = Math.random() * 350;
circle.style.left = x + "px";
circle.style.top = y + "px";
}

circle.addEventListener("click", () => {
score++;
scoreDisplay.textContent = score;
moveCircle();
});
moveCircle();
</script>
</body>
</html>

You might also like