forked from jatloe/RandomWebsite1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
johnidle.html
490 lines (469 loc) · 21.8 KB
/
johnidle.html
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
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="jatloesmile-hd.png">
<title>John's Idle Game</title>
<style>
.side{
display: inline;
}
.font{
font-family: 'Monospace Typewriter', monospace;
font-size: 15px;
}
</style>
</head>
<body>
<p class="side font">V1.3.24</p>
<h3 id="points" class="font" style="font-size:18px;">You have 1 points.</h3>
<button type="button" onclick="openTab(1)" class="side font">Points</button>
<button type="button" onclick="openTab(2)" class="side font" style="display:none;" id="tabbutton2">Infinity</button>
<button type="button" onclick="openTab(3)" class="side font">How to Play</button>
<button type="button" onclick="openTab(4)" class="side font">Options</button>
<br><br>
<div id="tab1">
<p class="side font" id="boostDisplay">Boost: 1</p>
<button type="button" onclick="buyBoost()" id="boost" class="font">Buy boost: 100 points</button>
<br>
<p class="side font" id="gen1Display">Generator 1: 1</p>
<button type="button" onclick="buyGen(1)" id="gen1" class="side font">1 -> 1</button>
<button type="button" onclick="buyAuto(1)" id="auto1" class="font">Generator 1 autobuyer: 1e50 points</button>
<br>
<p class="side font" id="gen2Display">Generator 2: 1</p>
<button type="button" onclick="buyGen(2)" id="gen2" class="side font">1 -> 1</button>
<button type="button" onclick="buyAuto(2)" id="auto2" class="font">Generator 2 autobuyer: 1e100 points</button>
<br>
<p class="side font" id="gen3Display">Generator 3: 1</p>
<button type="button" onclick="buyGen(3)" id="gen3" class="side font">1 -> 1</button>
<button type="button" onclick="buyAuto(3)" id="auto3" class="font">Generator 3 autobuyer: 1e150 points</button>
<br>
<p class="side font" id="gen4Display">Generator 4: 1</p>
<button type="button" onclick="buyGen(4)" id="gen4" class="side font">1 -> 1</button>
<button type="button" onclick="buyAuto(4)" id="auto4" class="font">Generator 4 autobuyer: 1e200 points</button>
<br>
<p class="side font" id="gen5Display">Generator 5: 1</p>
<button type="button" onclick="buyGen(5)" id="gen5" class="side font">1 -> 1</button>
<button type="button" onclick="buyAuto(5)" id="auto5" class="font">Generator 5 autobuyer: 1e250 points</button>
<br>
<p class="side font" id="gen6Display">Generator 6: 1</p>
<button type="button" onclick="buyGen(6)" id="gen6" class="side font">1 -> 1</button>
<button type="button" onclick="buyAuto(6)" id="auto6" class="font">Generator 6 autobuyer: 1e300 points</button>
</div>
<div id="tab2" style="display:none;">
<p class="font" id="IPdisplay">You have 1 Infinity Point(IP), boosting your game by 8x.</p>
<button type="button" onclick="buyInfUpgrade(1)" id="infupgrade1" class="font">Unlock infinity generator 1<br>Cost: 1 IP</button> <br>
<button type="button" onclick="buyInfUpgrade(2)" id="infupgrade2" class="font" style="display:none;">Infinity base increases based on generators<br>Cost: 2 IP</button> <br>
<button type="button" onclick="buyInfUpgrade(3)" id="infupgrade3" class="font" style="display:none;">Unlock infinity generator 2<br>Cost: 3 IP</button> <br>
<button type="button" onclick="buyInfUpgrade(4)" id="infupgrade4" class="font" style="display:none;">Start each infinity with 1e51 points<br>Cost: 5 IP</button> <br>
<button type="button" onclick="buyInfUpgrade(5)" id="infupgrade5" class="font" style="display:none;">Unlock infinity generator 3, current IP boosts IP gain<br>Cost: 10 IP</button> <br>
<button type="button" onclick="buyInfUpgrade(6)" id="infupgrade6" class="font" style="display:none;">Keep autobuyers 1-4 through infinities, current IP boosts infinity base gain<br>Cost: 25 IP</button> <br>
<button type="button" onclick="buyInfUpgrade(7)" id="infupgrade7" class="font" style="display:none;">Unlock infinity generator 4<br>Cost: 1000 IP</button> <br>
<button type="button" onclick="buyInfUpgrade(8)" id="infupgrade8" class="font" style="display:none;">Infinity base boosts IP gain<br>Cost: 420690 IP</button> <br>
<button type="button" onclick="buyInfUpgrade(9)" id="infupgrade9" class="font" style="display:none;">Unlock infinity generator 5<br>Cost: 6650000 IP</button> <br>
<button type="button" onclick="buyInfUpgrade(10)" id="infupgrade10" class="font" style="display:none;">Current infinity base boosts infinity base gain<br>Cost: 123456789 IP</button>
<br>
<p class="font" id="infbases">You have 1 infinity bases.</p>
<p class="side font" id="infgen1Display" style="display:none;">Infinity generator 1: 1</p>
<button type="button" onclick="buyInfGen(1)" id="infgen1" class="font" style="display:none;">1 -> 1</button>
<br>
<p class="side font" id="infgen2Display" style="display:none;">Infinity generator 2: 1</p>
<button type="button" onclick="buyInfGen(2)" id="infgen2" class="font" style="display:none;">1 -> 1</button>
<br>
<p class="side font" id="infgen3Display" style="display:none;">Infinity generator 3: 1</p>
<button type="button" onclick="buyInfGen(3)" id="infgen3" class="font" style="display:none;">1 -> 1</button>
<br>
<p class="side font" id="infgen4Display" style="display:none;">Infinity generator 4: 1</p>
<button type="button" onclick="buyInfGen(4)" id="infgen4" class="font" style="display:none;">1 -> 1</button>
<br>
<p class="side font" id="infgen5Display" style="display:none;">Infinity generator 5: 1</p>
<button type="button" onclick="buyInfGen(5)" id="infgen5" class="font" style="display:none;">1 -> 1</button>
</div>
<div id="tab3" style="display:none;">
<p class="font">In this game, when you buy a generator, all previous generators and points will reset. Each generator's new value when bought is equal to the square root of the previous generator's value(or points in the case of generator 1). Points gets increased based on the product of the generator values. Autobuyers constantly buy the generator without resetting the previous.</p>
</div>
<div id="tab4" style="display:none;">
<button onclick="save()" class="side font">Save</button>
<button onclick="importsave()" class="side font">Import</button>
<button onclick="exportsave()" class="side font">Export to Clipboard</button>
<button onclick="reset()" class="font">RESET THE GAME</button>
<textarea id="tocopy" style="display:none;"></textarea>
</div>
</body>
<script>
/*Credits:
john0512 - Original game idea creator, he created the game on Scratch then gave me permission to put it on my website; Playtester
02C00000 - Gave numerous suggestions on improving the game
DottedCalculator: Playtester
jatloe - Me!
*/
//Basic setup
let points = 1;
let gencount = [1,1,1,1,1,1,points];
let boost = 1;
let IP = 0;
let rate = 1;
let largestindex=0;
let inflargestindex=0;
let autobuyer = [false,false,false,false,false,false];
let autocosts = [Math.pow(10,50),Math.pow(10,100),Math.pow(10,150),Math.pow(10,200),Math.pow(10,250),Math.pow(10,300)];
let infupgrade = [false,false,false,false,false,false,false,false,false,false];
let infbase = 1;
let infgen = [1,1,1,1,1];
let infupgradecost = [1,2,3,5,10,25,1000,420690,6650000,123456789];
let infupgradetext = ["Unlock infinity generator 1","Infinity base increases more quickly","Unlock infinity generator 2","Start each infinity with 1e51 points","Unlock infinity generator 3, current IP boosts IP gain","Keep autobuyers 1-4 through infinities, current IP boosts infinity base gain","Unlock infinity generator 4","Infinity base boosts IP gain","Unlock infinity generator 5","Current infinity base boosts infinity base gain"];
let lasttick = Date.now();
let thistick = 0;
let currenttab = 1;
let infinitied = false;
let beaten = false;
load();
setInterval(update,50);
setInterval(save,10000);
function update() {
gencount[6] = points; // Essentially letting generator 0 to reference points in a for loop
//Check autobuyers
for(i=0;i<=5;i++) {
if(autobuyer[i] == true) {
gencount[i] = Math.sqrt(gencount[workingIndex(i-1)]);
}
}
if(isFinite(points) == false) {
infinitied = true;
document.getElementById("tabbutton2").style.display = "";
let newpoints = 1;
let ipgain = 1;
if(infupgrade[3] == true) {
newpoints = Math.pow(10,51);
}
if(infupgrade[4] == true) {
ipgain = Math.floor(Math.sqrt(IP)) + 1;
}
if(infupgrade[7] == true) {
ipgain = ipgain * Math.max(1,Math.pow(infbase,0.01));
}
let newinfo = {"points":newpoints,"gencount":[1,1,1,1,1,1,1],"boost":1,"IP":Math.max(1,Math.floor(IP+ipgain)),"autobuyer":[false,false,false,false,false,false],"lasttick":Date.now(),"infupgrade":infupgrade,"infbase":infbase,"infgen":infgen,"infinitied":true};
let player = JSON.stringify(newinfo);
localStorage.setItem('johnidlesave4', player);
load();
for(i=1;i<=6;i++) {
document.getElementById("auto" + String(i)).innerHTML = "Generator " + String(i) + " autobuyer: 1e" + String(i*50) + " points";
}
}
if(infinitied == true) {
document.getElementById("tabbutton2").style.display = "";
}
if(infupgrade[5] == true) {
for(num = 1; num <= 4; num++) {
autobuyer[num-1]=true;
document.getElementById("auto" + String(num)).innerHTML = "Generator " + String(num) + " autobuyer bought!";
}
}
document.getElementById("IPdisplay").innerHTML = "You have " + String(IP) + " Infinity Point(IP), boosting your game by " + stringify(Math.pow(1+IP,3)) + "x.";
//Increase points, update displays
thistick = Date.now();
rate = gencount[0]*gencount[1]*gencount[2]*gencount[3]*gencount[4]*gencount[5]*boost*Math.pow(1+IP,3)*infgen[0]*infgen[1]*infgen[2]*infgen[3]*infgen[4]*Math.max(0,thistick-lasttick)/50;
if(infinitied == true) {
let infbasegain = Math.max(0,thistick-lasttick)/50;
if(infupgrade[1] == true) {
infbasegain = infbasegain*infgen[0]*infgen[1]*infgen[2]*infgen[3]*infgen[4];
}
if(infupgrade[5] == true) {
infbasegain = infbasegain*IP;
}
if(infupgrade[9] == true) {
infbasegain = infbasegain * Math.max(1,Math.pow(Math.log(infbase),3));
}
infbase = infbase + infbasegain;
}
lasttick = thistick;
points = points + rate;
document.getElementById("points").innerHTML = "You have " + stringify(points) + " points.";
document.getElementById("boost").innerHTML = "Buy boost: " + booststring(boostCost(boost)) + " points";
document.getElementById("boostDisplay").innerHTML = "Boost: " + String(boost);
largestindex=0;
for(i=0;i<6;i++) {
document.getElementById("gen" + String(i+1) + "Display").innerHTML = "Generator " + String(i+1) + ": " + stringify(gencount[i]);
document.getElementById("gen" + String(i+1)).innerHTML = stringify(gencount[i]) + " -> " + stringify(Math.sqrt(gencount[workingIndex(i+6)]));
if(gencount[i] != 1) {
largestindex=i;
}
}
//Hide and show generators based on if they are used
for(j=0;j<=Math.min(largestindex+1,5);j++) {
document.getElementById("gen" + String(j+1) + "Display").style.display = "";
document.getElementById("gen" + String(j+1)).style.display = "";
document.getElementById("auto" + String(j+1)).style.display = "";
}
for(k=largestindex+2;k<6;k++) {
document.getElementById("gen" + String(k+1) + "Display").style.display = "none";
document.getElementById("gen" + String(k+1)).style.display = "none";
document.getElementById("auto" + String(k+1)).style.display = "none";
}
//Same but for IU
inflargestindex=0;
for(i=0;i<10;i++) {
if(infupgrade[i] == true) {
inflargestindex=i;
}
}
for(j=0;j<=Math.min(inflargestindex+1,9);j++) {
document.getElementById("infupgrade" + String(j+1)).style.display = "";
}
for(k=inflargestindex+2;k<10;k++) {
document.getElementById("infupgrade" + String(k+1)).style.display = "none";
}
document.getElementById("infbases").innerHTML = "You have " + stringify(infbase) + " infinity bases.";
if(infupgrade[0] == true) {
document.getElementById("infgen1Display").style.display = "";
document.getElementById("infgen1").style.display = "";
}
if(infupgrade[2] == true) {
document.getElementById("infgen2Display").style.display = "";
document.getElementById("infgen2").style.display = "";
}
if(infupgrade[4] == true) {
document.getElementById("infgen3Display").style.display = "";
document.getElementById("infgen3").style.display = "";
}
if(infupgrade[6] == true) {
document.getElementById("infgen4Display").style.display = "";
document.getElementById("infgen4").style.display = "";
}
if(infupgrade[8] == true) {
document.getElementById("infgen5Display").style.display = "";
document.getElementById("infgen5").style.display = "";
}
for(i=0;i<5;i++) {
document.getElementById("infgen" + String(i+1) + "Display").innerHTML = "Infinity Generator " + String(i+1) + ": " + stringify(infgen[i]);
if(i == 0){
document.getElementById("infgen" + String(i+1)).innerHTML = stringify(infgen[i]) + " -> " + stringify(Math.sqrt(infbase));
} else {
document.getElementById("infgen" + String(i+1)).innerHTML = stringify(infgen[i]) + " -> " + stringify(Math.sqrt(infgen[i-1]));
}
}
if(isFinite(infbase) == false && beaten == false) {
alert("GG! You have beaten the current game.");
beaten = true;
}
}
//End of update function
function openTab(tab) {
document.getElementById("tab" + String(currenttab)).style.display = "none";
document.getElementById("tab" + String(tab)).style.display = "";
currenttab=tab;
}
function save() {
let info = {"points":points,"gencount":gencount,"boost":boost,"IP":IP,"autobuyer":autobuyer,"lasttick":lasttick,"infupgrade":infupgrade,"infbase":infbase,"infgen":infgen,"infinitied":infinitied};
let player = JSON.stringify(info);
localStorage.setItem('johnidlesave4', player);
}
function load() {
if(localStorage.getItem('johnidlesave4') != null) {
info = JSON.parse(localStorage.getItem('johnidlesave4'));
points = info.points;
if(points === null) {
points = Math.pow(10,310);
}
gencount = info.gencount;
boost = info.boost;
IP = info.IP;
autobuyer = info.autobuyer;
lasttick = info.lasttick;
infupgrade = info.infupgrade;
infbase = info.infbase;
infgen = info.infgen;
infinitied = info.infinitied;
} else if(localStorage.getItem('johnidlesave3') != null) {
info = JSON.parse(localStorage.getItem('johnidlesave3'));
points = info.points;
if(points === null) {
points = Math.pow(10,310);
}
gencount = info.gencount;
boost = info.boost;
IP = info.IP;
autobuyer = info.autobuyer;
lasttick = info.lasttick;
infupgrade = info.infupgrade;
infbase = info.infbase;
infgen = info.infgen;
} else if(localStorage.getItem('johnidlesave2') != null) {
info = JSON.parse(localStorage.getItem('johnidlesave2'));
points = info.points;
if(points === null) {
points = Math.pow(10,310);
}
gencount = info.gencount;
boost = info.boost;
IP = info.IP;
autobuyer = info.autobuyer;
lasttick = info.lasttick;
} else if(localStorage.getItem('johnidlesave1') != null) {
info = JSON.parse(localStorage.getItem('johnidlesave1'));
points = info.points;
if(points === null) {
points = Math.pow(10,310);
}
gencount = info.gencount;
boost = info.boost;
IP = info.IP;
autobuyer = info.autobuyer;
} else if (localStorage.getItem('johnidlepoints') != null) {
points = Number(localStorage.getItem('johnidlepoints'));
}
for(i=1;i<=6;i++) {
if(autobuyer[i-1] == true) {
document.getElementById("auto" + String(i)).innerHTML = "Generator " + String(i) + " autobuyer bought!";
}
}
for(j=1;j<=10;j++) {
if(infupgrade[j-1] == true) {
document.getElementById("infupgrade" + String(j)).innerHTML = infupgradetext[j-1] + "<br>Bought!";
}
}
if(IP > 0) {
infinitied = true;
}
}
//Hotkeys
document.onkeyup = function(e) {
if(currenttab == 1) {
if (e.which == 49 || e.which == 97) {
buyGen(1);
} else if (e.which == 50 || e.which == 98) {
buyGen(2);
} else if (e.which == 51 || e.which == 99) {
buyGen(3);
} else if (e.which == 52 || e.which == 100) {
buyGen(4);
} else if (e.which == 53 || e.which == 101) {
buyGen(5);
} else if (e.which == 54 || e.which == 102) {
buyGen(6);
} else if (e.which == 66) {
buyBoost();
}
} else if(currenttab == 2) {
if (e.which == 49 || e.which == 97) {
buyInfGen(1);
} else if (e.which == 50 || e.which == 98) {
buyInfGen(2);
} else if (e.which == 51 || e.which == 99) {
buyInfGen(3);
} else if (e.which == 52 || e.which == 100) {
buyInfGen(4);
} else if (e.which == 53 || e.which == 101) {
buyInfGen(5);
}
}
};
window.addEventListener('beforeunload', function(e) {
save();
});
//This function turns numbers into nice numbers
function stringify(number) {
if(number<1000000) {
return number.toFixed(3);
} else if(isFinite(number)) {
let power = Math.floor(Math.log10(number));
number = number/Math.pow(10,power);
return number.toFixed(3) + "e" + String(power);
} else if(isNaN(number)) {
return "NaN";
} else {
return "Infinity";
}
}
function booststring(number) {
if(number>1000000) {
return "1e" + String(Math.log10(number));
} else {
return number;
}
}
//WOWLOG!!
function log(a,b) {
return Math.round(Math.log(b) / Math.log(a));
}
function boostCost(x) {
return Math.pow(10,Math.pow(2,log(3,x)+1));
}
function buyBoost() {
if(points>=boostCost(boost) && isFinite(boostCost(boost))) {
points = points - boostCost(boost);
boost = boost * 3;
update();
}
}
//Really annoying with the workingIndex lol, I'm glad it worked
function buyGen(num) {
if(gencount[workingIndex(num+6)] < Math.sqrt(gencount[workingIndex(num+5)])) {
gencount[workingIndex(num+6)] = Math.sqrt(gencount[workingIndex(num+5)]);
for(let i=-1;i<num-1;i++) {
gencount[workingIndex(i)]=1;
}
points = 1;
update();
}
}
function workingIndex(num) {
return (num+700)%7; //Essentially forces the input to be positive without changing residue mod 7
}
function buyAuto(num) {
if(points>=autocosts[num-1] && autobuyer[num-1] == false) {
points = points - autocosts[num-1];
autobuyer[num-1]=true;
document.getElementById("auto" + String(num)).innerHTML = "Generator " + String(num) + " autobuyer bought!";
update();
}
}
function buyInfUpgrade(num) {
if(IP>=infupgradecost[num-1] && infupgrade[num-1] == false) {
IP = IP - infupgradecost[num-1];
infupgrade[num-1] = true;
document.getElementById("infupgrade" + String(num)).innerHTML = infupgradetext[num-1] + "<br>Bought!";
}
}
function buyInfGen(num) {
if(num == 1) {
if(infgen[0] < Math.sqrt(infbase)) {
infgen[0] = Math.sqrt(infbase);
infbase = 1;
update();
}
} else {
if(infgen[num-1] < Math.sqrt(infgen[num-2])) {
infgen[num-1] = Math.sqrt(infgen[num-2]);
for(let i=0;i<num-1;i++) {
infgen[i]=1;
}
infbase = 1;
update();
}
}
}
function reset() {
if (confirm("Are you sure you want to reset the game?")) {
let resetinfo = {"points":1,"gencount":[1,1,1,1,1,1,1],"boost":1,"IP":0,"autobuyer":[false,false,false,false,false,false],"lasttick":Date.now(),"infupgrade":[false,false,false,false,false,false,false,false,false,false],"infbase":1,"infgen":[1,1,1,1,1],"infinitied":false};
let player = JSON.stringify(resetinfo);
localStorage.setItem('johnidlesave4', player);
load();
}
}
function importsave() {
let gameString = prompt('Enter your save:');
let savever = prompt('Save version(current is 4, ask jatloe if you want to make sure):');
localStorage.setItem('johnidlesave' + String(savever), atob(gameString));
load();
}
function exportsave() {
let info = {"points":points,"gencount":gencount,"boost":boost,"IP":IP,"autobuyer":autobuyer,"lasttick":lasttick,"infupgrade":infupgrade,"infbase":infbase,"infgen":infgen,"infinitied":infinitied};
let player = btoa(JSON.stringify(info));
document.getElementById("tocopy").style.display = "";
document.getElementById("tocopy").value = player;
document.getElementById("tocopy").select();
document.execCommand('copy');
document.getElementById("tocopy").style.display = "none";
}
</script>
</html>