-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-slotmachine.js
More file actions
116 lines (93 loc) · 2.89 KB
/
Copy pathnode-slotmachine.js
File metadata and controls
116 lines (93 loc) · 2.89 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
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
/**
* Main js
*/
var $ = require("jquery");
var http = require('http'),
fs = require('fs');
const express = require('express');
const app = express();
const port = 8000;
var path = require('path');
var slots = {
0: {
percent: 50,
html: '<img src="public/imgs/icons/0.png" />',
rate: 0
},
1: {
percent: 25,
html: '<img src="public/imgs/icons/1.png" />',
rate: 1
},
2: {
percent: 13,
html: '<img src="public/imgs/icons/2.png" />',
rate: 1.5
},
3: {
percent: 6,
html: '<img src="public/imgs/icons/3.png" />',
rate: 2
},
4: {
percent: 3,
html: '<img src="public/imgs/icons/4.png" />',
rate: 2.5
},
5: {
percent: 2,
html: '<img src="public/imgs/icons/5.png" />',
rate: 3
},
6: {
percent: 1,
html: '<img src="public/imgs/icons/6.png" />',
rate: 10
}
};
// app.use('/static', express.static(path.join(__dirname, 'public')))
app.use('/public', express.static(__dirname + '/public'));
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname + '/public/templates/index.html'));
});
app.get('/slots', function (req, res) {
var htmlArray = [[], [], []];
var h = 0;
for (slotObj in slots) {
var slot = slots[slotObj];
console.log(slot.percent);
for (i = 0; i < slot.percent; i++) {
htmlArray[0].push('<div class="slot" id="slot1-' + h + '" data-percent="' + slot.percent + '">' + slot.html + '<div>');
htmlArray[1].push('<div class="slot" id="slot2-' + h + '" data-percent="' + slot.percent + '">' + slot.html + '<div>');
htmlArray[2].push('<div class="slot" id="slot3-' + h + '" data-percent="' + slot.percent + '">' + slot.html + '<div>');
h++;
}
};
var arra = [shuffle(htmlArray[0]), shuffle(htmlArray[1]), shuffle(htmlArray[2])]
res.json({ slots: arra })
});
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
// fs.readFile('./templates/index.html', function (err, html) {
// if (err) {
// throw err;
// }
// http.createServer(function(request, response) {
// response.writeHeader(200, {"Content-Type": "text/html"});
// response.write(html);
// response.end();
// }).listen(8000);
// });