-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.html
149 lines (131 loc) · 4.48 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
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="Slot machine game">
<meta name="keywords" content="HTML, CSS, JavaScript, Slot Machine, Game">
<meta name="author" content="Jee Vang, Ph.D.">
<meta name="organization" content="One-Off Coder">
<title>Slot Machine!</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.min.css">
<style>
* {
font-family: monospace;
}
body {
margin: 10px;
}
.slot-number {
font-size: 100px;
}
.message {
text-align: center;
display: none;
font-size: xx-large;
color: red;
}
.center {
text-align: center;
}
.lever {
margin-top: 5px;
}
table.center {
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>
<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1 class="display-4">Play Slot!</h1>
<p class="lead">
Slot machine simulator
</p>
<p>
<a href="https://github.com/oneoffcoder/lightning-projects/tree/master/html/slot-machine-game" target="_blank">
Source Code
</a>
</p>
<hr class="my-4">
<p>
Hit lever button to start
</p>
</div>
</div>
<div class="center lever">
<button type="button" class="btn btn-primary" onclick="spin()">Lever</button>
</div>
<table class="center">
<tbody>
<tr>
<td>
<span id="item1" class="slot-number">-</span>
</td>
<td>
<span id="item2" class="slot-number">-</span>
</td>
<td>
<span id="item3" class="slot-number">-</span>
</td>
</tr>
</tbody>
</table>
<div id="message" class="center message">
You Won!
</div>
<audio id="boing">
<source src="boing.mp3" type="audio/mpeg">
</audio>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"
integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/howler/2.2.0/howler.min.js" crossorigin="anonymous"></script>
<script>
function getRandomNumber() {
return Math.floor(Math.random() * 2) + 1;
}
function getElement(id) {
return document.getElementById(id);
}
function spin() {
const item1 = getElement('item1');
const item2 = getElement('item2');
const item3 = getElement('item3');
const num1 = getRandomNumber();
const num2 = getRandomNumber();
const num3 = getRandomNumber();
item1.innerHTML = `${num1}`;
item2.innerHTML = `${num2}`;
item3.innerHTML = `${num3}`;
if (num1 === num2 && num1 === num3) {
playBoing();
showMessage();
} else {
hideMessage();
}
}
function playBoing() {
const boing = document.getElementById("boing");
boing.play();
}
function showMessage() {
const msg = document.getElementById("message");
msg.style.display = "block";
msg.classList.add('animated', 'pulse')
}
function hideMessage() {
const msg = document.getElementById("message");
msg.style.display = "none";
}
</script>
</body>
</html>