-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilityFunctions.js
66 lines (62 loc) · 2.19 KB
/
utilityFunctions.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
//function to initialize balloon movement and timer
function balloonMoveTimer(){
// setting opacity before balloons move so that user knows can't pop balloons
setTimeout(function () {opacityStatus = true;}, (delayTimerStart+1250));
opacityInterval = setInterval(function(){
gameObject.opacitySetting();}, 10);
// start moving balloons when start of game Time starts
if (gameTime === (countDown*1000)+delayTimerStart){
//remove from DOM?
// iterate for each ballon created
for (var i=0; i< elballoonArray.length; i++){
balloonMove(elballoonArray[i]);
}
}
// taking out invisibleDiv after delayTimerStart (1s) so that user can start popping balloons
setTimeout(function(){elInvisible.classList.remove('invisibleOn');},delayTimerStart+1000);
// starting interval
var timerInterval = setInterval(function(){
// setting timer to active
timerActive = true;
// if game time finishes
if (gameTime <= 0){
gameTime -= 1000;
gameObject.startTimer();
// make ballons stop
gameObject.clearIntervalOfballoonArray();
// make timer stop
clearInterval(timerInterval);
// check if win or loose
if (elballoonArray.length === 0){
//if win
gameObject.removeElGameEventListener();
timerActive = false;
clearInterval(timerInterval);
gameObject.congratsMessage();
//reinitializing game
gameObject.reeinitializingGameParam();
} else{
//if loose
timerActive = false;
gameObject.removeElGameEventListener();
clearInterval(timerInterval);
gameObject.endGameMessage();
//reinitializing game
gameObject.gameRestart();
}
} else if (elballoonArray.length === 0){
//if all balloons are popped before timer ends
gameObject.removeElGameEventListener();
timerActive = false;
clearInterval(timerInterval);
elTimer.classList.toggle('timer-color-slider');
gameObject.congratsMessage();
//reinitializing game
gameObject.reeinitializingGameParam();
} else {
// seting timer after 1s
setTimeout(gameObject.startTimer, delayTimerStart);
gameTime -= 1000;
}
}, 1000);
}