-
Notifications
You must be signed in to change notification settings - Fork 3
/
game.js
187 lines (165 loc) · 4.79 KB
/
game.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
class Game {
constructor() {
this.TOTALMILES = 1893;
this.characterManager = new CharacterManager()
this.car = new Car()
this.restaurants = new RestaurantManager()
this.people = []
this.cool = 0
this.wealth = 0
this.currentCityIndex = 0;
this.currentCity = cities[this.currentCityIndex];
this.eventsManager = new EventsManager()
this.restaurantManager = new RestaurantManager()
this.atCity = true;
}
setUpPeople(people){
this.people = people;
for (var person in this.people) {
this.cool += this.people[person].cool
this.wealth += this.people[person].wealth
var peep = this.people[person];
$("<div />")
.append(`
<span class='passengerName'>${peep.name}</span>
<div class="hungerContainer"><div class="hungerBar"></div></div>
`)
.addClass('passenger')
.attr('id', `passenger${peep.id}`)
.appendTo('#passengers')
}
}
changeCool(num) {
this.cool += num;
}
changeMoney(num) {
this.wealth += num;
}
currentCity() {
return this.currentCity;
}
currentCityIndex() {
return this.currentCityIndex;
}
getCar() {
return this.car;
}
distanceFromLastCity() {
return cities[this.currentCityIndex - 1].distanceRemaining - this.currentCity.distanceRemaining;
}
updateStatesEvent(event) {
if (event != undefined) {
if (event.description.includes('Nickelback')) {
console.log("NICKELBACK");
var stopItPlease = function() {
nickelback.pause();
nickelback.currentTime = 0;
}
setTimeout(stopItPlease, 12000);
var nickelback = new Audio('audio/nickelback.mp3');
nickelback.play();
}
this.changeCool(event.cool);
this.changeMoney(event.cost);
notification(event.description, event.cool, event.cost);
}
}
goWest() {
if (this.currentCityIndex < cities.length) {
this.currentCityIndex++;
this.currentCity = cities[this.currentCityIndex];
this.car.mileage += this.distanceFromLastCity();
}
// var event = this.eventsManager.getRandomEvent();
// this.updateStatesEvent(event);
return event;
}
getGasStats() {
var costPerGallon = this.car.generateCostPerGallon();
var requiredFuel = this.car.MAX_TANK_CAPACITY - this.car.currentTank;
var totalCost = requiredFuel * costPerGallon;
console.log('requiredFuel ' + requiredFuel);
console.log('total cost ' + totalCost);
return {
costPerGallon: costPerGallon,
amountToFill: requiredFuel,
totalCost: totalCost
}
}
refuelCar(totalCost) {
// let requiredFuel = this.car.requiredFuel();
// let randomNumber = Math.random();
// let costPerGallon = 2 + randomNumber;
// let costOfGas = requiredFuel * costPerGallon;
if (totalCost <= this.wealth) {
this.wealth -= totalCost;
this.car.refuel();
} else {
notification("Not enough money for gas!");
}
}
starvePeople() {
let people = this.people
for (var i = 0; i < people.length; i++) {
let person = people[i]
person.becomeHungerier()
}
}
feedPeople(restaurant) {
var canEat = true;
for (var person in this.people) {
// <<<<<<< HEAD
// this.people[person].feed()
// }
// this.wealth += restaurant.price
//
// =======
var that = this;
this.people[person].allergies.forEach(function(allergy){
if (allergy === "Gluten" && restaurant.type === 'Gluten'){
notification(that.people[person].name + " is allergic to Gluten, you can't eat here")
canEat = false;
}
if ((allergy === 'Vegan' || allergy === ' Vegan') && restaurant.type === 'Vegan'){
notification(that.people[person].name + " is a Vegan, you can't eat here")
canEat = false;
}
})
}
if (canEat){
console.log('here')
for (var person in this.people) {
this.people[person].feed();
this.wealth += restaurant.price
// setMoney(game.wealth);
setCoolPoints(game.cool);
selectRestaurant(restaurant);
$('#restaurantOptionsContainer').empty();
$('#restaurantOptions').hide();
$('#actions').show();
}
}
}
selectRestaurant(restaurant) {
this.changeMoney(restaurant.price);
this.changeCool(restaurant.cool);
}
isGameOver() {
var everyoneDead = true;
for (var i = 0; i < 4; i++) {
if (this.people[i] && !this.people[i].isDead) {
everyoneDead = false;
}
}
// this.people[0].isDead && this.people[1].isDead && this.people[2].isDead && this.people[3].isDead;
console.log('everyoneDead' + everyoneDead);
var coolDead = this.cool <= -100;
var outOfGas = this.car.currentTank <= 0;
return {
everyoneDead: everyoneDead,
coolDead: coolDead,
outOfGas: outOfGas
}
// return everyoneDead || this.cool <= -100 || this.people.length <= 0 || this.car.currentTank <= 0;
}
}