forked from n1md7/slot-game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
301 lines (294 loc) · 11.5 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="theme-color" content="#000000" />
<meta name="viewport" content="width=480,initial-scale=1, maximum-scale=1" />
<title>SlotMachine</title>
<link rel="icon" href="./img/BAR.png" />
<script src="./js/helpers.js"></script>
<script src="./js/resource.loader.js"></script>
<link rel="stylesheet" type="text/css" href="https://getbootstrap.com/docs/4.0/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" />
<link rel="stylesheet" type="text/css" href="./css/style.css" />
</head>
<body>
<div class="container">
<h2 class="text-center text-light my-3 gold"><i class="fab fa-phoenix-framework gold"></i> Slot Game</h2>
<div class="row justify-content-center mb-3">
<div class="col col-auto">
<canvas id="slot" width="440" height="240"></canvas>
</div>
</div>
<div class="row justify-content-center mb-3">
<div class="col col-auto">
<div class="input-group mb-3 w-75 m-auto">
<div class="input-group-prepend">
<span class="input-group-text">Current WIN</span>
</div>
<input type="text" class="form-control w-auto" id="cwin" value="0" />
</div>
</div>
</div>
<div class="row justify-content-center mb-3">
<div class="col col-auto">
<button class="btn btn-danger px-5" id="spin"><i class="fas fa-sync-alt"></i> SPIN</button>
<button class="btn btn-secondary px-5" id="auto"><i class="fab fa-android"></i> AUTO (OFF)</button>
</div>
</div>
<div class="row justify-content-center mb-3">
<div class="col col-auto">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Credits</span>
</div>
<input class="form-control" type="number" id="balance" min="1" max="5000" />
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-dollar-sign green"></i></span>
</div>
</div>
</div>
<div class="col col-auto">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">BETx</span>
</div>
<input class="form-control" type="number" id="bet" min="1" value="1" max="3" />
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-coins gold"></i></span>
</div>
</div>
</div>
</div>
<div class="row justify-content-center">
<div class="col col-auto">
<select id="mode" class="btn btn-default">
<option value="random">Random</option>
<option value="fixed">Fixed</option>
</select>
<select id="where" class="btn btn-default">
<option value="top">top</option>
<option value="middle">middle</option>
<option value="bottom">bottom</option>
</select>
<select id="what" class="btn btn-default"></select>
</div>
</div>
<div class="row justify-content-center my-3">
<div class="col col-auto">
<button class="btn btn-warning w-auto" type="button" id="checkout">
<i class="fas fa-money-bill-alt"></i> CHECKOUT
</button>
<button class="btn btn-primary w-auto" type="button" data-toggle="modal" data-target="#payTable">
<i class="fas fa-money-bill-alt"></i> Pay Table
</button>
</div>
</div>
</div>
<!-- Paytable modal -->
<div
class="modal fade"
id="payTable"
tabindex="-1"
role="dialog"
aria-labelledby="payTableTitle"
aria-hidden="true"
>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="payTableTitle">Pay Table</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<table class="table table-dark table-hover table-responsive">
<thead>
<tr>
<td>Reel1</td>
<td>Reel2</td>
<td>Reel3</td>
<td>TOP</td>
<td>MIDDLE</td>
<td>BOTTOM</td>
</tr>
</thead>
<tbody>
<tr>
<td><img src="./img/Cherry.png" width="40" /></td>
<td><img src="./img/Cherry.png" width="40" /></td>
<td><img src="./img/Cherry.png" width="40" /></td>
<td class="v-align">2000xBET</td>
<td class="v-align">1000xBET</td>
<td class="v-align">4000xBET</td>
</tr>
<tr>
<td><img src="./img/7.png" width="40" /></td>
<td><img src="./img/7.png" width="40" /></td>
<td><img src="./img/7.png" width="40" /></td>
<td class="v-align">150xBET</td>
<td class="v-align">150xBET</td>
<td class="v-align">150xBET</td>
</tr>
<tr>
<td>
<img src="./img/7.png" width="40" />
<img src="./img/Cherry.png" width="40" />
</td>
<td>
<img src="./img/7.png" width="40" />
<img src="./img/Cherry.png" width="40" />
</td>
<td>
<img src="./img/7.png" width="40" />
<img src="./img/Cherry.png" width="40" />
</td>
<td class="v-align">75xBET</td>
<td class="v-align">75xBET</td>
<td class="v-align">75xBET</td>
</tr>
<tr>
<td><img src="./img/3xBAR.png" width="40" /></td>
<td><img src="./img/3xBAR.png" width="40" /></td>
<td><img src="./img/3xBAR.png" width="40" /></td>
<td class="v-align">50xBET</td>
<td class="v-align">50xBET</td>
<td class="v-align">50xBET</td>
</tr>
<tr>
<td><img src="./img/2xBAR.png" width="40" /></td>
<td><img src="./img/2xBAR.png" width="40" /></td>
<td><img src="./img/2xBAR.png" width="40" /></td>
<td class="v-align">20xBET</td>
<td class="v-align">20xBET</td>
<td class="v-align">20xBET</td>
</tr>
<tr>
<td><img src="./img/BAR.png" width="40" /></td>
<td><img src="./img/BAR.png" width="40" /></td>
<td><img src="./img/BAR.png" width="40" /></td>
<td class="v-align">10xBET</td>
<td class="v-align">10xBET</td>
<td class="v-align">10xBET</td>
</tr>
<tr>
<td>
<img src="./img/BAR.png" width="40" />
<img src="./img/2xBAR.png" width="40" />
<img src="./img/3xBAR.png" width="40" />
</td>
<td>
<img src="./img/BAR.png" width="40" />
<img src="./img/2xBAR.png" width="40" />
<img src="./img/3xBAR.png" width="40" />
</td>
<td>
<img src="./img/BAR.png" width="40" />
<img src="./img/2xBAR.png" width="40" />
<img src="./img/3xBAR.png" width="40" />
</td>
<td class="v-align">5xBET</td>
<td class="v-align">5xBET</td>
<td class="v-align">5xBET</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script src="./js/reel.js"></script>
<script src="./js/slot.js"></script>
<script type="text/javascript">
const conf = {
fps: 60,
img: [],
width: 420 + 20,
height: 240,
canvas: find('#slot'),
spinBtn: find('#spin'),
autoBtn: find('#auto'),
mode: find('#mode'),
where: find('#where'),
what: find('#what'),
balance: find('#balance'),
bet: find('#bet'),
win: find('#cwin'),
checkout: find('#checkout'),
reel: {
width: 140,
height: 120,
xOffsets: [0, 140, 280].map((x) => x + 10),
animTimes: [20, 25, 30].map((x) => x * 100),
},
pSkip: 40,
imgMap: ['BAR', '2xBAR', '3xBAR', '7', 'Cherry'],
imgStartPts: [...range(-2, 2)],
player: {
money: 10,
},
imgDot: null,
autoModeDelay: 3000,
sound: {
win: new Audio('./sound/win.mp3'),
spin: new Audio('./sound/spin.mp3'),
},
};
//Resource loader
Resources('./img/BAR.png', './img/2xBAR.png', './img/3xBAR.png', './img/7.png', './img/Cherry.png').onLoad(
function (resources, names) {
//loading done and ready to go
//save loaded resources to conf.img
if (resources instanceof Array) {
conf.imgMap.forEach((i, j) => (conf.img[i] = resources[j]));
}
//add options to select
names.forEach(function (name) {
const key = name.replace(new RegExp('^(./img/)|(.png|.jpg|.jpeg)$', 'ig'), '');
const option = document.createElement('option');
option.value = key;
option.innerText = key;
conf.what.appendChild(option);
});
//sounds load
conf.sound.win.load();
conf.sound.spin.load();
//instantiation the game
(function (slot) {
let fps = conf.fps,
interval = 1000 / fps,
delta,
lastpUpdate = 0;
//bind click events
conf.spinBtn.onclick = slot.spin;
conf.checkout.onclick = slot.checkout;
conf.mode.onchange = slot.setMode;
conf.where.onchange = slot.setMode;
conf.what.onchange = slot.setMode;
conf.balance.onchange = slot.setCredits;
conf.balance.value = conf.player.money;
conf.autoBtn.onclick = slot.autoToggle;
//init game
slot.start();
//core function of the game
(function update(now) {
delta = now - lastpUpdate;
if (delta > interval) {
lastpUpdate = now - (delta % interval);
slot.loop(now);
}
window.requestAnimationFrame(update);
})();
})(new Slot(conf.canvas.getContext('2d')));
},
);
</script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" i></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</body>
</html>