-
Notifications
You must be signed in to change notification settings - Fork 0
/
impossiblestory.js
39 lines (39 loc) · 939 Bytes
/
impossiblestory.js
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
$(function() {
var shuffle = function(data) { // A Fisher-Yates shuffle
var copy = [];
var n = data.length;
var i = null;
while(n) {
i = Math.floor(Math.random() * data.length); // Pick an element
if (i in data) {
copy.push(data[i]);
delete data[i];
n--;
}
}
return copy;
};
var doShuffle = function() {
$("#movableContainer").addClass("hide");
var movables = [];
$(".moveable").each(function() {
movables.push($(this).detach());
});
newWorldOrder = shuffle(movables);
for (var x = 0; x < newWorldOrder.length; x++) {
$("#movableContainer").append(newWorldOrder);
}
$("#movableContainer").removeClass("hide");
};
var movableCount = $(".moveable").length;
var order = [];
for (var x = 0; x < movableCount; x++) {
order.push(x);
}
var count = 0;
$(".moveable").each(function() {
$(this).data("id", count++);
});
$("#btnShuffle").on("click", doShuffle);
doShuffle();
});