-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
166 lines (149 loc) · 7.22 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Aim Trainer</title>
<style>
html, body {
width: 100%; /* Ensure the body takes full width */
min-height: 100vh; /* Ensure the body takes at least the full height of the viewport */
margin: 0; /* Remove default margin */
font-family: 'Arial', sans-serif;
background-color: #282c34; /* Dark background for better contrast */
padding: 0; /* Remove default padding */
overflow: hidden;
}
h1 {
color: #61afef; /* Bright color for the header */
text-align: center;
margin-bottom: 50px; /* Adds space below the header */
}
#scoreDisplay {
position: fixed; /* Fixed positioning relative to the viewport */
top: 20px; /* Distance from the top of the viewport */
right: 20px; /* Distance from the right of the viewport */
font-size: 20px; /* Larger font size for better visibility */
color: #61afef; /* Color for the score text, adjust as needed */
background-color: transparent; /* Maintain the background consistency */
}
.circle {
width: 50px;
height: 50px;
border-radius: 50%;
position: absolute;
transition: all 0.2s ease;
cursor: pointer;
}
#settingsButton {
position: fixed; /* Fixed position to keep it in the same place */
top: 10px; /* Distance from the top */
left: 10px; /* Distance from the left */
padding: 10px 20px; /* Padding inside the button */
font-size: 16px; /* Text size */
color: #FFF; /* Text color */
background-color: #333; /* Button background color */
border: none; /* Remove default border */
border-radius: 5px; /* Slightly rounded corners for a modern look */
cursor: pointer; /* Change cursor to pointer on hover */
z-index: 1000; /* Ensure the button is above other elements */
}
#settingsButton:hover {
background-color: #555; /* Slightly change color on hover for feedback */
}
#difficultyOptions button {
display: block; /* Stack the buttons vertically */
margin: 5px 0; /* Add some space between the buttons */
padding: 5px 10px; /* Padding inside the button */
font-size: 14px; /* Text size */
color: #FFF; /* Text color */
background-color: #333; /* Button background color */
border: none; /* Remove default border */
border-radius: 5px; /* Rounded corners */
cursor: pointer; /* Change cursor to pointer on hover */
}
#difficultyOptions button:hover {
background-color: #555; /* Slightly change color on hover for feedback */
}
</style>
</head>
<body>
<h1>Aim Trainer</h1>
<button id="settingsButton">Settings</button>
<div id="difficultyOptions" style="display: none; position: fixed; top: 40px; left: 10px; background-color: #282c34; padding: 10px; border-radius: 5px;">
<button id="easyButton">Easy</button>
<button id="hardButton">Hard</button>
</div>
<div id="scoreDisplay">Score: 0</div>
<script>
let score = 0;
let difficulty = 'easy'; // Keep track of the current difficulty
function generateCircle() {
const circle = document.createElement('div');
circle.classList.add('game-circle'); // Add this line to ensure the circle has a class
let circleSize = 50; // Default size for easy difficulty
if (difficulty === 'hard') {
circleSize = Math.random() * (60 - 30) + 30; // Random size between 30px and 60px for hard difficulty
}
circle.style.width = `${circleSize}px`;
circle.style.height = `${circleSize}px`;
circle.style.borderRadius = '50%';
circle.style.backgroundColor = 'red';
circle.style.position = 'absolute';
// Adjust position to avoid spawning at the edges, considering dynamic size
const maxWidth = window.innerWidth - circleSize;
const maxHeight = window.innerHeight - circleSize;
circle.style.left = `${Math.random() * maxWidth}px`;
circle.style.top = `${Math.random() * maxHeight}px`;
// Reintegrate the click functionality for circle respawning
circle.addEventListener('click', function(event) {
event.stopPropagation();
score++;
updateScoreDisplay();
document.body.removeChild(circle);
generateCircle(); // Ensure a new circle is generated upon click
});
document.body.appendChild(circle);
}
document.body.addEventListener('click', function(event) {
if (!event.target.classList.contains('game-circle')) {
console.log('Missed the circle!');
score = 0; // Reset score to 0
updateScoreDisplay(); // Update the score display
}
}, true);
function removeAllCircles() {
const existingCircles = document.querySelectorAll('.game-circle'); // Assuming you add this class to your circles
existingCircles.forEach(circle => {
document.body.removeChild(circle);
});
}
// Modify your difficulty button event listeners to include removeAllCircles
document.getElementById('easyButton').addEventListener('click', function() {
removeAllCircles(); // Remove existing circles before changing difficulty
difficulty = 'easy';
generateCircle(); // Regenerate the circle with the new difficulty
});
document.getElementById('hardButton').addEventListener('click', function() {
removeAllCircles(); // Remove existing circles before changing difficulty
difficulty = 'hard';
generateCircle(); // Regenerate the circle with the new difficulty
});
document.getElementById('settingsButton').addEventListener('click', function() {
const difficultyOptions = document.getElementById('difficultyOptions');
if (difficultyOptions.style.display === "none") {
difficultyOptions.style.display = "block";
} else {
difficultyOptions.style.display = "none";
}
});
// Ensure this function exists or is correctly implemented to update the score display
function updateScoreDisplay() {
const scoreDisplay = document.getElementById('scoreDisplay');
scoreDisplay.textContent = `Score: ${score}`;
}
// Initial circle generation
generateCircle();
</script>
</body>
</html>