-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
704 lines (650 loc) · 29.1 KB
/
script.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
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
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
$(document).ready(function(){
// Layout script, sets body to window size at start
var bwidth = ($(window).width());
var bheight = ($(window).height());
function isiPhone(){
return (
(navigator.platform.indexOf("iPhone") != -1) ||
(navigator.platform.indexOf("iPod") != -1)
);
}
// $('#tmrlap').html(navigator.platform);
$('#loaderboxPhone').hide();
if(isiPhone()){
$('#loaderboxPad').hide();
$('#loaderboxPhone').show();
}
// $('#tmrlap').html(bwidth + ' ' + bheight);
bwidth -= 50;
bheight -= 50;
$('body').css('width', bwidth + 'px');
$('body').css('height', bheight + 'px');
$('#loaderready').hide();
$('.loaderBtn').click(function(){
var gameOver = document.getElementsByTagName("audio")[1];
gameOver.play();
$('.loaderBox').fadeOut(1000);
});
// No double tap zooming on buttons when double tapped
$('.updownbutton,.buttons').nodoubletapzoom();
// Breach box toggles
$('div.breachbtn').click(function(){
$(this).toggleClass("redbtn");
});
// Health box toggles
var hideCrisis = function() {
$('#hthCrisisQP').hide();
$('#hthCrisisQN').hide();
$('#hthCrisisTP').hide();
$('#hthCrisisTN').hide();
};
hideCrisis();
$("#hthCrisisSel").change(function() {
var pickMe = $('option:selected', this).val();
hideCrisis();
if (pickMe !== 'hthCrisisDis') {
$('#'+pickMe).show();
}
});
$('div.health_container .healthBar:nth-child(2)').addClass('whiteText');
var hullNow = 1;
$('div.health_container .healthBar').click(function(){
$(this).siblings('.healthBar').removeClass('greybtn').removeClass('greyText').removeClass('whiteText');
$(this).removeClass('greybtn').removeClass('greyText').addClass('whiteText');
var boxNum = $(this).index();
var boxes = $(this).parents('.health_container').children('.healthBar');
var startBar = 0;
if ($(this).hasClass('hullBar')) {
hullNow = boxNum;
}
$('#debugText').append(hullNow + '<br />');
if (boxNum > 0) {
boxes.slice( startBar, boxNum -1 ).each(function(){
if (!$(this).hasClass('greybtn')){
$(this).addClass('greybtn').addClass('greyText');
}
});
} else {
$(this).removeClass('greybtn').removeClass('greyText').addClass('whiteText');
}
});
// Settings box toggles
$('#settings').hide();
$('#debugBox').hide();
$('#credits').hide();
$('#redAlert').hide();
$('#gameOver').hide();
$('#setbtn').click(function(){
$('#timer').hide();
$('#settings').show();
});
$('#mainbtn').click(function(){
$('#settings').hide();
$('#timer').show();
});
$('#crsetbtn').click(function(){
$('#credits').hide();
$('#settings').show();
});
$('#crmainbtn').click(function(){
$('#credits').hide();
$('#timer').show();
});
$('#credbtn').click(function(){
$('#settings').hide();
$('#credits').show();
});
// System Status module display
$('.checkEnabled').change(function() {
var selBox = $(this).attr('id').substring(0,2);
if ($('#' + selBox + 'Enabled').prop('checked')) {
$('#' + selBox + 'Display').show();
} else {
$('#' + selBox + 'Display').hide();
}
});
$('.checkCritical').change(function() {
var selBox = $(this).attr('id').substring(0,2);
if ($('#' + selBox + 'Critical').prop('checked')) {
$('#' + selBox + 'System').addClass('redtext');
} else {
$('#' + selBox + 'System').removeClass('redtext');
}
});
// System Status installed in switches
$(".dropSystem").change(function() {
var selBox = $(this).attr('id');
var selBoxId = '#' + selBox;
var selBoxSub = $(this).attr('id').substring(0,2);
var selSysName = $('option:selected', this).text();
$('#' + selBoxSub + 'System').html(selSysName);
var selSysVal = $('option:selected', this).val();
var selSysDefault = 50;
switch(selSysVal) {
case 'sysLifeSup':
selSysDefault = 80;
break;
case 'sysShields':
selSysDefault = 50;
break;
case 'sysHyper':
selSysDefault = 0;
break;
case 'sysTeleport':
selSysDefault = 50;
break;
case 'sysLasers':
selSysDefault = 50;
break;
case 'sysCargoBay':
selSysDefault = 60;
break;
case 'sysEnergy':
selSysDefault = 100;
break;
default:
selSysDefault = 50;
}
$('#' + selBoxSub + 'Out').html(selSysDefault);
$('#' + selBoxSub + 'Out').removeClass('sysLifeSup sysShields sysHyper sysTeleport sysLasers sysCargoBay sysEnergy');
$('#' + selBoxSub + 'Out').removeClass('css100 css90 css80 css70 css60 css50 css40 css30 css20 css10 css0');
$('#' + selBoxSub + 'Out').addClass(selSysVal);
var newCls = 'css' + $('#' + selBoxSub + 'Out').html();
$('#' + selBoxSub + 'Out').addClass(newCls);
});
// System Status buttons - THIS SUCKS AND NEEDS TO BE REDONE WITH REPEATABLE FUNCTION
$('#pcOut').addClass('css50');
$('#fgOut').addClass('css50');
$('#peOut').addClass('css50');
$('#trOut').addClass('css50');
$('#smOut').addClass('css50');
$('.updownbutton').click(function () {
var selBox = $(this).attr('id');
var selBoxSub = $(this).attr('id').substring(0, 2);
var selBoxType = $(this).attr('id').substring(2, 4);
var selBoxVal = parseInt($('#' + selBoxSub + 'Out').html(), 10);
var oldCls = 'css' + $('#' + selBoxSub + 'Out').html();
$('#' + selBoxSub + 'Out').removeClass(oldCls);
if (selBoxType === 'Up') {
if ($('#' + selBoxSub + 'Out').html() < 100) {
selBoxVal += 10;
}
}
if (selBoxType === 'Dn') {
if ($('#' + selBoxSub + 'Out').html() > 0) {
selBoxVal -= 10;
}
}
$('#' + selBoxSub + 'Out').html(selBoxVal);
var newCls = 'css' + $('#' + selBoxSub + 'Out').html();
$('#' + selBoxSub + 'Out').addClass(newCls);
});
$('#showDebug').click(function(){
$('#debugBox').show();
});
var setDRDeck = $('#tmrDRDeck').val();
var setDREvent = $('#tmrDREvent').val();
var drinitdeck = parseInt(setDRDeck, 10); // + parseInt(setDREvent, 10);
// Create the card structure
function Drcard(name, shield, title, text, pcnos, pcsld, fgnos, fgsld, penos, pesld, trnos, trsld, smnos, smsld, breachnos, breachsld) {
this.name = name;
this.shield = shield;
this.title = title;
this.text = text;
this.pcnos = pcnos;
this.pcsld = pcsld;
this.fgnos = fgnos;
this.fgsld = fgsld;
this.penos = penos;
this.pesld = pesld;
this.trnos = trnos;
this.trsld = trsld;
this.smnos = smnos;
this.smsld = smsld;
this.breachnos = breachnos;
this.breachsld = breachsld;
Drcard.counter = Drcard.counter + 1;
}
Drcard.counter = 0;
// Insert cards into full deck
// shield green orange purple grey bluw
var cardDR = [];
cardDR[1] = new Drcard('DR01',80,'na','na',30,20,10,10,0,0,0,0,30,30,'na','na');
cardDR[2] = new Drcard('DR02',60,'na','na',10,10,20,0,0,0,20,20,10,50,'na','na');
cardDR[3] = new Drcard('DR03',40,'na','na',20,20,40,30,0,0,0,0,10,20,'na','na');
cardDR[4] = new Drcard('DR04',90,'na','na',0,0,10,0,20,20,30,20,20,30,'na','na');
cardDR[5] = new Drcard('DR05',50,'na','na',20,10,30,20,0,0,0,0,30,60,'na','na');
cardDR[6] = new Drcard('DR06',70,'na','na',30,20,0,0,0,0,40,20,30,40,'na','na');
cardDR[7] = new Drcard('DR07',50,'na','na',10,0,40,30,0,0,0,0,0,20,'na','na');
cardDR[8] = new Drcard('DR08',50,'na','na',0,0,20,20,40,20,0,0,20,20,'na','na');
cardDR[9] = new Drcard('DR09',40,'na','na',10,10,20,10,30,20,0,0,10,20,'na','na');
cardDR[10] = new Drcard('DR10',50,'na','na',30,20,20,10,0,0,0,0,10,20,'na','na');
cardDR[11] = new Drcard('DR11',100,'na','na',0,0,0,0,20,10,0,0,20,50,'a3','na');
cardDR[12] = new Drcard('DR12',50,'na','na',0,0,20,10,10,10,0,0,10,50,'d8','na');
cardDR[13] = new Drcard('DR13',100,'na','na',0,0,0,0,10,10,0,0,20,50,'b9','na');
cardDR[14] = new Drcard('DR14',70,'na','na',0,0,20,20,0,0,20,10,20,40,'na','na');
cardDR[15] = new Drcard('DR15',50,'na','na',0,0,0,0,0,0,20,30,20,40,'e6','na');
cardDR[16] = new Drcard('DR16',70,'na','na',30,30,0,0,0,0,0,0,30,60,'f1','na');
cardDR[17] = new Drcard('DR17',20,'na','na',30,20,0,0,40,30,0,0,10,30,'na','na');
cardDR[18] = new Drcard('DR18',30,'na','na',10,0,10,0,0,0,0,0,20,30,'c4','c4');
cardDR[19] = new Drcard('DR19',50,'na','na',20,20,0,0,0,0,50,30,20,40,'na','na');
cardDR[20] = new Drcard('DR20',70,'na','na',20,20,0,0,40,20,0,0,10,40,'na','na');
cardDR[21] = new Drcard('DR21',60,'na','na',20,20,20,10,0,0,0,0,10,40,'a3','na');
cardDR[22] = new Drcard('DR22',80,'na','na',20,20,0,0,0,0,40,10,10,40,'na','na');
cardDR[23] = new Drcard('DR23',50,'na','na',30,20,0,0,20,10,40,30,10,50,'na','na');
cardDR[24] = new Drcard('DR24',30,'na','na',0,0,10,0,0,0,10,0,20,40,'d8','d8');
cardDR[25] = new Drcard('DR25',30,'na','na',30,20,0,0,10,0,0,0,20,40,'e6','e6');
cardDR[26] = new Drcard('DR26',60,'na','na',20,10,0,0,0,0,20,20,20,50,'b9','na');
cardDR[27] = new Drcard('DR27',30,'na','na',0,0,0,0,10,10,10,10,20,30,'f1','na');
cardDR[28] = new Drcard('DR28',80,'na','na',10,10,0,0,30,20,40,20,10,40,'na','na');
cardDR[29] = new Drcard('DR29',50,'na','na',20,10,0,0,10,10,0,0,20,30,'a3','na');
cardDR[30] = new Drcard('DR30',50,'na','na',0,0,0,0,20,20,0,0,30,50,'b9','na');
cardDR[31] = new Drcard('DR31',100,'na','na',0,0,20,0,20,20,30,20,30,70,'na','na');
cardDR[32] = new Drcard('DR32',60,'na','na',0,0,0,0,40,20,20,10,20,40,'na','na');
cardDR[33] = new Drcard('DR33',30,'na','na',0,0,0,0,40,30,20,20,10,20,'na','na');
cardDR[34] = new Drcard('DR34',70,'na','na',0,0,0,0,0,0,20,20,20,30,'c4','na');
cardDR[35] = new Drcard('DR35',90,'na','na',30,20,10,10,0,0,10,10,20,30,'na','na');
cardDR[36] = new Drcard('DR36',80,'na','na',0,0,0,0,0,0,30,20,30,60,'c4','na');
cardDR[37] = new Drcard('DR37',70,'na','na',0,0,20,20,0,0,0,0,30,50,'d8','na');
cardDR[38] = new Drcard('DR38',70,'na','na',30,30,0,0,0,0,0,0,30,50,'e6','na');
cardDR[39] = new Drcard('DR39',70,'na','na',0,0,0,0,20,20,0,0,30,50,'f1','na');
cardDR[40] = new Drcard('DR40','na','GAME OVER','na','na','na','na','na','na','na','na','na','na','na','na','na');
cardDR[41] = new Drcard('DR41','na','ENERGY BURST','Discard all Energies on the ship floor back to the Energy supply Module. Draw and Resolve another Damage Report.','na','na','na','na','na','na','na','na','na','na','na','na');
cardDR[42] = new Drcard('DR42','na','CRYSTALS SHATTERED','Discard all Crystals on the ship floor back to the Crystal supply Module. Draw and Resolve another Damage Report.','na','na','na','na','na','na','na','na','na','na','na','na');
cardDR[43] = new Drcard('DR43','na','CIRCUITS FRIED','Discard all Circuits on the ship floor back to the Circuit supply Module. Draw and Resolve another Damage Report.','na','na','na','na','na','na','na','na','na','na','na','na');
cardDR[44] = new Drcard('DR44','na','SEALED OFF','Draw a Module card. Place this card on the Module indicated. No one may move into this Module while the card is here. Remove this card after the Damage Report timer sounds again. Draw and resolve another Damage Report.','na','na','na','na','na','na','na','na','na','na','na','na');
cardDR[45] = new Drcard('DR45','na','LIVE WIRE','Draw a Module card. Place this card on the Module indicated. Each time players move into this Module for the remainder of the game, they receive 1 Injury token. Draw and resolve another Damage Report.','na','na','na','na','na','na','na','na','na','na','na','na');
cardDR[46] = new Drcard('DR46','na','SUPPLY SHORTAGE','Remove 5 of each type of non-tool supply from the game. Draw and resolve another Damage Report.','na','na','na','na','na','na','na','na','na','na','na','na');
cardDR[47] = new Drcard('DR47','na','CRITICAL HIT','Take 25% hull damage. Draw and resolve another Damage Report.','na','na','na','na','na','na','na','na','na','na','na','na');
cardDR[48] = new Drcard('DR48','na','UNEXPECTED DELAYS','All players immediately slide their timers to the black clock. Draw and resolve another Damage Report.','na','na','na','na','na','na','na','na','na','na','na','na');
cardDR[49] = new Drcard('DR49','na','GAS LEAK','Until the next Damage Report timer sounds, all non-robot players start their turns one clock farther to the left (never going beyond the black clock). Draw and resolve another Damage Report.','na','na','na','na','na','na','na','na','na','na','na','na');
cardDR[50] = new Drcard('DR50','na','DISASTER LOOMS','Discard the next Damage Report card from the Damage Report deck. Draw and resolve another Damage Report.','na','na','na','na','na','na','na','na','na','na','na','na');
cardDR[51] = new Drcard('DR51','na','CATACLYSM','Without revealing them, shuffle the bottom 3 cards on the Damage Report deck and then return them to the bottom of the deck. Draw and resolve another Damage Report.','na','na','na','na','na','na','na','na','na','na','na','na');
cardDR[52] = new Drcard('DR52','na','MICRO-ORGANISM ATTACK','All players receive 2 Injury tokens. Draw and resolve another Damage Report.','na','na','na','na','na','na','na','na','na','na','na','na');
// var maxVal = Drcard.counter;
var maxVal = 39;
// Draw cards to use in game
var gameDraws = drinitdeck - 1;
var gameDeck = [];
while (gameDeck.length < gameDraws) {
var randomnumber = Math.floor(Math.random() * (maxVal - 1 + 1)) + 1;
var found=false;
for (var i=0;i<gameDeck.length;i++) {
if (gameDeck[i]==randomnumber) {
found=true;
break;
}
}
if (!found) {
gameDeck[gameDeck.length]=randomnumber;
}
}
var drawNum = 0;
// Pull card from drawn cards and apply it
var drawCard = function() {
var rando = gameDeck[drawNum];
drawNum++;
var statShields = $('.sysShields').html();
if (statShields == null) {
statShields = 0;
}
var checkHull = 0;
if (statShields <= 0) {
checkHull += 1;
}
var cardShields = cardDR[rando].shield;
var cardName = cardDR[rando].name;
$('#debugText').append('Shields ' + statShields + '<br />');
$('#debugText').append('Drew card ' + cardName + ' - ' + hullNow + '<br />');
if (statShields < cardShields) {
if (cardDR[rando].pcnos > 0) {
$('#pcOut').addClass('redtext');
$('#pcOut').removeClass('css' + $('#pcOut').html());
$('#pcOut').html(($('#pcOut').html() - cardDR[rando].pcnos));
if ($('#pcOut').html() > 0) {
$('#pcOut').addClass('css' + $('#pcOut').html());
} else {
$('#pcOut').addClass('css0');
}
}
if (cardDR[rando].fgnos > 0) {
$('#fgOut').addClass('redtext');
$('#fgOut').removeClass('css' + $('#fgOut').html());
$('#fgOut').html(($('#fgOut').html() - cardDR[rando].fgnos));
if ($('#fgOut').html() > 0) {
$('#fgOut').addClass('css' + $('#fgOut').html());
} else {
$('#fgOut').addClass('css0');
}
}
if (cardDR[rando].penos > 0) {
$('#peOut').addClass('redtext');
$('#peOut').removeClass('css' + $('#peOut').html());
$('#peOut').html(($('#peOut').html() - cardDR[rando].penos));
if ($('#peOut').html() > 0) {
$('#peOut').addClass('css' + $('#peOut').html());
} else {
$('#peOut').addClass('css0');
}
}
if (cardDR[rando].trnos > 0) {
$('#trOut').addClass('redtext');
$('#trOut').removeClass('css' + $('#trOut').html());
$('#trOut').html(($('#trOut').html() - cardDR[rando].trnos));
if ($('#trOut').html() > 0) {
$('#trOut').addClass('css' + $('#trOut').html());
} else {
$('#trOut').addClass('css0');
}
}
if (cardDR[rando].smnos > 0) {
$('#smOut').addClass('redtext');
$('#smOut').removeClass('css' + $('#smOut').html());
$('#smOut').html(($('#smOut').html() - cardDR[rando].smnos));
if ($('#smOut').html() > 0) {
$('#smOut').addClass('css' + $('#smOut').html());
} else {
$('#smOut').addClass('css0');
}
}
if (cardDR[rando].breachnos !== 'na') {
$('#breach' + cardDR[rando].breachnos).addClass('redbtn').addClass('redtext');
}
} else {
if (cardDR[rando].pcsld > 0) {
$('#pcOut').addClass('redtext');
$('#pcOut').removeClass('css' + $('#pcOut').html());
$('#pcOut').html(($('#pcOut').html() - cardDR[rando].pcsld));
if ($('#pcOut').html() > 0) {
$('#pcOut').addClass('css' + $('#pcOut').html());
} else {
$('#pcOut').addClass('css0');
}
}
if (cardDR[rando].fgsld > 0) {
$('#fgOut').addClass('redtext');
$('#fgOut').removeClass('css' + $('#fgOut').html());
$('#fgOut').html(($('#fgOut').html() - cardDR[rando].fgsld));
if ($('#fgOut').html() > 0) {
$('#fgOut').addClass('css' + $('#fgOut').html());
} else {
$('#fgOut').addClass('css0');
}
}
if (cardDR[rando].pesld > 0) {
$('#peOut').addClass('redtext');
$('#peOut').removeClass('css' + $('#peOut').html());
$('#peOut').html(($('#peOut').html() - cardDR[rando].pesld));
if ($('#peOut').html() > 0) {
$('#peOut').addClass('css' + $('#peOut').html());
} else {
$('#peOut').addClass('css0');
}
}
if (cardDR[rando].trsld > 0) {
$('#trOut').addClass('redtext');
$('#trOut').removeClass('css' + $('#trOut').html());
$('#trOut').html(($('#trOut').html() - cardDR[rando].trsld));
if ($('#trOut').html() > 0) {
$('#trOut').addClass('css' + $('#trOut').html());
} else {
$('#trOut').addClass('css0');
}
}
if (cardDR[rando].smsld > 0) {
$('#smOut').addClass('redtext');
$('#smOut').removeClass('css' + $('#smOut').html());
$('#smOut').html(($('#smOut').html() - cardDR[rando].smsld));
if ($('#smOut').html() > 0) {
$('#smOut').addClass('css' + $('#smOut').html());
} else {
$('#smOut').addClass('css0');
}
}
if (cardDR[rando].breachsld !== 'na') {
$('#breach' + cardDR[rando].breachsld).addClass('redbtn').addClass('redtext');
}
}
// Take hull damage if Shields were at 0 at the start and took damage this turn
if (checkHull === 1 && $('.sysShields').html() < 0) {
hullNow = hullNow + 1;
if (hullNow > 5) {
hullNow = 5;
}
// $('#hullOut').html(hullNow);
hullTarget = hullNow + 1;
$('div.health_container .healthBar.hullBar:nth-child(' + hullTarget + ')').addClass('redtext').addClass('whiteText');
$('div.health_container .healthBar.hullBar:nth-child(' + hullNow + ')').addClass('greybtn').addClass('greyText').removeClass('whiteText');
}
// Reset any negative values to 0
if ($('#pcOut').html() < 0) {
$('#pcOut').html('0');
}
if ($('#fgOut').html() < 0) {
$('#fgOut').html('0');
}
if ($('#peOut').html() < 0) {
$('#peOut').html('0');
}
if ($('#trOut').html() < 0) {
$('#trOut').html('0');
}
if ($('#smOut').html() < 0) {
$('#smOut').html('0');
}
if ($('#hullOut').html() > 5) {
$('#hullOut').html('5');
}
// Remove redtext from all changed values
setTimeout(function() {
$('.statusout, .breachbtn, div.health_container .healthBar.hullBar').removeClass('redtext');
}, 1000);
// Game over if system is critical or hull hits 0
/* if ($('#pcOut').hasClass('sysCritical') && $('#pcOut').html() <= 0) {
$('#gameOut').append('GAME OVER - Plasma Capacitor<br />');
}
if ($('#fgOut').hasClass('sysCritical') && $('#fgOut').html() <= 0) {
$('#gameOut').append('GAME OVER - Flux Generator<br />');
}
if ($('#peOut').hasClass('sysCritical') && $('#peOut').html() <= 0) {
$('#gameOut').append('GAME OVER - Photonic Emitter<br />');
}
if ($('#trOut').hasClass('sysCritical') && $('#trOut').html() <= 0) {
$('#gameOut').append('GAME OVER - Torque Relay<br />');
}
if ($('#smOut').hasClass('sysCritical') && $('#smOut').html() <= 0) {
$('#gameOut').append('GAME OVER - Sonic Modulator<br />');
}
if ($('#hullOut').html() >= 5) {
$('#gameOut').append('GAME OVER - hull<br />');
} */
};
$('#pickNew').click(function() {
if ($('#autoDRApply').prop('checked')) {
drawCard();
}
});
// Timer script
// Initialise timer buttons
$('#tmrpause').hide();
$('#tmrresume').hide();
$('#tmrreset').hide();
$('#gameoverdisp').hide();
var pcInit = 0;
var fgInit = 0;
var peInit = 0;
var trInit = 0;
var smInit = 0;
// Timer display
var timer = Tock({
callback: function () {
$('#tmrdisp').html(function() {
var ms = timer.lap();
// Initialise timer
if (ms <= 0) {
return "0:00.00";
}
// Calculate from raw milliseconds to m:ss.cs
var milliseconds = Math.floor((ms / 10) % 100).toString(),
seconds = Math.floor((ms / 1000) % 60).toString(),
minutes = Math.floor((ms / (60 * 1000)) % 60).toString();
// Add leading 0 to ss.cs
if (milliseconds.length === 1) {
milliseconds = '0' + milliseconds;
}
if (seconds.length === 1) {
seconds = '0' + seconds;
}
// Send result to display
return minutes + ":" + seconds + "." + milliseconds;
});
}
});
// Grab initial countdown interval and deck size from Settings page
var setInterSet = $('#tmrInterSet').val();
var tmrInterval = timer.timeToMS(setInterSet);
var setTotalTmr = tmrInterval * drinitdeck;
$('#setTotTime').html(timer.msToTime(setTotalTmr));
// var tmrInterval = 10000;
// var drinitdeck = 3;
var drnowdeck = drinitdeck;
// $('#tmrlap').html(tmrInterval + ' ' + drinitdeck + ' ' + setInterSet + ' ' + setTotalTmr + ' ' + setDREvent + ' ' + setDRDeck + ' ' + timer.msToTime(setTotalTmr));
// Grab updates to countdown interval and deck size from Settings page
$('#tmrInterSet').change(function() {
setInterSet = $('#tmrInterSet').val();
tmrInterval = timer.timeToMS(setInterSet);
setTotalTmr = tmrInterval * drinitdeck;
$('#setTotTime').html(timer.msToTime(setTotalTmr));
});
$('#tmrDRDeck').change(function() {
setDRDeck = $('#tmrDRDeck').val();
drinitdeck = parseInt(setDRDeck, 10); // + parseInt(setDREvent, 10);
drnowdeck = drinitdeck;
setTotalTmr = tmrInterval * drinitdeck;
$('#setTotTime').html(timer.msToTime(setTotalTmr));
});
$('#tmrDREvent').change(function() {
setDREvent = $('#tmrDREvent').val();
drinitdeck = parseInt(setDRDeck, 10); // + parseInt(setDREvent, 10);
drnowdeck = drinitdeck;
setTotalTmr = tmrInterval * drinitdeck;
$('#setTotTime').html(timer.msToTime(setTotalTmr));
});
// Timer button controls
// Start button - shown on load, hides itself, shows pause
$('#tmrstart').on('click', function () {
timer.start();
countdown.start(tmrInterval);
$('#tmrpause').show();
$('#tmrstart').hide();
$('#setbtn').hide();
$('#tmrreset').hide();
pcInit = $('#pcOut').html();
fgInit = $('#fgOut').html();
peInit = $('#peOut').html();
trInit = $('#trOut').html();
smInit = $('#smOut').html();
var redAlert = document.getElementsByTagName("audio")[0];
redAlert.play();
});
// Pause button - hidden until start, unhides reset, toggles between self and resume
$('#tmrpause').on('click', function () {
timer.pause();
countdown.pause();
$('#tmrpause').hide();
$('#tmrresume').show();
$('#tmrreset').show();
});
// Resume button - hidden until pause, hides reset toggles between self and pause
$('#tmrresume').on('click', function () {
timer.pause();
countdown.pause();
$('#tmrresume').hide();
$('#tmrpause').show();
$('#tmrreset').hide();
});
// Reset button - resets timer to 0, hidden until pause, shows start and hides self+resume
$('#tmrreset').on('click', function () {
timer.reset();
countdown.stop();
$('#tmrdisp').html('0:00.00');
$('#tmrlap').removeClass('redtext');
$('#tmrdisp').removeClass('redtext');
$('#tmrlap').html('');
$('#gameoverdisp').hide();
$('#tmrresume').hide();
$('#tmrpause').hide();
$('#tmrreset').hide();
$('#tmrdisp').show();
$('#tmrstart').show();
$('#setbtn').show();
drnowdeck = drinitdeck;
$('#pcOut').html(pcInit);
$('#fgOut').html(fgInit);
$('#peOut').html(peInit);
$('#trOut').html(trInit);
$('#smOut').html(smInit);
$('.statusout').removeClass('css100 css90 css80 css70 css60 css50 css40 css30 css20 css10 css0');
$('#pcOut').addClass('css' + $('#pcOut').html());
$('#fgOut').addClass('css' + $('#fgOut').html());
$('#peOut').addClass('css' + $('#peOut').html());
$('#trOut').addClass('css' + $('#trOut').html());
$('#smOut').addClass('css' + $('#smOut').html());
$('.breachbtn').removeClass('redbtn');
$('div.health_container .healthBar').removeClass('greybtn').removeClass('greyText').removeClass('whiteText');
$('div.health_container .healthBar:nth-child(2)').addClass('whiteText');
hullNow = 1;
});
var countdown = Tock({
countdown : true,
interval : 10,
callback : function () {
$('#tmrcount').html(timer.msToTime(countdown.lap()));
},
complete : function () {
drnowdeck -= 1;
var drdrawcard = drinitdeck - drnowdeck;
countdown.stop();
if (drnowdeck <= 0) {
timer.stop();
$('#tmrpause').hide();
$('#tmrreset').show();
$('#tmrlap').html('');
$('#gameoverdisp').show();
$('#tmrdisp').hide();
$('#debugText').append(timer.msToTime(timer.lap()) + ' Interval ' + $('#tmrInterSet').val() + ' set ' + drdrawcard + ' of ' + drinitdeck + '<br />');
var gameOver = document.getElementsByTagName("audio")[1];
gameOver.play();
} else {
if ($('#autoDRApply').prop('checked')) {
drawCard();
}
if (drnowdeck === 1) {
$('#tmrlap').html('DAMAGE REPORT - Draw Card #' + drdrawcard + '! ' + drnowdeck + ' card remains');
$('#tmrlap').addClass('redtext');
$('#tmrdisp').addClass('redtext');
} else {
$('#tmrlap').html('DAMAGE REPORT - Draw Card #' + drdrawcard + '! ' + drnowdeck + ' cards remain');
}
$('#debugText').append(timer.msToTime(timer.lap()) + ' Interval ' + $('#tmrInterSet').val() + ' set ' + drdrawcard + ' of ' + drinitdeck + '<br />');
var redAlert = document.getElementsByTagName("audio")[0];
redAlert.play();
countdown.start(tmrInterval);
}
}
});
});
$(window).load(function(){
$('.loaderPop').hide();
$('#loaderready').show();
// $('#loaderbox').fadeOut(500);
});
$(window).resize(function () {
// Layout script, sets body to window size on resize
var bwidth = ($(window).width());
var bheight = ($(window).height());
bwidth -= 50;
bheight -= 50;
$('body').css('width', bwidth + 'px');
$('body').css('height', bheight + 'px');
});