-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetV.html
More file actions
1846 lines (1682 loc) · 62.8 KB
/
setV.html
File metadata and controls
1846 lines (1682 loc) · 62.8 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
<!DOCTYPE html> <html> <body>
<canvas id = "ctx" width="480" height="640" style="border:1px solid #000000;"></canvas>
<script>
// Variable declarations
var mouse = {
x:undefined,
y:undefined
}
// Portrait mode include this file
var cardGrid = {
cardWidth:80,
cardLength:120,
col1x:25,
col2x:125,
col3x:225,
col4x:325,
row1y:50,
row2y:190,
row3y:330,
padxy:2,
padwl:4,
padx:15,
pos1:35,
pos2:45,
pos3:65,
pos4:80,
pos5:95
};
var cardsRemaining = 69;
//SFXs
{
var selectCardSFX = new Audio();
selectCardSFX.src = 'resources/SFX/selectCard.mp3';
var deselectCardSFX = new Audio();
deselectCardSFX.src = 'resources/SFX/deselectCard.mp3';
var selectCardFullSFX = new Audio();
selectCardFullSFX.src = 'resources/SFX/selectCardFull.mp3';
var submitCardsSFX = new Audio();
submitCardsSFX.src = 'resources/SFX/submitCards.mp3';
var submitCardsRejectSFX = new Audio();
submitCardsRejectSFX.src = 'resources/SFX/submitCardsReject.mp3';
var timer2SFX = new Audio();
timer2SFX.src = 'resources/SFX/timer2.mp3';
var timer0SFX = new Audio();
timer0SFX.src = 'resources/SFX/timer0.mp3';
var newCardsSFX = new Audio();
newCardsSFX.src = 'resources/SFX/newCards.mp3';
var hintSFX = new Audio();
hintSFX.src = 'resources/SFX/hint.mp3';
var clearCardsSFX = new Audio();
clearCardsSFX.src = 'resources/SFX/clearCards.mp3';
var gameOverWinSFX = new Audio();
gameOverWinSFX.src = 'resources/SFX/gameOverWin.mp3';
// not using this one right now.
var gameOverTimeEndsSFX = new Audio();
gameOverTimeEndsSFX.src = 'resources/SFX/gameOverTimeEnds.mp3';
// end SFX
// BackGround Music
var backgroundMusic1 = new Audio();
backgroundMusic1.src = 'resources/SFX/backgroundMusic1.mp3';
var backgroundMusic2 = new Audio();
backgroundMusic2.src = 'resources/SFX/backgroundMusic2.mp3';
}
//background music looping
backgroundMusic2.addEventListener('ended', function() {
this.currentTime = 0;
this.play();
}, false);
backgroundMusic2.loop = true;
backgroundMusic2.play();
backgroundMusic2.volume = .5;
var gameControls = {
timer:60,
gameOver:false,
hintUsed:false,
timesUp:false,
gamePaused:false,
sfxOn: true
};
var uiElements = {
bannerX:100,
bannerY:10,
bannerW:240,
bannerL:25,
bannerTextX:110,
bannerTextY:27,
bannerText:"Select 3 cards to make a match",
scoreX:25,
scoreY:10,
scoreW:60,
scoreL:25,
scoreTextX:40,
scoreTextY:29,
scoreText:0,
timerX:350,
timerY:10,
timerW:60,
timerL:25,
timerTextX:370,
timerTextY:29,
timerText:60,
quitButtonX:440,
quitButtonY:10,
quitButtonW:20,
quitButtonL:20,
quitButtonTextX:446,
quitButtonTextY:25,
submitButtonX:25,
submitButtonY:550,
submitButtonW:105,
submitButtonL:50,
submitButtonTextX:40,
submitButtonTextY:580,
hintButtonX:165,
hintButtonY:480,
hintButtonW:105,
hintButtonL:50,
hintButtonTextX:200,
hintButtonTextY:510,
settingsButtonX:165,
settingsButtonY:550,
settingsButtonW:105,
settingsButtonL:50,
settingsButtonTextX:180,
settingsButtonTextY:580,
sfxButtonHeaderTextX:130,
sfxButtonHeaderTextY:400,
sfxButtonOnX:150,
sfxButtonOnY:410,
sfxButtonOnW:60,
sfxButtonOnL:60,
sfxButtonOnTextX:160,
sfxButtonOnTextY:450,
sfxButtonOffX:250,
sfxButtonOffY:410,
sfxButtonOffW:60,
sfxButtonOffL:60,
sfxButtonOffTextX:257,
sfxButtonOffTextY:450,
clearSelectionButtonX:25,
clearSelectionButtonY:480,
clearSelectionButtonW:105,
clearSelectionButtonL:50,
clearSelectionButtonTextX:30,
clearSelectionButtonTextY:510,
rulesX:80,
rulesY:60,
rulesW:300,
rulesL:550,
rulesLine1X:160,
rulesLine1Y:100,
returnButtonX:150,
returnButtonY:500,
returnButtonW:160,
returnButtonL:50,
returnButtonTextX:165,
returnButtonTextY:530,
reloadButtonX:120,
reloadButtonY:360,
reloadButtonW:240,
reloadButtonL:60,
reloadButtonTextX:150,
reloadButtonTextY:400,
pad:5
};
var selected = {
card1:false,
card2:false,
card3:false,
card4:false,
card5:false,
card6:false,
card7:false,
card8:false,
card9:false,
card10:false,
card11:false,
card12:false,
full:0
};
var displayed = {
card1: true,
card2: true,
card3: true,
card4: true,
card5: true,
card6: true,
card7: true,
card8: true,
card9: true,
card10:true,
card11:true,
card12:true,
hint: true,
submit: true,
deck: true,
clearSubmit: true,
settings: true,
banner: true,
timer: true,
returnButton: false,
oneMore: false,
sfxButtons: false
};
var hint = {
card1: false,
card2: false,
card3: false,
card4: false,
card5: false,
card6: false,
card7: false,
card8: false,
card9: false,
card10:false,
card11:false,
card12:false,
};
// drawDeck has a lot of UI x/y coordinates in it
drawDeck = function () {
drawBottom = function () {
//Deck three (bottom)
XG.fillRect(380, 488, 80, 120);
// fill.Rect(x, y, w, h)
// clear.Rect(+2, +2, -4, -4)
XG.clearRect(382, 490, 76, 116);
};
drawMiddle = function () {
//Deck two (middle)
// fill.Rect (x-6, y-6, w, h)
XG.fillRect(374, 482, 80, 120);
XG.clearRect(376, 484, 76, 116);
};
drawTop = function () {
//Deck one (top)
XG.fillRect(368, 476, 80, 120);
XG.clearRect(370, 478, 76 , 116);
};
if (displayed.deck === true) {
var XG = document.getElementById("ctx").getContext("2d");
var deckTextLine1x = 375;
var deckTextLine1y = 520;
var deckTextLine2x = 375;
var deckTextLine2y = 540;
var deckTextLine3x = 395;
var deckTextLine3y = 580;
XG.beginPath();
if (playDeck.length >= 42) {
drawBottom();
drawMiddle();
drawTop();
} else if (playDeck.length >= 21) {
XG.clearRect(368, 476, 92, 132);
XG.stroke;
drawBottom();
drawMiddle();
deckTextLine1x = deckTextLine1x + 4;
deckTextLine2x = deckTextLine2x + 4;
deckTextLine3x = deckTextLine3x + 4;
} else {
XG.clearRect(368, 476, 92, 132);
XG.stroke;
drawBottom();
deckTextLine1x = deckTextLine1x + 9;
deckTextLine2x = deckTextLine2x + 9;
if (playDeck.length > 9) {
deckTextLine3x = deckTextLine3x + 10;
} else {
deckTextLine3x = deckTextLine3x + 15;
}
}
XG.font="14px Arial";
XG.fillText("Draw Deck", deckTextLine1x, deckTextLine1y);
XG.fillText("Cards Left:", deckTextLine2x, deckTextLine2y);
XG.fillStyle = 'red';
XG.font="24px Arial";
XG.fillText(cardsRemaining, deckTextLine3x, deckTextLine3y)
XG.stroke();
XG.font="14px Arial";
XG.fillStyle = "black";
XG.closePath();
};
};
endGame = function () {
gameOverWinSFX.play();
for (let i=1; i<13; i++){
let endgame = "card" + (i);
hint[endgame] = false;
selected[endgame] = false;
selected.full = 0;
displayed[endgame] = false;
};
displayed.hint = false;
displayed.submit = false;
displayed.clearSubmit = false;
displayed.deck = false;
displayed.settings = false;
//displayed.timer = false;
displayed.oneMore = true;
uiElements.bannerText = " Play Again!!";
let CTXG = document.getElementById("ctx").getContext("2d");
CTXG.beginPath();
CTXG.clearRect(10, 45, 460, 585);
CTXG.stroke();
CTXG.closePath();
CTXG.beginPath();
CTXG.fillRect(10, 45, 460, 560);
CTXG.font="30px Arial";
CTXG.fillStyle = "white";
CTXG.fillText("GAME OVER!!", 150, 100 );
CTXG.stroke();
CTXG.fillStyle = "black";
CTXG.fillRect(10, 200, 460, 560);
CTXG.lineWidth = "10";
CTXG.strokeStyle = "green";
CTXG.rect(uiElements.reloadButtonX, uiElements.reloadButtonY, uiElements.reloadButtonW, uiElements.reloadButtonL);
CTXG.stroke();
CTXG.closePath();
CTXG.beginPath();
CTXG.font="24px Arial";
CTXG.fillStyle = "white";
CTXG.fillText("Another Round?", uiElements.reloadButtonTextX, uiElements.reloadButtonTextY );
CTXG.stroke();
CTXG.closePath();
//One More Game? Button
gameControls.gameOver = true;
};
// End Variable declaration
// Begin Functions
window.addEventListener("click", function(event) {
mouse.x = event.x,
mouse.y = event.y
var width = 80;
var length = 120;
console.log("Refresh triggered. Game Over === " + gameControls.gameOver);
submitButton(mouse.x, mouse.y, playSurface);
quitButton(mouse.x, mouse.y);
clearSelectionButton(mouse.x, mouse.y);
settingsButton(mouse.x, mouse.y);
//if(displayed.returnButton === true){
// returnButton(mouse.x, mouse.y);
//}
whichCards(mouse.x, mouse.y, width, length);
//if there is a click fire off all these functions which represent all off the selectable
// elements in the game
cardOne();
cardTwo();
cardThree();
cardFour();
cardFive();
cardSix();
cardSeven();
cardEight();
cardNine();
cardTen();
cardEleven();
cardTwelve();
hintButton(mouse.x, mouse.y);
drawDeck();
drawBanner();
if (displayed.oneMore === true) {
reloadGame(mouse.x,mouse.y);
}
if (displayed.returnButton === true) {
returnButton(mouse.x, mouse.y);
}
});
window.addEventListener("touchstart", function(event) {
var touchobj = event.changedTouches[0]
touch.x = parseInt(touchobj.clientX);
touch.y = parseInt(touchobj.clientY);
var width = 80;
var length = 120;
console.log("Refresh triggered. Game Over === " + gameControls.gameOver);
submitButton(touch.x, touch.y, playSurface);
quitButton(touch.x, touch.y);
clearSelectionButton(touch.x, touch.y);
settingsButton(touch.x, touch.y);
//if(displayed.returnButton === true){
// returnButton(touch.x, touch.y);
//}
whichCards(touch.x, touch.y, width, length);
//if there is a click fire off all these functions which represent all off the selectable
// elements in the game
cardOne();
cardTwo();
cardThree();
cardFour();
cardFive();
cardSix();
cardSeven();
cardEight();
cardNine();
cardTen();
cardEleven();
cardTwelve();
hintButton(touch.x, touch.y);
drawDeck();
drawBanner();
if (displayed.oneMore === true) {
reloadGame(touch.x,touch.y);
}
if (displayed.returnButton === true) {
returnButton(touch.x, touch.y);
}
});
score = function () {
var SCORE = document.getElementById("ctx").getContext("2d");
SCORE.beginPath();
SCORE.clearRect(uiElements.scoreX, uiElements.scoreY, uiElements.scoreW, uiElements.scoreL);
SCORE.strokeStyle="black";
SCORE.lineWidth=4;
SCORE.rect(uiElements.scoreX, uiElements.scoreY, uiElements.scoreW, uiElements.scoreL);
SCORE.font="20px Arial";
SCORE.fillStyle="green";
if (uiElements.scoreText === 0) {
SCORE.fillText(uiElements.scoreText, uiElements.scoreTextX + 10 , uiElements.scoreTextY);
} else if (uiElements.scoreText < 999){;
SCORE.fillText(uiElements.scoreText, uiElements.scoreTextX , uiElements.scoreTextY);
} else {
SCORE.fillText(uiElements.scoreText, uiElements.scoreTextX - 3 , uiElements.scoreTextY);
};
SCORE.stroke();
SCORE.fillStyle="black";
SCORE.closePath();
};
timer = function () {
if (displayed.timer === true) {
var TIMER = document.getElementById("ctx").getContext("2d");
TIMER.beginPath();
TIMER.clearRect(uiElements.timerX, uiElements.timerY, uiElements.timerW, uiElements.timerL);
TIMER.stroke();
TIMER.closePath();
TIMER.beginPath();
TIMER.arc(uiElements.timerTextX +10, uiElements.timerTextY - 5, 17, 0, 2 * Math.PI, false);
TIMER.fillStyle = 'white';
TIMER.fill();
TIMER.lineWidth = 3;
TIMER.strokeStyle = 'black';
TIMER.stroke();
TIMER.font="20px Arial";
TIMER.fillStyle = 'red';
if (gameControls.gameOver === false) {
if (uiElements.timerText > 9) {
TIMER.fillText(uiElements.timerText, uiElements.timerTextX - 1, uiElements.timerTextY);
} else {
TIMER.fillText(uiElements.timerText, uiElements.timerTextX + 5, uiElements.timerTextY);
}
} else {
TIMER.fillText("", uiElements.timerTextX, uiElements.timerTextY);
};
TIMER.stroke();
TIMER.fillStyle = 'black';
TIMER.closePath();
if (uiElements.timerText === 3) {
timer2SFX.play();
timer2SFX.volume = .5;
}
if (uiElements.timerText === 0) {
timer0SFX.play();
timer0SFX.volume = .5;
}
}
};
updateTimer = function () {
console.log("timer started");
if (gameControls.gamePaused === false){
if (gameControls.timer === 0) {
gameControls.timer = 60;
gameControls.timesUp = true;
removeCards();
}
if (gameControls.gameOver === false && gameControls.gamePaused === false) {
var countdownTimer = setInterval(function(){
if (gameControls.gamePaused === false) {
gameControls.timer --;
}
uiElements.timerText = gameControls.timer;
timer();
if (gameControls.timer <= 0 && gameControls.gameOver === false && gameControls.gamePaused === false){
clearInterval(countdownTimer);
if (gameControls.gamePaused === false) {
updateTimer();
}
}
},1000);
}
}
}
updateScore = function () {
var scoreToAdd = 100;
var scoreTemp = 0;
var finalScore = 0;
if (gameControls.hintUsed === true) {
scoreToAdd = 50;
};
if (gameControls.timesUp === true) {
scoreToAdd = 0;
};
scoreToAdd = scoreToAdd + uiElements.timerText;
uiElements.bannerText = scoreToAdd;
scoreTemp = uiElements.scoreText;
finalScore = scoreToAdd + scoreTemp;
uiElements.scoreText = finalScore;
score();
gameControls.timesUp = false;
console.log("Score: " + scoreToAdd + " hint used? " + gameControls.hintUsed + " Time's Up? " + gameControls.timesUp);
};
// creating a deck of cards based on these four different characteristics or suits.
createDeck = function () {
var symbol = [ "diamond", "squiggle", "oval"];
var color = [ "red", "green", "purple"];
var shading = [ "solid", "striped", "open"];
var quantity = [ 1, 2, 3];
// needed for each of the loops. Each for loop is like a power multiplier in this case 3 to the 4th power or 81 loops
// Leaving these in and commented out as I will be porting this to other scripting languages.
//var i = 0; For the symbols on the card
//var j = 0; For the color of the symbols on the card
//var k = 0; For the shading of the symbols on the card
//var l = 0; For the quantity of symbols on the card
// Creating the deck <Start> ------------------------------------------------------------
// deck array
var deck = [];
var m = 0;
// looping structure to create the deck of cards
for (let i = 0; i < symbol.length; i++) {
for (let j = 0; j < color.length; j++) {
for (let k = 0; k < shading.length; k++) {
for (let l = 0; l < quantity.length; l++) {
deck[m] = {symbol: symbol[i], color:color[j], shading: shading[k], quantity: quantity[l], cardID : m+1, hint:false, displayed:false, slot:0, selected:false};
// DEBUG output to make sure this works
//console.log((m+1) + " " + symbol[i] + " and " + color[j] + " and " + shading[k] + " and " + quantity[l]);
//console.log((m+1) + " " + deck[m].symbol + ", "+ deck[m].color + ", "+ deck[m].shading + ", "+ deck[m].quantity);
m++;
}
}
}
}
return deck;
};
shuffleDeck = function (deckMaster) {
let shuffled = deckMaster.slice(0);
var j, x, i;
for (i = shuffled.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
x = shuffled[i];
shuffled[i] = shuffled[j];
shuffled[j] = x;
}
return shuffled;
}
createTable = function (playDeck) {
//create initial table plateau of 12 dealt cards
var plateau = [];
for ( let cards = 0; cards < 12; cards++) {
plateau[cards] = playDeck.pop();
plateau[cards].slot = cards;
};
return plateau;
};
// noMatch is used when creating a new playsurface
//isMatch is used when determining if the three selected and submitted cards are a match
noMatch = function (playSurface) {
// clearing the hint data
for (let i=1; i<13; i++){
let clearHints = "card" + (i);
hint[clearHints] = false;
}
// complicated nesting for loops to find matches
for (let i = 0; i < (playSurface.length - 2); i++) {
for (let j = i+1; j < (playSurface.length - 1); j++) {
for (let k = j+1; k < playSurface.length; k++) {
symbolMatched = 0;
colorMatched = 0;
shadingMatched = 0;
quantityMatched = 0;
weHaveASet = 0;
// Are the symbols all the same or all different?
if (playSurface[i].symbol === playSurface[j].symbol && playSurface[i].symbol === playSurface[k].symbol) {
symbolMatched = 1;
} else if ((playSurface[i].symbol !== playSurface[j].symbol) && (playSurface[i].symbol !== playSurface[k].symbol) && (playSurface[j].symbol !== playSurface[k].symbol)) {
symbolMatched = 1;
} else {
symbolMatched = 0;
}
// Now check the colors
if (playSurface[i].color === playSurface[j].color && playSurface[i].color === playSurface[k].color) {
colorMatched = 1;
} else if ((playSurface[i].color !== playSurface[j].color) && (playSurface[i].color !== playSurface[k].color) && (playSurface[j].color !== playSurface[k].color)) {
colorMatched = 1;
} else {
colorMatched = 0;
}
// Now the check the shading
if (playSurface[i].shading === playSurface[j].shading && playSurface[i].shading === playSurface[k].shading) {
shadingMatched = 1;
} else if ((playSurface[i].shading !== playSurface[j].shading) && (playSurface[i].shading !== playSurface[k].shading) && (playSurface[j].shading !== playSurface[k].shading)) {
shadingMatched = 1;
} else {
shadingMatched = 0;
}
// finally the quantity of symbols
if (playSurface[i].quantity === playSurface[j].quantity && playSurface[i].quantity === playSurface[k].quantity) {
quantityMatched = 1;
} else if ((playSurface[i].quantity !== playSurface[j].quantity) && (playSurface[i].quantity !== playSurface[k].quantity) && (playSurface[j].quantity !== playSurface[k].quantity)) {
quantityMatched = 1;
} else {
quantityMatched = 0;
}
// Now checking if we have a set
if (4 === (symbolMatched + colorMatched + shadingMatched + quantityMatched)) {
weHaveASet = 1;
// saving the set for the hint buttons.
let resultI = "card" + (i + 1);
let resultJ = "card" + (j + 1);
let resultK = "card" + (k + 1);
hint[resultI] = true;
hint[resultJ] = true;
hint[resultK] = true;
// DEBUG code
//console.log(hint.card1 + " " + hint.card2 + " " + hint.card3 + " " + hint.card4 + " " + hint.card5 + " " + hint.card6 + " " + hint.card7 + " " + hint.card8 + " " + hint.card9 + " " + hint.card10 + " " + hint.card11 + " " + hint.card12);
//console.log ( " \n\nWe have a Set!!: i = " + i + " j = " + j + " k = " + k + " symbol: " + symbolMatched + " color: " + colorMatched + " shading: " + shadingMatched + " quantity: " + quantityMatched + "\n");
//console.log((1) + " " + playSurface[i].symbol + ", "+ playSurface[i].color + ", "+ playSurface[i].shading + ", "+ playSurface[i].quantity);
//console.log((2) + " " + playSurface[j].symbol + ", "+ playSurface[j].color + ", "+ playSurface[j].shading + ", "+ playSurface[j].quantity);
//console.log((3) + " " + playSurface[k].symbol + ", "+ playSurface[k].color + ", "+ playSurface[k].shading + ", "+ playSurface[k].quantity);
// if we have a set then no need to do anything else. Break out of this loop.
return weHaveASet;
} else {
weHaveASet = 0;
//DEBUG code
//console.log("nope");
//console.log ( " \nNo Set: i = " + i + " j = " + j + " k = " + k + " symbol: " + symbolMatched + " color: " + colorMatched + " shading: " + shadingMatched + " quantity: " + quantityMatched);
//console.log((1) + " " + playSurface[i].symbol + ", "+ playSurface[i].color + ", "+ playSurface[i].shading + ", "+ playSurface[i].quantity);
//console.log((2) + " " + playSurface[j].symbol + ", "+ playSurface[j].color + ", "+ playSurface[j].shading + ", "+ playSurface[j].quantity);
//console.log((3) + " " + playSurface[k].symbol + ", "+ playSurface[k].color + ", "+ playSurface[k].shading + ", "+ playSurface[k].quantity);
};
}; // end of k for loop
}; // end of j for loop
}; // end of i for loop
return weHaveASet;
}; //end of the function
submitButton = function (x,y, playSurface) {
if (displayed.submit === true && gameControls.gamePaused === false) {
if ((x >= uiElements.submitButtonX - uiElements.pad && x <= uiElements.submitButtonX + uiElements.submitButtonW + (uiElements.pad * 2)) && (y >= uiElements.submitButtonY - uiElements.pad && y <= uiElements.submitButtonY + uiElements.submitButtonL + (uiElements.pad * 2))) {
console.log("submitButton");
if (selected.full === 3) {
var submitted = [];
let j = 0;
for(let i = 1; i < 13; i++) {
let count = "card" + i;
if (selected[count] === true) {
console.log (i-1);
submitted[j] = playSurface[i-1];
j++;
}
}
console.log("submitted cards:" + submitted[0].slot + " " + submitted[1].slot + " " + submitted[2].slot );
//Is Match function
if (gameControls.gameOver === false) {
flashSubmitButton();
isMatch(submitted);
if (gameControls.gameOver === false){
refreshScreen();
}
}
} else {
submitCardsRejectSFX.play();
console.log("Please Select Three cards");
}
}
}
};
reloadGame = function (x,y) {
if ((x >= uiElements.reloadButtonX - uiElements.pad && x <= uiElements.reloadButtonX + uiElements.reloadButtonW + (uiElements.pad * 2)) && (y >= uiElements.reloadButtonY - uiElements.pad && y <= uiElements.reloadButtonY + uiElements.reloadButtonL + (uiElements.pad * 2)) && displayed.oneMore === true) {
// SFX for Button Click
console.log("reload Game");
window.location.reload(true);
}
};
drawSettingsButton = function () {
var CTX = document.getElementById("ctx").getContext("2d");
CTX.beginPath();
CTX.clearRect(uiElements.settingsButtonX, uiElements.settingsButtonY, uiElements.settingsButtonW, uiElements.settingsButtonL);
CTX.lineWidth=6;
CTX.font="20px Arial";
CTX.strokeStyle="Black";
CTX.strokeRect(uiElements.settingsButtonX, uiElements.settingsButtonY, uiElements.settingsButtonW, uiElements.settingsButtonL);
CTX.fillText("Settings", uiElements.settingsButtonTextX, uiElements.settingsButtonTextY);
CTX.stroke();
CTX.closePath();
}
settingsButton = function (x,y) {
if ((x >= uiElements.settingsButtonX - uiElements.pad && x <= uiElements.settingsButtonX + uiElements.settingsButtonW + (uiElements.pad * 2)) && (y >= uiElements.settingsButtonY - uiElements.pad && y <= uiElements.settingsButtonY + uiElements.settingsButtonL + (uiElements.pad * 2)) && displayed.settings === true) {
// SFX for Button Click
console.log("settingsButton");
pauseGame();
displaySettings();
}
};
displaySettings = function () {
var SETTINGS = document.getElementById("ctx").getContext("2d");
SETTINGS.clearRect(5,5,420,600);
SETTINGS.clearRect(50,50,450,580);
SETTINGS.beginPath();
SETTINGS.strokeStyle="Black";
SETTINGS.lineWidth=6;
SETTINGS.rect(uiElements.rulesX, uiElements.rulesY, uiElements.rulesW, uiElements.rulesL);
SETTINGS.font="20px Arial";
SETTINGS.fillText("Settings Panel", uiElements.rulesLine1X, uiElements.rulesLine1Y);
SETTINGS.stroke();
SETTINGS.closePath();
displayed.returnButton = true;
drawReturnButton();
displayed.sfxButtons = true;
drawSfxButtons();
};
drawReturnButton = function () {
if (displayed.returnButton === true) {
var CTX = document.getElementById("ctx").getContext("2d");
CTX.beginPath();
CTX.clearRect(uiElements.settingsButtonX, uiElements.settingsButtonY, uiElements.settingsButtonW, uiElements.settingsButtonL);
CTX.stroke();
CTX.lineWidth=6;
CTX.font="20px Arial";
CTX.strokeStyle="Blue";
CTX.strokeRect(uiElements.returnButtonX, uiElements.returnButtonY , uiElements.returnButtonW, uiElements.returnButtonL);
CTX.fillText("Back To Game", uiElements.returnButtonTextX, uiElements.returnButtonTextY);
CTX.stroke();
CTX.closePath();
}
}
returnButton = function (x,y) {
if ((x >= uiElements.returnButtonX - uiElements.pad && x <= uiElements.returnButtonX + uiElements.returnButtonW + (uiElements.pad * 2)) && (y >= uiElements.returnButtonY - uiElements.pad && y <= uiElements.returnButtonY + uiElements.returnButtonL + (uiElements.pad * 2)) && displayed.returnButton === true) {
var WIPE = document.getElementById("ctx").getContext("2d");
WIPE.clearRect(5,5,420,600);
WIPE.clearRect(50,50,450,580);
WIPE.beginPath();
// SFX for Button Click
console.log("return to Game Button");
unPauseGame();
}
};
pauseGame = function () {
if (gameControls.gamePaused === false){
gameControls.gamePaused = true;
for (let i=1; i<13; i++){
let pausing = "card" + (i);
displayed[pausing] = false;
};
displayed.hint = false;
displayed.submit = false;
displayed.clearSubmit = false;
displayed.deck = false;
displayed.banner = false;
displayed.timer = false;
displayed.settings = false;
displayed.returnButton = true;
displayed.sfxButtons = true;
}
refreshScreen();
}
unPauseGame = function () {
if (gameControls.gamePaused === true){
gameControls.gamePaused = false;
for (let i=1; i<13; i++){
let pausing = "card" + (i);
displayed[pausing] = true;
};
displayed.hint = true;
displayed.submit = true;
displayed.clearSubmit = true;
displayed.settings = true;
displayed.deck = true;
displayed.banner = true;
displayed.timer = true;
displayed.returnButton = false;
displayed.sfxButtons = false;
}
createGameUI();
refreshScreen();
}
flashSubmitButton = function () {
var CTX = document.getElementById("ctx").getContext("2d");
CTX.beginPath();
CTX.clearRect(uiElements.submitButtonX, uiElements.submitButtonY, uiElements.submitButtonW, uiElements.submitButtonL);
CTX.lineWidth=6;
CTX.font="20px Arial";
CTX.strokeStyle="Red";
CTX.strokeRect(uiElements.submitButtonX, uiElements.submitButtonY, uiElements.submitButtonW, uiElements.submitButtonL);
CTX.fillText("Submit", uiElements.submitButtonTextX, uiElements.submitButtonTextY);
CTX.stroke();
CTX.closePath();
restoreSubmitButton = function () {
CTX.beginPath();
CTX.clearRect(uiElements.submitButtonX, uiElements.submitButtonY, uiElements.submitButtonW, uiElements.submitButtonL);
CTX.lineWidth=6;
CTX.font="20px Arial";
CTX.strokeStyle="Blue";
CTX.strokeRect(uiElements.submitButtonX, uiElements.submitButtonY, uiElements.submitButtonW, uiElements.submitButtonL);
CTX.fillText("Submit", uiElements.submitButtonTextX, uiElements.submitButtonTextY);
CTX.stroke();
CTX.closePath();
};
if (playDeck.length > 3) {
setTimeout(restoreSubmitButton, 180);
}
};
isMatch = function (submitted) {
// clearing the hint data
// complicated nesting for loops to find matches
for (let i = 0; i < (submitted.length - 2); i++) {
for (let j = i+1; j < (submitted.length - 1); j++) {
for (let k = j+1; k < submitted.length; k++) {
symbolMatched = 0;
colorMatched = 0;
shadingMatched = 0;
quantityMatched = 0;
weHaveASet = 0;
// Are the symbols all the same or all different?
if (submitted[i].symbol === submitted[j].symbol && submitted[i].symbol === submitted[k].symbol) {
symbolMatched = 1;
} else if ((submitted[i].symbol !== submitted[j].symbol) && (submitted[i].symbol !== submitted[k].symbol) && (submitted[j].symbol !== submitted[k].symbol)) {
symbolMatched = 1;
} else {
symbolMatched = 0;
}
// Now check the colors
if (submitted[i].color === submitted[j].color && submitted[i].color === submitted[k].color) {
colorMatched = 1;
} else if ((submitted[i].color !== submitted[j].color) && (submitted[i].color !== submitted[k].color) && (submitted[j].color !== submitted[k].color)) {
colorMatched = 1;
} else {
colorMatched = 0;
}
// Now the check the shading
if (submitted[i].shading === submitted[j].shading && submitted[i].shading === submitted[k].shading) {
shadingMatched = 1;
} else if ((submitted[i].shading !== submitted[j].shading) && (submitted[i].shading !== submitted[k].shading) && (submitted[j].shading !== submitted[k].shading)) {
shadingMatched = 1;
} else {
shadingMatched = 0;
}
// finally the quantity of symbols
if (submitted[i].quantity === submitted[j].quantity && submitted[i].quantity === submitted[k].quantity) {
quantityMatched = 1;
} else if ((submitted[i].quantity !== submitted[j].quantity) && (submitted[i].quantity !== submitted[k].quantity) && (submitted[j].quantity !== submitted[k].quantity)) {
quantityMatched = 1;
} else {
quantityMatched = 0;
}
// Now checking if we have a set
if (4 === (symbolMatched + colorMatched + shadingMatched + quantityMatched)) {
weHaveASet = 1;
// update score
submitCardsSFX.play();
updateScore();
gameControls.hintUsed = false;
//clearhints and selections
for (let i=1; i<13; i++){
let clearHints = "card" + (i);
hint[clearHints] = false;
selected[clearHints] = false;
selected.full = 0;
};
cardsRemaining = cardsRemaining - 3;
dealCards(submitted);
continueGame(submitted);
submitted.length = 0;
if (gameControls.gameOver === false) {
refreshScreen();
}
if (cardsRemaining === 0) {
endGame();
console.log("Game ended due to no more cards");
};
} else {
weHaveASet = 0;
submitCardsRejectSFX.play();
//clear the submitted array
//flash the submit button
//flashSubmitButton();
//Change the game banner text
uiElements.bannerText = "Not a Match!";
clearSelections();
setTimeout(defaultBanner, 100);
};
}; // end of k for loop
}; // end of j for loop
}; // end of i for loop
return weHaveASet;
}; //end of the function
defaultBanner = function () {
uiElements.bannerText = "Select 3 cards to make a match";
};
dealCards = function(submitted) {
// Setting variables
var slot1 = submitted[0].slot;
var slot2 = submitted[1].slot;
var slot3 = submitted[2].slot;
console.log("Dealing Cards --> slot 1 is card " + slot1 + "; slot 2 is " + slot2 + "; slot 3 is " + slot3 );
//changing the cards from the ones submitted to ones from the deck
playSurface[slot1] = playDeck.pop();
playSurface[slot1].slot = slot1;