-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
172 lines (164 loc) · 5.47 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
167
168
169
170
171
172
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Game</title>
</head>
<body onload="song(false)">
<audio id="audio" onended="reset(true)"></audio>
<button id="pulsante" onclick="start()">Start</button>
<h1 id="titolo">Timer: 0s | Cerchi: 0</h1>
<h2 id="cps">~0 Tocchi al secondo</h2>
<center>
<select id="difficolta" onchange="difficulty()">
<option value="easy">Facile</option>
<option value="medium" selected>Intermedio</option>
<option value="hard">Difficile</option>
</select>
<select id="musica" onchange="song(true)">
<optgroup label="Anime">
<option value="BakemonogatariRenaiCirculation">Bakemonogatari Renai Circulation</option>
<option value="TokyoGhoul">Tokyo Ghoul</option>
<option value="NoGameNoLife">No Game No Life</option>
<option value="OnePunchMan">One Punch Man</option>
<option value="HappySugarLife">Happy Sugar Life</option>
</optgroup>
<optgroup label="Altro">
<option value="debug">Debug</option>
</optgroup>
</select>
</center>
<div class="cerchio" id="cerchio"></div>
<style>
html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.cerchio {
position: relative;
width: 150px;
height: 150px;
background-color: cyan;
margin: 0;
padding: 0;
border-radius: 50%;
visibility: hidden;
}
h1,
h2 {
padding: 0;
margin: 0;
text-align: center;
user-select: none;
}
#pulsante {
position: absolute;
top: 50%;
left: 50%;
border-radius: 2%;
width: 5%;
height: 4%;
cursor: pointer;
}
*{
}
</style>
<script>
var cont = 0;
var timer = 0;
var flag = false;
var pressed = false;
var tempo = 700;
var audioCheck;
var clicks = 0;
let cerchio = document.getElementById("cerchio");
let titolo = document.getElementById("titolo");
let cps = document.getElementById("cps");
let xmlhr = new XMLHttpRequest();
let difficoltà = document.getElementById("difficolta");
let musica = document.getElementById("musica");
let audio = document.getElementById("audio");
let intervalObject;
cerchio.addEventListener("mouseover", update);
cerchio.addEventListener("click", update);
function updateText() {
titolo.innerHTML = "Timer: " + timer + "s | Cerchi: " + clicks;
cps.innerHTML = '~' + Math.round(cont / timer) + " Tocchi al secondo";
};
function reset(x) {
if (x) {
alert("Canzone completata in " + timer + " secondi");
}
timer = 0;
cont = 0;
clicks = 0;
clearInterval(intervalObject);
flag = false;
}
function update() {
if (!flag) {
intervalObject = setInterval(function () {
timer += 1;
updateText();
}, 1000);
audioCheck = setInterval(function () {
if (!pressed) {
audio.pause();
} else {
pressed = false;
}
updateText();
}, tempo);
flag = true;
}
clicks += 1;
audio.play();
pressed = true;
cerchio.style.left = Math.random() * (90 - 1) + 1 + "%";
cerchio.style.top = Math.random() * (80 - 1) + "%";
cerchio.style.backgroundColor = "rgb(" + Math.random() * 255 + ',' + Math.random() * 255 + ',' + Math.random() * 255 + ")";
cont += 1;
updateText();
}
function start() {
cerchio.style.visibility = "visible";
document.getElementById("pulsante").style.visibility = "hidden";
}
function difficulty() {
clearInterval(audioCheck);
if (difficoltà.value == "easy") {
tempo = 1800;
cerchio.style.width = "300px";
cerchio.style.height = "300px";
} else if (difficoltà.value == "medium") {
tempo = 1000;
cerchio.style.width = "170px";
cerchio.style.height = "170px";
} else if (difficoltà.value == "hard") {
tempo = 500;
cerchio.style.width = "110px";
cerchio.style.height = "110px";
}
audioCheck = setInterval(function () {
if (!pressed) {
audio.pause();
} else {
pressed = false;
}
updateText();
}, tempo);
}
function song(x) {
if (x) {
reset(false);
}
document.getElementById("audio").src = "Custom/Songs/" + musica.value + ".mp3"
}
</script>
</body>
</html>