-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiplayer.js
More file actions
1603 lines (1359 loc) · 45.1 KB
/
Copy pathmultiplayer.js
File metadata and controls
1603 lines (1359 loc) · 45.1 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
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
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var cloud_wins
var cloud_tries
var cloud_realTries
async function roomLoad() {
let name = 'default'
let opp_name = 'default_username'
// let readyToGo = 0
let roomAfree = 0
let roomBfree = 0
let roomAbutton = document.getElementById('roomA')
let roomBbutton = document.getElementById('roomB')
let pin = Math.round(Math.random() * Math.random() * 1000000)
document
.getElementById('roomA')
.addEventListener('click', async function (e) {
roomAbutton.innerHTML = 'LOADING'
roomAbutton.style.background = 'rgba(54, 79, 204, 1)'
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec',
{
method: 'POST',
body: JSON.stringify({
key: 'Room' + pin,
value: 1
})
}
)
let tutorial = document.getElementById('tutorial')
tutorial.innerHTML = ''
let text = document.createElement('p')
text =
'Room pin: ' +
pin +
'. Get your friend to join with the room pin! Enter your name: '
tutorial.append(text)
let input = document.createElement('input')
input.id = 'inputBox3'
// input.innerHTML = 'Name'
tutorial.append(input)
let ready = document.createElement('button')
ready.innerHTML = 'Ready Up!'
ready.classList.add('room')
ready.id = 'ready'
tutorial.append(ready)
document
.getElementById('ready')
.addEventListener('click', async function (e) {
name = document.getElementById('inputBox3').value
console.log(name)
let tutorial = document.getElementById('tutorial')
tutorial.innerHTML = ''
let text = document.createElement('p')
text =
'Room pin: ' +
pin +
'. Get your friend to join with the room pin. ' +
name +
' is a cool name! Waiting for another player...'
tutorial.append(text)
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec',
{
method: 'POST',
body: JSON.stringify({
key: 'Room' + pin + ' host name',
value: name
})
}
)
})
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec?key=Room' +
pin
)
.then(res => res.text())
.then(value => {
roomAfree = Number(value)
console.log(roomAfree)
})
while (roomAfree == 1) {
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec?key=Room' +
pin
)
.then(res => res.text())
.then(value => {
roomAfree = Number(value)
console.log(roomAfree)
})
}
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec?key=Room' +
pin +
' opponent name'
)
.then(res => res.text())
.then(value => {
opp_name = value
console.log(opp_name)
})
tutorial.innerHTML = ''
text =
'Success! ' + opp_name + ' has joined your room! Ready when you are...'
tutorial.append(text)
ready.innerHTML = 'Start match!'
ready.classList.add('room')
ready.id = 'ready5'
tutorial.append(ready)
document.getElementById('ready5').addEventListener('click', async function (e) {
ready.innerHTML = 'LOADING'
ready.style.background = 'rgba(54, 79, 204, 1)'
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec',
{
method: 'POST',
body: JSON.stringify({
key: 'Room' + pin,
value: 3
})
}
)
startGameMultiplayer(opp_name, pin)
})
})
document
.getElementById('roomB')
.addEventListener('click', async function (e) {
let tutorial = document.getElementById('tutorial')
tutorial.innerHTML = ''
let text = document.createElement('p')
text = 'Enter in your pin: '
tutorial.append(text)
let input = document.createElement('input')
input.id = 'inputBox2'
// input.innerHTML = 'Name'
tutorial.append(input)
let ready = document.createElement('button')
ready.innerHTML = 'Connect'
ready.classList.add('room')
ready.id = 'ready2'
tutorial.append(ready)
let connection_pin = 0
document
.getElementById('ready2')
.addEventListener('click', async function (e) {
ready.innerHTML = 'LOADING'
ready.style.background = 'rgba(54, 79, 204, 1)'
connection_pin = document.getElementById('inputBox2').value
console.log(connection_pin)
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec?key=Room' +
connection_pin
)
.then(res => res.text())
.then(value => {
roomAfree = Number(value)
console.log(roomAfree)
})
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec?key=Room' +
connection_pin +
' host name'
)
.then(res => res.text())
.then(value => {
opp_name = value
console.log(opp_name)
})
if (roomAfree == 1) {
let tutorial = document.getElementById('tutorial')
tutorial.innerHTML = ''
let text = document.createElement('p')
text =
'Connection successful to ' +
opp_name +
"'s room! Set your name: "
tutorial.append(text)
let input = document.createElement('input')
input.id = 'inputBox2'
tutorial.append(input)
let ready = document.createElement('button')
ready.innerHTML = 'Ready up!'
ready.classList.add('room')
ready.id = 'ready6'
tutorial.append(ready)
document
.getElementById('ready6')
.addEventListener('click', async function (e) {
name = document.getElementById('inputBox2').value
console.log(name);
let tutorial = document.getElementById('tutorial')
tutorial.innerHTML = ''
let text = document.createElement('p')
text =
'Okay, ' +
name +
". Waiting for host to start match... "
tutorial.append(text)
// ready.innerHTML = 'LOADING'
// ready.style.background = rgba(54, 79, 204, 1)
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec',
{
method: 'POST',
body: JSON.stringify({
key: 'Room' + connection_pin + ' opponent name',
value: name
})
}
)
console.log('name posted')
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec',
{
method: 'POST',
body: JSON.stringify({
key: 'Room' + connection_pin,
value: 2
})
}
)
roomAfree = 2
console.log('room ready')
while (roomAfree == 2) {
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec?key=Room' +
connection_pin
)
.then(res => res.text())
.then(value => {
roomAfree = Number(value)
console.log(roomAfree)
})
}
startGameMultiplayerB(opp_name, connection_pin)
})
}
else {
let tutorial = document.getElementById('tutorial')
tutorial.innerHTML = ''
let text = document.createElement('p')
text = 'Invalid pin'
tutorial.append(text)
let ready = document.createElement('button')
ready.innerHTML = 'Reload page'
ready.classList.add('room')
ready.id = 'ready7'
tutorial.append(ready)
document
.getElementById('ready7')
.addEventListener('click', async function (e) {
window.location.href = 'multiplayer.html'
})
}
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec',
{
method: 'POST',
body: JSON.stringify({
key: 'Room' + pin + ' host name',
value: name
})
}
)
})
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec?key=Room' +
pin
)
.then(res => res.text())
.then(value => {
roomAfree = Number(value)
console.log(roomAfree)
})
while (roomAfree < 2) {
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec?key=Room' +
pin
)
.then(res => res.text())
.then(value => {
roomAfree = Number(value)
console.log(roomAfree)
})
}
console.log('ready!')
})
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec?key=RoomA'
)
.then(res => res.text())
.then(value => {
roomAfree = Number(value)
console.log('Room A: ', value)
})
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec?key=RoomB'
)
.then(res => res.text())
.then(value => {
roomBfree = Number(value)
console.log('Room B: ', value)
})
if (roomAfree < 2) {
if (roomAfree == 1) {
roomAbutton.innerHTML = 'Room A: 1/2'
} else {
roomAbutton.innerHTML = 'Room A: 0/2'
}
} else {
roomAbutton.style.pointerEvents = 'none'
roomAbutton.style.backgroundColor = 'red'
roomAbutton.innerHTML = 'Room A: FULL'
}
if (roomBfree < 2) {
if (roomBfree == 1) {
roomBbutton.innerHTML = 'Room B: 1/2'
} else {
roomBbutton.innerHTML = 'Room B: 0/2'
}
} else {
roomBbutton.style.pointerEvents = 'none'
roomBbutton.style.backgroundColor = 'red'
roomBbutton.innerHTML = 'Room B: FULL'
}
// document
// .getElementById('roomA')
// .addEventListener('click', async function (e) {
// await fetch(
// 'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec',
// {
// method: 'POST',
// body: JSON.stringify({
// key: 'RoomA',
// value: roomAfree + 1
// })
// }
// )
// roomLoadA()
// })
// document
// .getElementById('roomB')
// .addEventListener('click', async function (e) {
// await fetch(
// 'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec',
// {
// method: 'POST',
// body: JSON.stringify({
// key: 'RoomB',
// value: roomBfree + 1
// })
// }
// )
// roomLoadB()
// })
}
async function startGameMultiplayer(opp_name, pin) {
let tutorial = document.getElementById('tutorial')
tutorial.remove()
let parent2 = document.getElementById('bot-box')
let actual = document.createElement('p')
actual.textContent = opp_name + "'s cash: $60"
actual.setAttribute('id', 'quote')
parent2.appendChild(actual)
let cBox = document.createElement('div')
cBox.setAttribute('id', 'content2')
cBox.innerHTML = ''
active = [] // reset
let content = document.getElementById('content')
content.innerHTML = ''
let rutton = document.createElement('div')
rutton.setAttribute('id', 'rutton')
content.append(rutton)
content.append(cBox)
let buttonRow = document.getElementById('rutton')
let play = document.createElement('button')
play.innerText = 'Play'
play.setAttribute('id', 'play-card')
play.classList.add('play-btn')
let shuffle = document.createElement('button')
shuffle.innerText = 'Shuffle'
shuffle.setAttribute('id', 'shuffle')
shuffle.classList.add('play-btn')
let sell = document.createElement('button')
sell.innerText = 'Sell'
sell.setAttribute('id', 'sell')
sell.classList.add('play-btn')
pointTotal()
draw5(cBox)
buttonRow.append(play)
buttonRow.append(sell)
buttonRow.append(shuffle)
document.getElementById('play-card').addEventListener('click', function (e) {
if (active.length != 0) {
document.getElementById('play-card').style.visibility = 'hidden'
let user_val = active[active.length - 1].innerText.split(' ')
let card_val_user = card_val(user_val[0])
playCardMultiA(active[active.length - 1].innerText, pin)
}
})
document.getElementById('shuffle').addEventListener('click', function (e) {
document.getElementById('content2').innerHTML = ''
points = points - 5
pointTotal()
draw5(cBox)
})
document.getElementById('sell').addEventListener('click', function (e) {
sellCard(active[active.length - 1])
})
}
async function startGameMultiplayerB(opp_name, pin) {
let tutorial = document.getElementById('tutorial')
tutorial.remove()
let parent2 = document.getElementById('bot-box')
let actual = document.createElement('p')
actual.textContent = opp_name + "'s cash: $60"
actual.setAttribute('id', 'quote')
parent2.appendChild(actual)
let cBox = document.createElement('div')
cBox.setAttribute('id', 'content2')
cBox.innerHTML = ''
active = [] // reset
let content = document.getElementById('content')
content.innerHTML = ''
let rutton = document.createElement('div')
rutton.setAttribute('id', 'rutton')
content.append(rutton)
content.append(cBox)
let buttonRow = document.getElementById('rutton')
let play = document.createElement('button')
play.innerText = 'Play'
play.setAttribute('id', 'play-card')
play.classList.add('play-btn')
let shuffle = document.createElement('button')
shuffle.innerText = 'Shuffle'
shuffle.setAttribute('id', 'shuffle')
shuffle.classList.add('play-btn')
let sell = document.createElement('button')
sell.innerText = 'Sell'
sell.setAttribute('id', 'sell')
sell.classList.add('play-btn')
pointTotal()
draw5(cBox)
buttonRow.append(play)
buttonRow.append(sell)
buttonRow.append(shuffle)
document.getElementById('play-card').addEventListener('click', function (e) {
if (active.length != 0) {
document.getElementById('play-card').style.visibility = 'hidden'
let user_val = active[active.length - 1].innerText.split(' ')
let card_val_user = card_val(user_val[0])
playCardMultiB(active[active.length - 1].innerText, pin)
}
})
document.getElementById('shuffle').addEventListener('click', function (e) {
document.getElementById('content2').innerHTML = ''
points = points - 5
pointTotal()
draw5(cBox)
})
document.getElementById('sell').addEventListener('click', function (e) {
sellCard(active[active.length - 1])
})
}
async function roomLoad2() {
let roomAbutton = document.getElementById('roomA')
let roomBbutton = document.getElementById('roomB')
let roomAfree = 0
let roomBfree = 0
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec?key=RoomA'
)
.then(res => res.text())
.then(value => {
roomAfree = Number(value)
console.log('Room A: ', value)
})
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec?key=RoomB'
)
.then(res => res.text())
.then(value => {
roomBfree = Number(value)
console.log('Room B: ', value)
})
if (roomAfree < 2) {
if (roomAfree == 1) {
roomAbutton.innerHTML = 'Room A: 1/2'
} else {
roomAbutton.innerHTML = 'Room A: 0/2'
}
} else {
roomAbutton.style.pointerEvents = 'none'
roomAbutton.style.backgroundColor = 'red'
roomAbutton.innerHTML = 'Room A: FULL'
}
if (roomBfree < 2) {
if (roomBfree == 1) {
roomBbutton.innerHTML = 'Room B: 1/2'
} else {
roomBbutton.innerHTML = 'Room B: 0/2'
}
} else {
roomBbutton.style.pointerEvents = 'none'
roomBbutton.style.backgroundColor = 'red'
roomBbutton.innerHTML = 'Room B: FULL'
}
document
.getElementById('roomA')
.addEventListener('click', async function (e) {
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec',
{
method: 'POST',
body: JSON.stringify({
key: 'RoomA',
value: roomAfree + 1
})
}
)
roomLoadA()
})
document
.getElementById('roomB')
.addEventListener('click', async function (e) {
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec',
{
method: 'POST',
body: JSON.stringify({
key: 'RoomB',
value: roomBfree + 1
})
}
)
roomLoadB()
})
}
async function getCloudWins() {
let mainTitle = document.getElementById('main-title')
let mainText = document.createElement('p')
let global = 'Global win percentage: Loading...'
mainText.innerHTML = global
mainTitle.append(mainText)
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec?key=Wins'
)
.then(res => res.text())
.then(value => {
cloud_wins = Number(value)
console.log('Cloud wins:', value)
})
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec?key=Tries'
)
.then(res => res.text())
.then(value => {
cloud_tries = Number(value)
console.log('Cloud tries:', value)
})
// let mainTitle = document.getElementById('main-title')
// let mainText = document.createElement('p')
global =
'Global win percentage: ' +
Math.round((cloud_wins / cloud_tries) * 1000) / 10 +
'%'
mainText.innerHTML = global
mainTitle.append(mainText)
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec',
{
method: 'POST',
body: JSON.stringify({
key: 'Try ' + cloud_realTries + ' accessed',
value: new Date().toLocaleString()
})
}
)
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec?key=Tries'
)
.then(res => res.text())
.then(value => {
cloud_realTries = Number(value)
console.log('Real tries:', value)
})
await fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec',
{
method: 'POST',
body: JSON.stringify({
key: 'RealTries',
value: cloud_realTries + 1
})
}
)
}
window.onload = function () {
// getCloudWins();
roomLoad()
}
let quotes = [
'If you’re offered a seat on a rocket ship, don’t ask what seat! Just get on. Sheryl Sandberg',
'First, have a definite, clear practical ideal; a goal, an objective. Second, have the necessary means to achieve your ends; wisdom, money, materials, and methods. Third, adjust all your means to that end. Aristotle',
'If the wind will not serve, take to the oars. Latin Proverb',
'You can’t fall if you don’t climb. But there’s no joy in living your whole life on the ground. Unknown',
'We must believe that we are gifted for something, and that this thing, at whatever cost, must be attained. Marie Curie',
'Too many of us are not living our dreams because we are living our fears. Les Brown',
'Challenges are what make life interesting and overcoming them is what makes life meaningful. Joshua J. Marine',
'If you want to lift yourself up, lift up someone else. Booker T. Washington',
'I have been impressed with the urgency of doing. Knowing is not enough; we must apply. Being willing is not enough; we must do. Leonardo da Vinci',
'Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. Jamie Paolinetti',
'You take your life in your own hands, and what happens? A terrible thing, no one to blame. Erica Jong',
'What’s money? A man is a success if he gets up in the morning and goes to bed at night and in between does what he wants to do. Bob Dylan',
'I didn’t fail the test. I just found 100 ways to do it wrong. Benjamin Franklin',
'In order to succeed, your desire for success should be greater than your fear of failure. Bill Cosby',
'A person who never made a mistake never tried anything new. Albert Einstein',
'The person who says it cannot be done should not interrupt the person who is doing it. Chinese Proverb',
'There are no traffic jams along the extra mile. Roger Staubach',
'It is never too late to be what you might have been. George Eliot',
'You become what you believe. Oprah Winfrey',
'I would rather die of passion than of boredom. Vincent van Gogh',
'A truly rich man is one whose children run into his arms when his hands are empty. Unknown',
'It is not what you do for your children, but what you have taught them to do for themselves, that will make them successful human beings. Ann Landers',
'If you want your children to turn out well, spend twice as much time with them, and half as much money. Abigail Van Buren',
'Build your own dreams, or someone else will hire you to build theirs. Farrah Gray',
'The battles that count aren’t the ones for gold medals. The struggles within yourself–the invisible battles inside all of us–that’s where it’s at. Jesse Owens',
'Education costs money. But then so does ignorance. Sir Claus Moser',
'I have learned over the years that when one’s mind is made up, this diminishes fear. Rosa Parks',
'It does not matter how slowly you go as long as you do not stop. Confucius',
'If you look at what you have in life, you’ll always have more. If you look at what you don’t have in life, you’ll never have enough. Oprah Winfrey',
'Remember that not getting what you want is sometimes a wonderful stroke of luck. Dalai Lama',
'You can’t use up creativity. The more you use, the more you have. Maya Angelou',
'Dream big and dare to fail. Norman Vaughan',
'Our lives begin to end the day we become silent about things that matter. Martin Luther King Jr.',
'Do what you can, where you are, with what you have. Teddy Roosevelt',
'If you do what you’ve always done, you’ll get what you’ve always gotten. Tony Robbins',
'Dreaming, after all, is a form of planning. Gloria Steinem',
'It’s your place in the world; it’s your life. Go on and do all you can with it, and make it the life you want to live. Mae Jemison',
'You may be disappointed if you fail, but you are doomed if you don’t try. Beverly Sills',
'Remember no one can make you feel inferior without your consent. Eleanor Roosevelt',
'Life is what we make it, always has been, always will be. Grandma Moses',
'The question isn’t who is going to let me; it’s who is going to stop me. Ayn Rand',
'When everything seems to be going against you, remember that the airplane takes off against the wind, not with it. Henry Ford',
'It’s not the years in your life that count. It’s the life in your years. Abraham Lincoln',
'Change your thoughts and you change your world. Norman Vincent Peale',
'Either write something worth reading or do something worth writing. Benjamin Franklin',
'Nothing is impossible, the word itself says, “I’m possible!” –Audrey Hepburn',
'The only way to do great work is to love what you do. Steve Jobs',
'If you can dream it, you can achieve it. Zig Ziglar'
]
// function randomQuote() {
// let parent2 = document.getElementById('bot-box')
// let randomInt = Math.floor(Math.random() * 47)
// let actual = document.createElement('p')
// actual.textContent = quotes[randomInt]
// actual.setAttribute('id', 'quote')
// parent2.appendChild(actual)
// }
function startGame() {
let tut = document.getElementById('tutorial')
tut.style.visibility = 'hidden'
}
const deck = []
const suits = ['Hearts', 'Diamonds', 'Clubs', 'Spades']
const values = [
'Ace',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'10',
'Jack',
'Queen',
'King'
]
suits.forEach(suit => {
values.forEach(value => {
deck.push({ value, suit })
})
})
function createDeck() {
return suits.flatMap(suit => values.map(value => ({ value, suit })))
}
const myDeck = createDeck()
function shuffleDeck(deck) {
for (let i = deck.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1))
;[deck[i], deck[j]] = [deck[j], deck[i]]
}
return deck
}
shuffleDeck(myDeck)
function drawCard(deck) {
return deck.pop()
}
const myCard = drawCard(myDeck)
function displayDeck(deck) {
const deckElement = document.createElement('div')
deck.forEach(card => {
const cardElement = document.createElement('div')
cardElement.className = 'card'
cardElement.innerText = `${card.value} of ${card.suit}`
deckElement.appendChild(cardElement)
})
document.body.appendChild(deckElement)
}
function draw5(cBox) {
for (let i = 0; i < 5; i++) {
let card1 = document.createElement('button')
card1.classList.add('card')
const myDeck2 = createDeck()
shuffleDeck(myDeck2)
const myCard2 = drawCard(myDeck2)
myCard2.id = `${myCard2.value} / ${myCard2.suit}`
console.log(myCard2.id)
console.log(myCard2)
let cardString = `${myCard2.value} of ${myCard2.suit}`
card1.textContent = cardString
// switch (myCard2.suit) {
// case 'Hearts' || 'Diamonds':
// card1.classList.add('card-red')
// break
// case 'Spades' || 'Clubs':
// card1.classList.add('card-black')
// break
// case 'Clubs':
// card1.classList.add('card-black')
// break
// default:
// card1.classList.add('card-red')
// break
// }
if (myCard2.suit === 'Hearts' || myCard2.suit === 'Diamonds') {
card1.classList.add('card-red')
} else {
card1.classList.add('card-black')
}
console.log(myCard2.suit + card1.className)
cBox.appendChild(card1)
}
}
function draw1(suit) {
switch (suit) {
case 0:
return 'Heart'
case 1:
return 'Spade'
case 2:
return 'Club'
case 3:
return 'Diamond'
default:
return 'Heart'
}
}
function card_val(card) {
switch (card) {
case 'Jack':
return 11
case 'Queen':
return 12
case 'King':
return 13
case 'Ace':
return 20
default:
return card
}
}
function card_val_opp(card) {
switch (card) {
case 10:
return 'Jack'
case 11:
return 'Queen'
case 12:
return 'King'
case 13:
return 'Ace'
default:
return card
}
}
function win_game(did) {
console.log(did)
let content = document.getElementById('content')
content.innerHTML = ''
let rutton = document.createElement('div')
rutton.setAttribute('id', 'rutton')
content.append(rutton)
let text = document.createElement('p')
let title = document.getElementById('placeholder2')
title.innerText = 'The Results:'
let play_again = document.createElement('button')
play_again.innerText = 'Play again'
play_again.setAttribute('id', 'play-card')
play_again.classList.add('play-btn')
const newButton = document.createElement('button')
newButton.classList.add('play-btn')
newButton.setAttribute('id', 'copyButton')
newButton.innerHTML = 'Copy Results'
let did2 = did
console.log(did2)
if (did2 == 1) {
fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec',
{
method: 'POST',
body: JSON.stringify({
key: 'Wins',
value: cloud_wins + 1
})
}
)
fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec',
{
method: 'POST',
body: JSON.stringify({
key: 'Tries',
value: cloud_tries + 1
})
}
)
text.innerText = 'You won Card Tennis!'
content.append(text)
document.getElementById('content').appendChild(newButton)
content.append(play_again)
} else {
fetch(
'https://script.google.com/macros/s/AKfycbzX0DmUX_b5BTwMkrV3BleUkUHqtIECeiaNXq46Orn5wUmZnPNqkUTaAs2qo8VfJs6eoA/exec',
{
method: 'POST',
body: JSON.stringify({
key: 'Tries',
value: cloud_tries + 1
})
}
)
text.innerText = 'You lost but keep trying!'
content.append(text)
document.getElementById('content').appendChild(newButton)
content.append(play_again)
}
// switch (did2) {
// case 0:
// text.innerText = 'You lost but keep trying!'
// content.append(text)
// document.getElementById('content').appendChild(newButton)
// content.append(play_again)
// case 1:
// text.innerText = 'You won Card Tennis!'
// content.append(text)
// document.getElementById('content').appendChild(newButton)
// content.append(play_again)
// default:
// text.innerText = 'You lost but keep trying!'
// content.append(text)
// document.getElementById('content').appendChild(newButton)
// content.append(play_again)
// }
newButton.addEventListener('click', () => {