-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.js
68 lines (54 loc) · 1.45 KB
/
jquery.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
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
/*
* JQuery script to handle for Tower of Hanoi movements
*/
function calc_move(movement) {
var snapshot = movement[0];
var source_name = movement[1];
var dest_name = movement[2];
switch(source_name) {
case 'peg_0':
var id_no = snapshot[0].state.pop()
break;
case 'peg_1':
var id_no = snapshot[1].state.pop()
break;
case 'peg_2':
var id_no = snapshot[2].state.pop()
break;
};
var id = "#" + id_no;
var start = $( '#' + source_name ).position().left;
var stop = $( '#' + dest_name ).position().left;
var travel = (stop - start);
if (travel < 0) {
travel = "-=" + Math.abs(travel);
} else {
travel = "+=" + travel;
};
var floor = $( '#base_0' ).position().top - 30;
switch(dest_name) {
case 'peg_0':
var drop = snapshot[0].state.length
break;
case 'peg_1':
var drop = snapshot[1].state.length
break;
case 'peg_2':
var drop = snapshot[2].state.length
break;
};
drop = floor - drop*30
return [id, travel, drop];
};
$(document).click(function() {
[id, travel, drop] = calc_move( moves_list.shift() )
$( id ).animate({
'top': 20
}, 500);
$( id ).animate({
'left': travel
}, 500);
$( id ).animate({
'top': drop
}, 500);
});