forked from abhijitWakchaure/akatsuki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleftScorecard.js
65 lines (60 loc) · 2.05 KB
/
leftScorecard.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
class LeftScorecard {
constructor() {
this.prevLength = passengersInCar.length;
}
update() {
for (var i = 0; i < passengersInCar.length; i++) {
passengersInCar[i].patience -= 1;
if (passengersInCar[i].patience <= 0 || globalTimer <= 0) {
console.log("Game Over");
gameOver.play();
noLoop();
$("#notice").html("Game Over!");
$("#notice").show();
leftScorecard.animateNotice();
}
}
if (passengersInCar.length > 0) {
var nextDestination = passengersInCar[0].destination;
if (typeof nextDestination !== "undefined" && nextDestination != null)
$(".bg").css(
"background-image",
"url(images/places/" + nextDestination + ".jpg)"
);
else $(".bg").css("background-image", "url(images/places/Blank.jpg)");
} else {
$(".bg").css("background-image", "url(images/places/Blank.jpg)");
}
}
animateFrindsInCar() {
$("#friendsInCar").addClass("animate__flash");
}
animateNotice() {
$("#notice").addClass("animate__slideInDown");
}
show() {
var html = `
<div class="row animate__animated my-1" id="friendsInCar">
<div class="col-6">Friends in Car:</div>
<div class="col-6 text-right">${passengersInCar.length} / 2</div>
</div>`;
if (passengersInCar.length > 0) {
html += `<div class="my-1">Next Destinations:</div>`;
}
for (var i = 0; i < passengersInCar.length; i++) {
html += `
<div class="row my-1">
<div class="col-4 mr-1">${passengersInCar[i].destination}</div>
<div class="col-6 per-parent">
<div class="per-wrapper" style="width: ${passengersInCar[i].patience}%"> </div>
</div>
<div class="col-1">${passengersInCar[i].patience}</div>
</div>`;
}
$("#leftDiv").html(html);
if (leftScorecard.prevLength != passengersInCar.length) {
leftScorecard.prevLength = passengersInCar.length;
leftScorecard.animateFrindsInCar();
}
}
}