-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwheel_logic.js
67 lines (65 loc) · 1.47 KB
/
wheel_logic.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
var shared_angle=40;
var rotations=0;
var is_rotating=false;
var lucks=0;
function rotate_wheel()
{
if(rotations==360)
{
rotations=0;
}
var wheel=document.getElementById("wheel");
wheel.style.transform="rotate("+rotations+"deg)";
rotations=rotations+10;
is_rotating=true;
console.log(rotations);
}
function rotations_AI()
{
//If the rotation is between -20 to +20 of the multiplier(i.e.the sweet spot)
var sweet_spots=[0,80,160,240,280];
var wheel=document.getElementById("wheel");
for (var i = 0; i <sweet_spots.length; i++) {
//increase the lucks
lucks=lucks+1;
if(rotations>sweet_spots[i]-20 && rotations<sweet_spots[i]+20)
{
if(lucks>=10)
{
lucks=0;
//Resetting the bad lucks to zero such that there are less chances of getting gems or jackpot
wheel.style.transform="rotate("+sweet_spots[i]+"deg)";
alert("Very lucky guy");
}
else
{
sweet_spots[i]=sweet_spots[i]+shared_angle;
wheel.style.transform="rotate("+sweet_spots[i]+"deg)";
alert("Oops.");
}
}
}
}
function start_rotation()
{
if(!is_rotating)
{
var timer=setInterval(rotate_wheel,25);
window.timer=timer;
}
}
function set_rotation()
{
console.log('dffdg');
var wheel=document.getElementById("wheel");
var input_rot=document.getElementById("rotation").value;
wheel.style.transform="rotate("+input_rot+"deg)";
rotations=input_rot;
rotations_AI();
}
function stop_rotation()
{
rotations_AI();
clearInterval(timer);
is_rotating=false;
}