File size: 8,220 Bytes
bed5506
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce16325
bed5506
 
 
 
 
 
 
 
 
 
 
ce16325
bed5506
 
 
 
 
 
 
 
 
 
 
ce16325
bed5506
 
 
 
 
 
 
 
 
 
 
ce16325
bed5506
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
var money = 1000;
var waste = 0;
var selected = 0;
var rateMoney = 0;
var rateWaste = 0;
var year = 2014;
var blocks = [{"bType":"", "bVersion":""},
	{"bType":"", "bVersion":""},
	{"bType":"", "bVersion":""},
	{"bType":"", "bVersion":""},
	{"bType":"", "bVersion":""},
	{"bType":"", "bVersion":""}];
var firstBlock = false;
var smudFacts = ["SMUD's headquarters building, built in the late 1950s on the edge of the East Sacramento neighborhood, is notable for its mural by Wayne Thiebaud.",
	"SMUD is one of the ten largest publicly owned utilities in the United States, generating the bulk of its power through natural gas.",
	"SMUD houses large hydroelectric generation plants that account for 22% of its power.",
	"SMUD's green power (renewable) energy output was estimated as 19% in 2009."];

$(document).ready(function(){
	refreshMoney();
	$('.titlescreen').fadeIn();
	$('.year-number').text(year);
	$('.block').click(function(){
		if (blocks[$(this).data('block')].bType == "") {
			$('.buy-menu').fadeIn();
		} else {
			upgradeImgRefresh();
			$('.upgrade-menu').slideDown();
		}
		selected = $(this).data('block');
	});
	$('.escape-container').click(function(){
		$('.popup').fadeOut();
	});
	$('.btn-next').click(function()
		{
			$('.year-report').fadeOut();
		});
	$('.btn-start').click(function(){
		$('.popup').fadeOut();
	});
	$('.btn-buy').click(function(){
		addBuilding(selected, $(this).data('buy'), 1);
		refreshMoney();
		$('.popup').fadeOut();
	});
	$('.btn-upgrade').click(function(){
		upgrade(selected, blocks[selected].bType, $(this).data('upgrade'));
		refreshMoney();
		refreshVersion(selected);
		$('.popup').fadeOut();
	});
	$('.btn-remove').click(function () {
		var remove = blocks[selected];
		remove.bType = "";
		remove.bVersion = "";
		refresh(selected);
		$('.block[data-block=' + selected + '] .version-text').fadeOut();
		$('.popup').fadeOut();
	});
	$('.btn-next-year').click(function(){
		if (firstBlock) {
			nextYear();
		} else {
			alert("You need to purchase your first energy source.");
		}
	});
	$('.remove-waste-25-btn').click(function(){
		if(money >= 200)
		{
			money = money - 200;
			if(waste - 25 <= 0)
			{
				waste = 0;
			}
			else{
				waste = waste - 25;
			}
			refreshMoney();
			refreshWaste();
		}
		else{
			alert('You do not have enough money');
		}
		refreshMoney();
		refreshWaste();
	});
	$('.remove-waste-50-btn').click(function(){
		if(money >= 400)
		{
			money = money - 400;
			if(waste - 50 <= 0)
			{
				waste = 0;
			}
			else{
				waste = waste - 50;
			}
			refreshMoney();
			refreshWaste();
		}
		else{
			alert('You do not have enough money');
		}
		refreshMoney();
		refreshWaste();
	});
});

function addBuilding (blockId, buildingType, buildingVersion){
	switch(buildingType){
		case 'oil':
			if (firstBlock == false) {
				firstBlock = true;
			}
			if (money >= 100) {
				blocks[blockId].bType = "oil";
				blocks[blockId].bVersion = buildingVersion;
				money = money - 100;
				rateMoney = rateMoney + 100;
				rateWaste = rateWaste + 5;
				refresh(selected);
			} else {
				alert("Need mas money!");
			}
			break;
		case 'solar':
			if (money >= 500) {
				blocks[blockId].bType = "solar";
				blocks[blockId].bVersion = buildingVersion;
				money = money - 500;
				rateMoney = rateMoney + 250;
				rateWaste = rateWaste + 1;
				refresh(selected);
			} else {
				alert("Need mas money!");
			}
			break;
		case 'nuclear':
			if (money >= 2500) {
				blocks[blockId].bType = "nuclear";
				blocks[blockId].bVersion = buildingVersion;
				money = money - 2500;
				rateMoney = rateMoney + 1500;
				rateWaste = rateWaste + 5;
				refresh(selected);
			} else {
				alert("Need mas money!");
			}
			break;
		case 'wind':
			if (money >= 1500) {
				blocks[blockId].bType = "wind";
				blocks[blockId].bVersion = buildingVersion;
				money = money - 1500;
				rateMoney = rateMoney + 500;
				rateWaste = rateWaste + 1;
				refresh(selected);
			} else {
				alert("Need mas money!");
			}
			break;
		default:
			blocks[blockId].bType = null;
			blocks[blockId].bVersion = null;
			break;
	}
}

function upgrade(blockId, buildingType, buildingVersion) {
	switch(buildingVersion){
		case 1:
			if (blocks[blockId].bVersion == 1) {
				alert('This is already your version.');
			} else {

			}
			break;
		case 2:
			if (blocks[blockId].bVersion == 2) {
				alert('This is already your version.');
			} else {
				if (money >= 1000){
					blocks[blockId].bVersion = buildingVersion;
					money = money - 1000;
					rateMoney = rateMoney + 100 * 1.5;
					rateWaste = rateWaste + 5;
				} else {
					alert("Need mas money!");
				}
			}
			break;
		case 3:
			if (blocks[blockId].bVersion == 3000) {
				alert('This is already your version.');
			} else {
				if (money >= 3000){
					blocks[blockId].bVersion = buildingVersion;
					money = money - 3000;
					rateMoney = rateMoney + 100 * 2;
					rateWaste = rateWaste + 5;
				} else {
					alert("Need mas money!");
				}
			}
			break;
		case '':

			break;
		default:
			break;
	}
}

function upgradeImgRefresh() {
	var type = blocks[selected].bType;
	var imgUrl;
	switch(type){
		case 'oil':
			imgUrl = "img/oil.png";
			break;
		case 'solar':
			imgUrl = "img/solar.png";
			break;
		case 'nuclear':
			imgUrl = "img/nuclear.png";
			break;
		case 'wind':
			imgUrl = "img/wind.png";
			break;
		case '':
			imgUrl = null;
			break;
		default:
			imgUrl = null;
			break;
	}
	$('.upgrade-menu img').attr('src', imgUrl);
}

function refresh (blockId){
	var type = blocks[blockId].bType;
	var version = blocks[blockId].bVersion;
	var imgUrl;
	switch(type){
		case 'oil':
			imgUrl = "img/oil.png";
			break;
		case 'solar':
			imgUrl = "img/solar.png";
			break;
		case 'nuclear':
			imgUrl = "img/nuclear.png";
			break;
		case 'wind':
			imgUrl = "img/wind.png";
			break;
		case '':
			imgUrl = null;
			break;
		default:
			imgUrl = null;
			break;
	}
	$('.block[data-block=' + blockId + '] img').attr('src', imgUrl);
	$('.block[data-block=' + blockId + '] .version-text').text('Version ' + version);
	$('.block[data-block=' + blockId + '] .version-text').data('version', version);
	$('.block[data-block=' + blockId + '] .version-text').fadeIn();
}

function refreshVersion(blockId){
	var type = blocks[blockId].bType;
	var version = blocks[blockId].bVersion;
	$('.block[data-block=' + blockId + '] .version-text').text('Version ' + version);
	$('.block[data-block=' + blockId + '] .version-text').data('version', version);
}

function refreshMoney (){
	$('.money-amount').text('$' + money);
}

function refreshWaste (){
	var wasteBar = $('.waste-bar');
	wasteBar.text(waste + '%');
	wasteBar.css('width', waste + '%');
}

function nextYear(){
	$('.year-report').fadeIn();
	$('.year-gain').text(rateMoney);
	$('.year-waste').text(rateWaste + '%');
	money = money + rateMoney;
	waste = waste + rateWaste;
	$('.fact-text').text(smudFacts[Math.floor(Math.random()*smudFacts.length)]);
	$('.remove-waste-25').text('$200');
	$('.remove-waste-50').text('$400');
	if (waste >= "100"){
		gameOver();
		var wasteBar = $('.waste-bar');
		wasteBar.text('100%');
		wasteBar.css('width', '100%');
	} else {
		refreshMoney();
		refreshWaste();
		year++;
		$('.year-number').text(year);
	}	
}

function wipeGrid(){
	for (var i = blocks.length - 1; i >= 0; i--) {
		refresh(i);
	};
}

function gameOver(){
	$('.yearnum').text(year - 2014);
	$('.btn-next-year').fadeOut('fast');
	$('.gameover').fadeIn();
	$('.btn-again').click(function(){
		money = 1000;
		refreshMoney();
		waste = 0;
		refreshWaste();
		selected = 0;
		rateMoney = 0;
		rateWaste = 0;
		year = 2014;
		$('.year-number').text(year);
		blocks = [{"bType":"", "bVersion":""},
		{"bType":"", "bVersion":""},
		{"bType":"", "bVersion":""},
		{"bType":"", "bVersion":""},
		{"bType":"", "bVersion":""},
		{"bType":"", "bVersion":""}];
		wipeGrid();
		$('.gameover').fadeOut();
		$('.version-text').fadeOut();
		$('.btn-next-year').fadeIn();
		year = 0;
		firstBlock = false;
	});
	$('.btn-menu').click(function(){
			
	});

}

//Add next year if buildings exist done
//add title screen done
//fix image sizes done
//change year to year done

//add versions
//show benefits
//upgrade all same + percentage differences