-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
620 lines (591 loc) · 23.4 KB
/
main.js
File metadata and controls
620 lines (591 loc) · 23.4 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
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
//Initialisation of variables
var stats = {
version: 1,
time: 0,
numAchievements: 0,
totalClicks: 0,
totalUnits: 0,
totalAtoms: 0
};
var currentEvents = {
currentEventOne: " ",
currentEventTwo: " ",
currentEventThree: " ",
currentEventFour: " "
};
var units = {
//Could combine unlocks with units. Would need to keep the unlock class for the unit type divs though.
//(plural, type, amount, atoms, cost, production)
//Atoms
hydrogen: new unit("", "atoms", 0, 1, [], []),
carbon: new unit("", "atoms", 0, 1, [], []),
nitrogen: new unit("", "atoms", 0, 1, [], []),
oxygen: new unit("", "atoms", 0, 1, [], []),
sodium: new unit("", "atoms", 0, 1, [], []),
silicon: new unit("", "atoms", 0, 1, [], []),
chlorine: new unit("", "atoms", 0, 1, [], []),
sulfur: new unit("", "atoms", 0, 1, [], []),
iron: new unit("", "atoms", 0, 1, [], []),
copper: new unit("", "atoms", 0, 1, [], []),
gold: new unit("", "atoms", 0, 1, [], []),
//Molecules
water: new unit("", "molecules", 0, 0, ["hydrogen", 2, "oxygen", 1], ["hydrogen", 0.2, "oxygen", 0.1]),
carbonDioxide: new unit("", "molecules", 0, 0, ["carbon", 1, "oxygen", 2], ["carbon", 0.1, "oxygen", 0.2]),
sodiumChloride: new unit("", "molecules", 0, 0, ["sodium", 1, "chlorine", 1], ["sodium", 0.1, "chlorine", 0.1]),
silica: new unit("", "molecules", 0, 0, ["silicon", 1, "oxygen", 2], ["silicon", 0.1, "oxygen", 0.1]),
glucose: new unit("", "molecules", 0, 0, ["carbon", 6, "hydrogen", 12, "oxygen", 6], ["carbonDioxide", 0.1, "water", 0.1]),
//Macromolecule
nucleotide: new unit("nucleotides", "macromolecule", 0, 0, ["carbon", 5, "hydrogen", 5, "nitrogen", 2, "oxygen", 2], ["nitrogen", 1]),
lipid: new unit("lipids", "macromolecule", 0, 0, ["carbon", 45, "hydrogen", 98, "oxygen", 6], ["aminoAcid", 0.1]),
aminoAcid: new unit("amino acids", "macromolecule", 0, 0, ["carbon", 5, "hydrogen", 11, "nitrogen", 1, "oxygen", 2, "sulfur", 1], ["lipid", 0.1, "nucleotide", 0.1]),
DNA: new unit("", "macromolecule", 0, 0, ["nucleotide", 3000000000], []),
starch: new unit("", "macromolecule", 0, 0, ["glucose", 60, "water", -60], ["glucose", 1, "nucleotide", 1]),
//Substance
dust: new unit("", "substance", 0, 0, ["silica", 10, "rock", .01, "iron", .1], ["silica", 1]),
sand: new unit("", "substance", 0, 0, ["silica", 100], ["silica", 1]),
rock: new unit("rocks", "substance", 0, 0, ["silica", 100, "iron", 200], ["sand", 0.1]),
dirt: new unit("", "substance", 0, 0, ["silica", 10, "rock", .1], ["nitrogen", 1]),
ironOre: new unit("", "substance", 0, 0, ["rock", 1, "iron", 1], ["iron", 0.5]),
copperOre: new unit("", "substance", 0, 0, ["rock", 1, "copper", 1], ["copper", 0.5]),
//Planetary
river: new unit("rivers", "planetary", 0, 0, ["silica", 1, "iron", 2], []),
//Space
spaceDust: new unit("", "space", 0, 0, ["hydrogen", 1000000], []),
meteoroid: new unit("meteoroids", "space", 0, 0, ["hydrogen", 1000000], []),
asteroid: new unit("asteroids", "space", 0, 0, ["hydrogen", 1000000], []),
asteroidBelt: new unit("asteroid belts", "space", 0, 0, ["asteroid", 1000, "water", 1000000], []),
planet: new unit("planets", "space", 0, 0, ["hydrogen", 2, "oxygen", 1], []),
nebula: new unit("nebulae", "space", 0, 0, ["hydrogen", 2, "oxygen", 1], []),
star: new unit("stars", "space", 0, 0, ["hydrogen", 2, "oxygen", 1], []),
solarSystem: new unit("solar systems", "space", 0, 0, ["star", 1, "planet", 8, "asteroidBelt", 1], []),
blackhole: new unit("blackholes", "space", 0, 0, ["star", 1], []),
galaxy: new unit("galaxies", "space", 0, 0, ["supermassiveBlackhole", 2, "solarSystem", 1000000000], []),
galaxySuperCluster: new unit("galaxy super clusters", "space", 0, 0, ["galaxy", 100], []),
supermassiveBlackhole: new unit("supermassive blackholes", "space", 0, 0, ["blackhole", 1000], []),
//life
cell: new unit("cells", "life", 0, 0, ["DNA", 1, "lipid", 10000, "aminoAcid", 1000000, "water", 10000000], []),
amoeba: new unit("amoebas", "life", 0, 0,["cell", 1], []),
chlorella: new unit("chlorellas", "life", 0, 0,["cell", 1], []),
human: new unit("humans", "life", 0, 0, ["hydrogen", 2, "oxygen", 1], []),
};
var achievements = {
//(condition, state, name, para)
time1: new achievement(["stats", "time", 900], false, "Noob", "You've played for 15 minutes. Well done?"),
time2: new achievement(["stats", "time", 3600], false, "Rookie", "I see you're getting the hang of it."),
time3: new achievement(["stats", "time", 36000], false, "Amateur", "You should understand the basics by now."),
atoms1: new achievement(["stats", "totalAtoms", 100], false, "Tiny", "You can't even see anything."),
atoms2: new achievement(["stats", "totalAtoms", 1000], false, "Still Tiny", "Is there anything even there?"),
atoms3: new achievement(["stats", "totalAtoms", 10000], false, "Tiny Part 3", "You'll get there eventually"),
achievements1: new achievement(["stats", "numAchievements", 5], false, "Freebie", "Wow. You get an achievement for having other achievements"),
achievements2: new achievement(["stats", "numAchievements", 10], false, "You're Special", "It's the effort that counts."),
achievements3: new achievement(["stats", "numAchievements", 15], false, "Tryhard", "This is like getting a medal for being 6th place."),
recordBreaker: new achievement(["unit", "human", 1], false, "Record Breaker", "You created humanity in less than 7 days!")
};
var events = {
//(condition, state, message)
newGame1: new evt(["stats", "time", 0], false, "You're a god now. But what's a god without a universe?"),
newGame2: new evt(["stats", "time", 10], false, "You dont have a universe... but you do have a ball. Nice."),
newGame3: new evt(["stats", "time", 15], false, "New things pop into existence as you examine the ball."),
unit1: new evt(["stats", "totalUnits", 1], false, "There's something strange about this ball..."),
unit2: new evt(["stats", "totalUnits", 25], false, "I guess there's nothing else to do, might as well play with your ball a bit more."),
unit3: new evt(["stats", "totalUnits", 100], false, "It looks like you have a very small universe now... carry on making what matters: matter."),
createdWater: new evt(["unit", "water", 1], false, "This is a little bit more complex. Your universe didn't get any bigger though."),
createdGlucose: new evt(["unit", "glucose", 1], false, "Sweet! This one is pretty complex.")
};
var unlocks = {
//(condition, state)
//Type Divs
molecules: new unlock(["unit", "hydrogen", 10, "unit", "oxygen", 10], false),
macromolecule: new unlock(["unit", "glucose", 100], false),
substance: new unlock(["unit", "silica", 100], false),
planetary: new unlock(["unit", "planet", 1], false),
space: new unlock(["unit", "rock", 10], false),
life: new unlock(["unit", "DNA", 1], false),
faith: new unlock(["unit", "human", 1], false),
//Atoms
carbon: new unlock(["unit", "hydrogen", 10], false),
nitrogen: new unlock(["unit", "carbon", 10], false),
oxygen: new unlock(["unit", "nitrogen", 10], false),
sodium: new unlock(["unit", "oxygen", 10], false),
silicon: new unlock(["unit", "sodium", 10], false),
chlorine: new unlock(["unit", "silicon", 10], false),
sulfur: new unlock(["unit", "chlorine", 10], false),
iron: new unlock(["unit", "sulfur", 10], false),
copper: new unlock(["unit", "iron", 10], false),
gold: new unlock(["unit", "gold", 1], false),
//Molecules
water: new unlock(["unit", "hydrogen", 10], false),
carbonDioxide: new unlock(["unit", "carbon", 25], false),
sodiumChloride: new unlock(["unit", "silica", 20], false),
silica: new unlock(["unit", "silicon", 10], false),
glucose: new unlock(["unit", "carbon", 100], false),
//Macromolecules
nucleotide: new unlock(["unit", "carbon", 10000], false),
lipid: new unlock(["unit", "carbon", 10000], false),
aminoAcid: new unlock(["unit", "carbon", 10000], false),
DNA: new unlock(["unit", "nucleotide", 10000], false),
starch: new unlock(["unit", "glucose", 100], false),
//Substance
dust: new unlock(["unit", "sand", 10], false),
sand: new unlock(["unit", "silica", 100], false),
rock: new unlock(["unit", "silica", 100], false),
dirt: new unlock(["unit", "silica", 100], false),
ironOre: new unlock(["unit", "rock", 10], false),
copperOre: new unlock(["unit", "rock", 10], false),
//Planetary
river: new unlock(["unit", "DNA", 1], false),
//Space
spaceDust: new unlock(["unit", "DNA", 1], false),
meteoroid: new unlock(["unit", "DNA", 1], false),
asteroid: new unlock(["unit", "silica", 100000], false),
asteroidBelt: new unlock(["unit", "asteroid", 100], false),
planet: new unlock(["unit", "silica", 10000000000], false),
star: new unlock(["unit", "nebula", 10], false),
solarSystem: new unlock(["unit", "star", 1], false),
blackhole: new unlock(["unit", "star", 10], false),
supermassiveBlackhole: new unlock(["unit", "blackhole", 1000], false),
galaxy: new unlock(["unit", "blackhole", 10], false),
galaxySuperCluster: new unlock(["unit", "galaxy", 10], false),
//Life
cell: new unlock(["unit", "DNA", 1], false),
amoeba: new unlock(["unit", "DNA", 1], false),
chlorella: new unlock(["unit", "DNA", 1], false),
human: new unlock(["unit", "DNA", 1], false),
};
var idleEffects = {
//Have negative effects first
river: new idle(["rock", -.1, "sand", .1, "iron", 20]),
chlorella: new idle(["carbonDioxide", -6, "water", -6, "glucose", 1, "oxygen", 12]),
amoeba: new idle(["glucose", -1, "oxygen", -12, "carbonDioxide", 6, "water", 6])
};
//Class Constructors
function unit(plural, type, amount, atoms, cost, production){
this.plural = plural;
this.type = type;
this.amount = amount;
this.atoms = atoms;
this.cost = cost;
this.production = production;
}
//achievement and unlock class are the same. Event is very similar.
function achievement(condition, state, name, para) {
this.condition = condition;
this.state = state;
this.name = name;
this.para = para;
}
function evt(condition, state, message) {
this.condition = condition;
this.state = state;
this.message = message;
}
function unlock(condition, state) {
this.condition = condition;
this.state = state;
}
function idle(effect) {
this.effect = effect;
}
//Gameplay Functions
function calcUnitAtoms(unit){
//determines how many atoms there are in a specific unit.
var numAtoms = 0;
for(i = 0; i < units[unit].cost.length; i += 2){
if(units[units[unit].cost[i]].atoms !== 0){
numAtoms += units[units[unit].cost[i]].atoms * units[unit].cost[i + 1];
}
else{
calcUnitAtoms(units[unit].cost[i]);
}
}
units[unit].atoms = numAtoms;
}
function checkAchievements(){
for(achievement in achievements) {
if(achievements[achievement].state !== true){
var tempBool = false;
for(i = 0; i < achievements[achievement].condition.length; i += 3){
if(achievements[achievement].condition[i] == "unit") {
if(units[achievements[achievement].condition[i + 1]].amount >= achievements[achievement].condition[i + 2]){
tempBool = true;
}
else tempBool = false;
}
if(achievements[achievement].condition[i] == "stats") {
if(stats[achievements[achievement].condition[i + 1]] >= achievements[achievement].condition[i + 2]){
tempBool = true;
}
else tempBool = false;
}
}
if(tempBool === true) {
achievements[achievement].state = true;
stats.numAchievements += 1;
document.getElementById("completedAchievements").innerHTML = stats.numAchievements;
}
}
}
}
function checkEvents(){
for(evt in events) {
if(events[evt].state !== true){
var tempBool = false;
for(i = 0; i < events[evt].condition.length; i += 3){
if(events[evt].condition[i] == "unit") {
if(units[events[evt].condition[i + 1]].amount >= events[evt].condition[i + 2]){
tempBool = true;
}
else tempBool = false;
}
if(events[evt].condition[i] == "stats") {
if(stats[events[evt].condition[i + 1]] >= events[evt].condition[i + 2]){
tempBool = true;
}
else tempBool = false;
}
}
if(tempBool === true) {
events[evt].state = true;
newEvent(events[evt].message);
}
}
}
}
function checkUnlocks() {
for(unlock in unlocks) {
if(unlocks[unlock].state !== true){
var tempBool = false;
for(i = 0; i < unlocks[unlock].condition.length; i += 3){
if(unlocks[unlock].condition[i] == "unit") {
if(units[unlocks[unlock].condition[i + 1]].amount >= unlocks[unlock].condition[i + 2]){
tempBool = true;
}
else{
tempBool = false;
break;
}
}
if(unlocks[unlock].condition[i] == "stats") {
if(stats[unlocks[unlock].condition[i + 1]] >= unlocks[unlock].condition[i + 2]){
tempBool = true;
}
else{
tempBool = false;
break;
}
}
}
if(tempBool === true) {
unlocks[unlock].state = true;
}
// Temporarily unlock everything to help with formatting
//unlocks[unlock].state = true;
}
}
}
function updateAllValues() {
stats.totalUnits = 0;
stats.totalAtoms = 0;
//updates the current number of every unit
for(unit in units) {
document.getElementById(unit + "Amount").innerHTML = units[unit].amount.toFixed(0);
stats.totalUnits += units[unit].amount;
stats.totalAtoms += units[unit].amount * units[unit].atoms;
}
//updates the amount of a unit you create per click as well as their effect
for(var unitA in units) {
var number = 1;
for(var unitB in units) {
if(units[unitB].production != null){
for(i = 0; i < units[unitB].production.length; i++){
if(units[unitB].production[i] == unitA){
number += units[unitB].production[i + 1] * units[unitB].amount;
}
}
}
}
//updates effect amounts
if(number > determineMax(unitA)) number = determineMax(unitA);
document.getElementById(unitA + "CreateAmount").innerHTML = number.toFixed(1).replace(".0", "");
if(typeof units[unitA].production == "object"){
for(i = 0; i < (units[unitA].production.length); i += 2){
document.getElementById(unitA + "Effect" + (i/2+1).toString()).innerHTML = (units[unitA].amount * units[unitA].production[i + 1]).toFixed(1).replace(".0", "");
}
}
}
//updates various stats
determineTimePlayed();
a = stats.totalAtoms / Math.pow(10, 80);
document.getElementById("totalAtoms").innerHTML = Math.floor(stats.totalAtoms);
document.getElementById("percentOfUniverse").innerHTML = a.toFixed(20);
document.getElementById("totalAchievements").innerHTML = Object.keys(achievements).length;
document.getElementById("completedAchievements").innerHTML = stats.numAchievements;
}
function newEvent(message) {
currentEvents.currentEventFour = currentEvents.currentEventThree;
currentEvents.currentEventThree = currentEvents.currentEventTwo;
currentEvents.currentEventTwo = currentEvents.currentEventOne;
currentEvents.currentEventOne = message;
loadEvents();
}
function create(type) {
//determines the max amount of a unit that can be created per click and buys it.
var prod = 1;
for(unit in units) {
if(units[unit].production.length > 0){
for(i = 0; i < units[unit].production.length; i += 2){
if(units[unit].production[i] == type){
prod += units[unit].production[i + 1] * units[unit].amount;
}
}
}
}
if(prod > determineMax(type)) prod = determineMax(type);
buyUnit(type, prod);
updateAllValues();
}
function buyUnit(type, number) {
//processes the buying of units
if(units[type].cost.length > 0 ){
var enough = false;
for(i = 0; i < units[type].cost.length; i += 2) {
if(units[units[type].cost[i]].amount >= number * units[type].cost[i + 1]) {
enough = true;
}
else {
enough = false;
break;
}
}
if(enough){
for(i = 0; i < units[type].cost.length; i += 2) {
units[units[type].cost[i]].amount -= number * units[type].cost[i + 1];
}
units[type].amount += number;
}
}
else units[type].amount += number;
}
function save() {
var save = {
units: units,
stats: stats,
achievements: achievements,
events: events,
unlocks: unlocks,
currentEvents: currentEvents
};
localStorage.setItem("save", JSON.stringify(save));
}
function load() {
if(localStorage.getItem("save") !== null){
var savegame = JSON.parse(localStorage.getItem("save"));
if(savegame.stats.version == stats.version) {
if (typeof savegame.units !== "undefined") units = savegame.units;
if (typeof savegame.stats !== "undefined") stats = savegame.stats;
if (typeof savegame.achievements !== "undefined") achievements = savegame.achievements;
if (typeof savegame.unlocks !== "undefined") unlocks = savegame.unlocks;
if (typeof savegame.events !== "undefined") events = savegame.events;
if (typeof savegame.currentEvents !== "undefined") currentEvents = savegame.currentEvents;
loadAchievements();
loadEvents();
loadUnlocks();
updateAllValues();
}
}
}
function loadAchievements() {
for (achievement in achievements) {
if (achievements[achievement].state === true) document.getElementById(achievement).style.display = "block";
}
if(stats.numAchievements >= 1){
document.getElementById("noAchievements").style.display = "none";
}
}
function loadEvents() {
document.getElementById("eventOne").innerHTML = currentEvents.currentEventOne;
document.getElementById("eventTwo").innerHTML = currentEvents.currentEventTwo;
document.getElementById("eventThree").innerHTML = currentEvents.currentEventThree;
document.getElementById("eventFour").innerHTML = currentEvents.currentEventFour;
}
function loadUnlocks() {
for (unlock in unlocks) {
if (unlocks[unlock].state === true) document.getElementById(unlock + "Section").style.display = "block";
else document.getElementById(unlock + "Section").style.display = "none";
}
}
Array.min = function( array ){
//returns the smallest value in an array of numbers
return Math.min.apply( Math, array );
};
function determineTimePlayed() {
var days, hours, minutes, seconds;
time = stats.time;
seconds = ((time % 86400) % 3600) % 60;
minutes = (((time - seconds) % 86400) % 3600) / 60;
hours = (((time - seconds) - minutes * 60) % 86400) / 3600;
days = (((time - seconds) - minutes * 60) - hours * 3600) / 86400;
document.getElementById("days").innerHTML = days;
document.getElementById("hours").innerHTML = hours;
document.getElementById("minutes").innerHTML = minutes;
document.getElementById("seconds").innerHTML = seconds;
}
function determineMax(unit) {
//returns the bottleneck for purchasing a new unit
var ratios = [];
var ratio = 0;
for(i = 0; i < units[unit].cost.length; i += 2) {
if(units[units[unit].cost[i]].amount / units[unit].cost[i+1] >= 0){
ratio = units[units[unit].cost[i]].amount / units[unit].cost[i+1];
ratios.push(ratio);
}
}
return Math.floor(Array.min(ratios));
}
function openTab(evt, name, type) {
var i, tabcontent, tablinks;
//closes all other tabs
tabcontent = document.getElementsByClassName("tabcontent " + type);
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
//sets the color of all tab links back to normal
tablinks = document.getElementsByClassName("tablinks" + type);
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
//Opens the tab and changes the color of the link
document.getElementById(name).style.display = "block";
evt.currentTarget.className += " active";
}
function newAchievement(ach) {
var achDiv = document.createElement("div");
achDiv.id = ach;
achDiv.style.display = "none";
achDiv.className = "achievement";
var achHead = document.createElement("h3");
achHead.innerHTML = achievements[ach].name;
achDiv.appendChild(achHead);
var achPar = document.createElement("p");
achPar.innerHTML = achievements[ach].para;
achDiv.appendChild(achPar);
document.getElementById("Achievements").appendChild(achDiv);
}
function newUnit(unit) {
var unitDiv = document.createElement("div");
unitDiv.id = unit + "Section";
unitDiv.style.display = "none";
var unitP = document.createElement("p");
unitP.className = "unit";
var btn = document.createElement("button");
btn.onclick= function(arg) {
return function() {
create(arg);
};
}(unit);
btn.innerHTML = "Create (<span id='" + unit + "CreateAmount'>0</span>)";
var unitTitle = createDisplayString(unit);
unitP.innerHTML = unitTitle + ": <span id='" + unit + "Amount'>0</span> ";
unitP.appendChild(btn);
unitP.appendChild(document.createElement("br"));
//Creates HTML textNodes for all units
var tempCost = "Cost: ";
if(units[unit].cost.length != 0){
for(i = 0; i < units[unit].cost.length; i += 2){
if(units[units[unit].cost[i]].plural.length != 0 && units[unit].cost[i+1] != 1){
tempCost += units[unit].cost[i+1] + " " + units[units[unit].cost[i]].plural + ", ";
}
else tempCost += units[unit].cost[i+1] + " " + units[unit].cost[i] + ", ";
}
tempCost = createDisplayString(tempCost);
}
else tempCost = "Cost: You can create this directly from the ball.";
var cost = document.createTextNode(tempCost);
//Creates HTML divs for all units
var effectDiv = document.createElement("div");
var tempEffect = "Create an additional ";
if(units[unit].production.length != 0){
for(i = 0; i < units[unit].production.length; i += 2) {
tempEffect += "<span id='" + unit + "Effect" + (i/2+1).toString() + "'>0</span>" + createDisplayString(" " + units[unit].production[i]);
if(i + 2 != units[unit].production.length) tempEffect += ", ";
}
tempEffect += " per click";
}
else tempEffect = "Effect: Used to build more complex things.";
//Appends all new divs to a unit div, and then appends that div to the units type section.
effectDiv.innerHTML = tempEffect;
unitP.appendChild(cost);
unitP.appendChild(effectDiv);
unitDiv.appendChild(unitP);
document.getElementById(units[unit].type).appendChild(unitDiv);
}
function createDisplayString(oldString) {
var newString = oldString.charAt(0).toUpperCase();
for(j = 1; j < oldString.length; j++){
if(oldString.charAt(j) == oldString.charAt(j).toUpperCase()
&& oldString.charAt(j) != ","
&& oldString.charAt(j) != ":"
&& oldString.charAt(j) != parseInt(oldString.charAt(j))
&& oldString.charAt(j-1) != oldString.charAt(j-1).toUpperCase()){
newString += " " + oldString.charAt(j);
}
else if(oldString.charAt(j-1) == " "){
newString += oldString.charAt(j).toUpperCase();
}
else if(oldString.charAt(j) == "," && j == oldString.length - 2);
else newString += oldString.charAt(j);
}
return newString;
}
/*function findSciExp(number){
var str = number.toString();
str = str.substring(str.indexOf("+") + 1);
number = parseInt(str);
}
function updateExponents(number) {
}
*/
//Testing Functions
function lockAllUnits(){
for(unlock in unlocks) {
unlocks[unlock].state = false;
}
}
function unlockAllUnits(){
for(unlock in unlocks) {
unlocks[unlock].state = true;
}
}
setInterval(function() {
stats.time++;
updateAllValues();
checkAchievements();
checkEvents();
checkUnlocks();
loadAchievements();
loadUnlocks();
for(idle in idleEffects){
for(i = 0; i < idleEffects[idle].effect.length; i += 2){
if(units[idleEffects[idle].effect[i]].amount + idleEffects[idle].effect[i+1] * units[idle].amount >= 0){
units[idleEffects[idle].effect[i]].amount += idleEffects[idle].effect[i+1] * units[idle].amount;
}
else break;
}
}
}, 1000);
setInterval(function() {
save();
}, 60000);
window.onload = function() {
for(unit in units) {
if(units[unit].atoms === 0){
calcUnitAtoms(unit);
}
newUnit(unit);
}
for(achievement in achievements) {
newAchievement(achievement);
}
document.getElementById("hydrogenSection").style.display = "block";
load();
};