-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.js
More file actions
78 lines (71 loc) · 1.88 KB
/
Copy pathjquery.js
File metadata and controls
78 lines (71 loc) · 1.88 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
var playing = false;
var score;
var trialsleft;
var step;
var action;
var fruits=['apple','banana','pineapple','orange','grapes','watermelon','carrot','cherry','guava'];
$(function(){
$("#startreset").click(function(){
if (playing==true) {
location.reload();
}
else{
playing=true;
score=0;
$("#scorevalue").html(score);
$("#trialsleft").show();
trialsleft=3;
addHearts();
$("#gameOver").hide();
$("#startreset").html("Reset Game");
startAction();
}
});
$("#fruit1").mouseover(function(){
score++;
$("#scorevalue").html(score);
document.getElementById("slicesound").play();
clearInterval(action);
$("#fruit1").hide("explode", 500);
setTimeout(startAction,500);
});
function addHearts(){
$("#trialsleft").empty();
for (var i = 0; i < trialsleft; i++) {
$("#trialsleft").append('<img src="images/heart.png" class="life">');
}
}
function startAction(){
$("#fruit1").show();
chooseFruit();
$("#fruit1").css({'left' : Math.round(550*Math.random()), 'top' :-50});
step=1+Math.round(5*Math.random());
action = setInterval(function(){
$("#fruit1").css('top', $("#fruit1").position().top + step);
if($("#fruit1").position().top > $("#fruitsContainer").height()){
if(trialsleft>1){
$("#fruit1").show();
chooseFruit();
$("#fruit1").css({'left' : Math.round(550*Math.random()), 'top' :-50});
step=1+Math.round(5*Math.random());
trialsleft--;
addHearts()
}else{
playing=false;
$("#startreset").html("Start Game");
$("#gameOver").show();
$("#gameOver").html('<p>Game Over</p><p>Your Score is: '+ score +'</p>');
$("#trialsleft").hide();
stopAction();
}
}
}, 10);
}
function chooseFruit(){
$("#fruit1").attr('src' , 'images/' + fruits[Math.round(8*Math.random())] + '.png');
}
function stopAction(){
clearInterval(action);
$("#fruit1").hide();
}
});