-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptBall.js
More file actions
72 lines (60 loc) · 1.61 KB
/
ScriptBall.js
File metadata and controls
72 lines (60 loc) · 1.61 KB
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
const container = jQuery("#container-ball");
const easyButton = jQuery("#easy");
const mediumButton = jQuery("#medium");
const hardButton = jQuery("#hard");
const startGame = jQuery("#start-button");
const reset = jQuery("#reset");
const box_point = jQuery("#box_points");
let Point = 0;
Point = parseInt(Point);
let intervalId;
function createBall() {
let x = Math.floor(Math.random() * (container.width() - 65));
let y = Math.floor(Math.random() * (container.height() - 65));
let ball = jQuery("<div></div>");
ball.addClass("target");
ball.html('<i class="fa-solid fa-bullseye"></i>');
ball.css("left", x + "px");
ball.css("top", y + "px");
ball.click(function () {
ball.remove();
Point++;
box_point.text(Point);
});
container.append(ball);
}
function startInterval(time) {
clearInterval(intervalId);
intervalId = setInterval(createBall, time * 1000);
}
function setDifficultyLevel(time) {
Point = 0;
txtTimer.text("00:00");
box_point.text("0");
startTimer();
startInterval(time);
jQuery(".target").remove();
}
easyButton.click(function () {
setDifficultyLevel(1.3);
});
mediumButton.click(function () {
setDifficultyLevel(1);
});
hardButton.click(function () {
setDifficultyLevel(0.3);
});
startGame.click(function () {
startInterval(0.7);
jQuery(".target").remove();
txtTimer.text("00:00");
startTimer();
});
reset.click(function () {
clearInterval(intervalTimer);
clearInterval(intervalId);
jQuery(".target").remove();
txtTimer.text("00:00");
Point = 0;
box_point.text("0");
});