-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.html
260 lines (253 loc) · 6.45 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<!DOCTYPE html>
<head>
<title>Slot Machine</title>
<style>
@import url('https://fonts.googleapis.com/css?family=Roboto');
@import url('https://fonts.googleapis.com/css?family=Roboto+Mono');
a{
color: #283593;
text-decoration: none;
}
h3{
margin-top: 12px;
}
*{
margin:0px;
}
body{
background-color: #424242;
font-family: 'Roboto', sans-serif;
}
main{
border-radius: 5px;
background-color: #EF5350;
margin-top: 30px;
padding-top: 20px;
padding-bottom: 20px;
padding-left: 15px;
padding-right: 15px;
margin-left: calc((100% - 580px) / 2);
width: 550px;
}
section#status{
margin-bottom: 25px;
padding-top: 25px;
padding-bottom: 25px;
border-radius: 5px;
text-align: center;
background-color: #37474F;
color: #FFFFFF;
font-size: 25px;
font-family: 'Roboto Mono', monospace;
}
section#Slots{
border-radius: 15px;
background-color: #FAFAFA;
}
section#Gira{
margin-top: 25px;
padding-top: 25px;
padding-bottom: 25px;
border-radius: 5px;
text-align: center;
background-color: #AB47BC;
color: #FFFFFF;
font-size: 25px;
}
section#Gira:hover{
background-color: #BA68C8;
}
section#options{
margin-top: 20px;
padding-top: 5px;
border-radius: 5px;
background-color: #C62828;
color: #FFFFFF;
}
.option{
padding-left: 5px;
}
section#info{
background-color: #616161;
padding-left: 12px;
padding-bottom: 12px;
border-radius: 5px;
overflow: hidden;
animation-duration: 1s;
color: #BDBDBD;
margin-top: 50px;
margin-left: 30%;
margin-right: 30%;
display: none;
}
#slot1, #slot2, #slot3{
display: inline-block;
margin-top: 5px;
margin-left: 15px;
margin-right: 15px;
background-size: 150px;
width: 150px;
height: 150px;
}
.a1{
background-image: url("res/tiles/seven.png");
}
.a2{
background-image: url("res/tiles/cherries.png");
}
.a3{
background-image: url("res/tiles/club.png");
}
.a4{
background-image: url("res/tiles/diamond.png");
}
.a5{
background-image: url("res/tiles/heart.png");
}
.a6{
background-image: url("res/tiles/spade.png");
}
.a7{
background-image: url("res/tiles/joker.png");
}
</style>
</head>
<html>
<body onload="toggleAudio()">
<main>
<section id="status">WELCOME!</section>
<section id="Slots">
<div id="slot1" class="a1"></div>
<div id="slot2" class="a1"></div>
<div id="slot3" class="a1"></div>
</section>
<section onclick="doSlot()" id="Gira">TAKE A SPIN!</section>
<section id="options">
<img src="res/icons/audioOn.png" id="audio" class="option" onclick="toggleAudio()" />
</section>
</main>
<section id="info">
<h3>Come si Gioca?</h3>
<p>Tenta la tua fortuna premendo il bottone! Il Jolly vale l'elemento mancante per vincere. Tre elementi uguali e vinici! Ma attenzione, non prendere tre Jolly o perderai!</p>
<h3>Licenza</h3>
<p><a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Licenza Creative Commons" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br />Quest'opera è distribuita con Licenza <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribuzione - Non commerciale - Condividi allo stesso modo 4.0 Internazionale</a>.</p>
</section>
<script>
var doing = false;
var spin = [new Audio("res/sounds/spin.mp3"),new Audio("res/sounds/spin.mp3"),new Audio("res/sounds/spin.mp3"),new Audio("res/sounds/spin.mp3"),new Audio("res/sounds/spin.mp3"),new Audio("res/sounds/spin.mp3"),new Audio("res/sounds/spin.mp3")];
var coin = [new Audio("res/sounds/coin.mp3"),new Audio("res/sounds/coin.mp3"),new Audio("res/sounds/coin.mp3")]
var win = new Audio("res/sounds/win.mp3");
var lose = new Audio("res/sounds/lose.mp3");
var audio = false;
let status = document.getElementById("status")
var info = true;
function doSlot(){
if (doing){return null;}
doing = true;
var numChanges = randomInt(1,4)*7
var numeberSlot1 = numChanges+randomInt(1,7)
var numeberSlot2 = numChanges+2*7+randomInt(1,7)
var numeberSlot3 = numChanges+4*7+randomInt(1,7)
var i1 = 0;
var i2 = 0;
var i3 = 0;
var sound = 0
status.innerHTML = "SPINNING"
slot1 = setInterval(spin1, 50);
slot2 = setInterval(spin2, 50);
slot3 = setInterval(spin3, 50);
function spin1(){
i1++;
if (i1>=numeberSlot1){
coin[0].play()
clearInterval(slot1);
return null;
}
slotTile = document.getElementById("slot1");
if (slotTile.className=="a7"){
slotTile.className = "a0";
}
slotTile.className = "a"+(parseInt(slotTile.className.substring(1))+1)
}
function spin2(){
i2++;
if (i2>=numeberSlot2){
coin[1].play()
clearInterval(slot2);
return null;
}
slotTile = document.getElementById("slot2");
if (slotTile.className=="a7"){
slotTile.className = "a0";
}
slotTile.className = "a"+(parseInt(slotTile.className.substring(1))+1)
}
function spin3(){
i3++;
if (i3>=numeberSlot3){
coin[2].play()
clearInterval(slot3);
testWin();
return null;
}
slotTile = document.getElementById("slot3");
if (slotTile.className=="a7"){
slotTile.className = "a0";
}
sound++;
if (sound==spin.length){
sound=0;
}
spin[sound].play();
slotTile.className = "a"+(parseInt(slotTile.className.substring(1))+1)
}
}
function testWin(){
var slot1 = document.getElementById("slot1").className
var slot2 = document.getElementById("slot2").className
var slot3 = document.getElementById("slot3").className
if (((slot1 == slot2 && slot2 == slot3) ||
(slot1 == slot2 && slot3 == "a7") ||
(slot1 == slot3 && slot2 == "a7") ||
(slot2 == slot3 && slot1 == "a7") ||
(slot1 == slot2 && slot1 == "a7") ||
(slot1 == slot3 && slot1 == "a7") ||
(slot2 == slot3 && slot2 == "a7") ) && !(slot1 == slot2 && slot2 == slot3 && slot1=="a7")){
status.innerHTML = "YOU WIN!";
win.play();
}else{
status.innerHTML = "YOU LOSE!"
lose.play();
}
doing = false;
}
function toggleAudio(){
if (!audio){
audio = !audio;
for (var x of spin){
x.volume = 0.5;
}
for (var x of coin){
x.volume = 0.5;
}
win.volume = 1.0;
lose.volume = 1.0;
}else{
audio = !audio;
for (var x of spin){
x.volume = 0;
}
for (var x of coin){
x.volume = 0;
}
win.volume = 0;
lose.volume = 0;
}
document.getElementById("audio").src = "res/icons/audio"+(audio?"On":"Off")+".png";
}
function randomInt(min, max){
return Math.floor((Math.random() * (max-min+1)) + min);
}
</script>
</body>
</html>