forked from ni3175/Memory_Matching_Game
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgame.js
executable file
·947 lines (822 loc) · 34.7 KB
/
game.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
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
var framePrefab : GameObject; // Frame Object
var picturePrefab : GameObject; // Picture Object
var avatars : Texture2D[]; // Avatars array
var avatarsMini : Texture2D[]; // Avatars mini pictures array
var scores_tex : Texture2D; // Texture used for scores
var avatarSelected : int; // Number of selected avatar
static var object1 : GameObject; // Selected object 1
static var object2 : GameObject; // Selected object 2
var materialsArray : Material[]; // Materials array used for game pictures
static var newMaterials1 : int[]; // Is used for level material creation.
static var newMaterials2 : int[]; // Array used for material creation limit. Example: We need two same pictures for them to be matched, so this array will help us to create only two matching picture per material.
static var openPic1 : boolean; // Can picture 1 be opened
static var openPic2 : boolean; //
static var closePic1 : boolean; // Can picture 2 be opened
static var closePic2 : boolean; //
var OpenSpeed : int; // Opening speed
var CloseSpeed : int; // Closing speed
var selection : AudioClip; // Object select sound
var swish : AudioClip; // Destroy pictures sound
var memoryGUISkin : GUISkin; // Skin used for game
static var currentLevel : int; // Current playing level
var playerName : String; // Name of the player
var playTime : String; // Time needed to complete the level
static var timeLeft : String;
static var timeLevelLoad : float; // Time when the level wes loaded
var pictures : GameObject[]; // Pictures array
static var pictureNumber : int; // Number of pictures for level
static var menu : int; // Menu index
static var gameStart : boolean; // Can game start
var mainMenuBackground : Texture2D; // Background texture for main menu
var halloffame : Texture2D; // Hall of Fame texture
var demoMode : boolean; // Is game in demo mode
var myScore:float;
static var scores = new Array(); // Saved scores
static var isScoreSet : boolean; // Is new score saved
//alll the parameters about facebook integration and url from albums
var message : String;
//var myPic = new Array();
//var myfPic = new Array();
var myCounter: int;
var myfCounter: int;
var popularCounter:int;
var recentCounter:int;
//var www=new Array();
var furl = new Array(); // url from my friends' albums
var myurl = new Array(); // url from my albums
var popularUrl = new Array(); // url from most popluar albums
var recentUrl = new Array();//url from most recent photos
var funiqueUrl = new Array();
var myuniqueUrl = new Array();
function Awake(){
//demoMode = false; // Used for a game demo preview, here is a script contro
}
function Start(){
menu = 1; // Set to main menu
playTime = "0"; // Set play time, converted to String
timeLeft = "60";
playerName = "Your Name"; // Set default player name
currentLevel = 1; // Set current level
//materialsArray = UnityCommunication.materialsArray;
//Application.ExternalCall("myfAlbums"); ///get my friends albums url from html generated by unity
//Application.ExternalCall("myAlbums");
}
function Update(){
timeLevelLoad = Time.timeSinceLevelLoad; // How much time from the level load event
if(cam.timerON == true && cam.startTime > 0){ // If timer is ON and start time is greater then 0
playTime = CalculateTime(); // Call calculate time function }
if(currentLevel==1){
timeLeft = (60-float.Parse(playTime)).ToString();
}
if(currentLevel==2){
timeLeft = (60-float.Parse(playTime)).ToString();
}
if(currentLevel ==4){
timeLeft = (150-float.Parse(playTime)).ToString();
}
//Debug.Log(float.Parse(game.timeLeft));
//print(float.Parse(game.timeLeft));
}
if(Input.GetKeyUp(KeyCode.Escape)){ // If we press Escape key
switch(menu){ // Select game mode/menu
case 0: // If we are in Game Play mode
// Prepare game to be reset
cam.timerON = false; // Timer is OFF
cam.finish = true; // End game
menu = 1; // Go to main menu
openPic1 = true; // We can open pictures
openPic2 = true; //
closePic1 = false; // Picture 1 can't be closed
closePic2 = false; //
object1 = null; // Set picture 1 reference to empty
object2 = null; //
playTime = "0"; // Reset time
timeLeft = "60"; // Reset time
ClearLevel(); // Clear the level
break;
case 1: // Main Menu
break;
case 2: // Avatar Select
menu = 1;
break;
case 3: // Level Select
menu = 2;
break;
case 4: // Score
break;
case 5: // Hall of Fame
break;
}
}
OpenPicture1(); // Open first selected picture function
OpenPicture2(); // Open second selected picture function
ClosePicture1(); // Close first picture function
ClosePicture2(); // Close second picture function
pictures = GameObject.FindGameObjectsWithTag("picture"); // Get all picture objects
pictureNumber = pictures.length; // Get number of pictures left
}
function OnGUI(){
GUI.skin = memoryGUISkin; // Set skin
GUI.matrix = Matrix4x4.Scale(Vector3(Screen.width/800.0,Screen.height/600.0,1)); // Auto scale GUI
if(menu == 1){ // Main menu
GUI.DrawTexture(Rect(0, 0, 800, 800),mainMenuBackground, ScaleMode.ScaleToFit, true,0); // Draw texture
if(GUI.Button(Rect(303, 431, 198, 46), "", "start")){ // If click on start button
Application.ExternalCall("myAlbums");
Application.ExternalCall("myfAlbums");
Application.ExternalCall("popularPhotos");
Application.ExternalCall("recentPhotos");
audio.PlayOneShot(selection); // Play sound
menu++; // Menu index = 2
}
if(GUI.Button(Rect(303, 487, 198, 46), "", "exit")){ // Exit button - used on PC
Application.Quit(); // Quit application
}
}
if(menu == 2){ // Avatar select menu
GUI.DrawTexture(Rect(0, 0, 800, 800), mainMenuBackground, ScaleMode.ScaleToFit, true,0); //
//playerName = GUI.TextField(Rect(247, 424, 310, 54), playerName, 10); // Enter player name
/*
GUI.Label(Rect(332, 294, 140, 140), "", "avatarplace"); // Avatar background
if(GUI.Button(Rect(291, 323, 55, 84), "", "avatarminus")){ // Avatar plus button
if(avatarSelected > 0){ // if avatar selected index is greater than 0
audio.PlayOneShot(selection); // Play sound
avatarSelected--; //
}
}
if(GUI.Button(Rect(459, 323, 55, 84), "", "avatarplus")){ // Avatar minus button
if(avatarSelected < avatars.length-1){ // if avatar selected index is smaller then number of avatars
audio.PlayOneShot(selection); //
avatarSelected++; //
}
}*/
//GUI.Label(Rect(200,50,368,74),"Photo Selection","selectphoto");
if(GUI.Button(Rect(200,100,380,50),"Most recent photos","levelbutton")){
audio.PlayOneShot(selection);
getRecentMaterial();
menu++;
}
if(GUI.Button(Rect(200,200,380,50),"Most popular photos","levelbutton")){
audio.PlayOneShot(selection);
getPopularMaterial();
menu++;
}
if(GUI.Button(new Rect(200,300,380,50),"My photos","levelbutton")){
//Application.ExternalCall("myAlbums");
audio.PlayOneShot(selection);
getMyMaterial();
menu++;
//Application.ExternalCall("myAlbums");
}
if(GUI.Button(new Rect(200,400,380,50),"Friends'photos","levelbutton")){
//Application.ExternalCall("myfAlbums");
audio.PlayOneShot(selection);
getFriMaterial();
menu++;
}
//if(GUI.Button(Rect(303, 500, 198, 46), "", "start")){ // Start button
//if(playerName == "" || playerName == "Your Name"){ // The name must be different then the default name
// playerName = "New Player";
//audio.PlayOneShot(selection); //
// menu++; // menu = 3
//}else{
// audio.PlayOneShot(selection); //
//menu++;
//}
//}
//GUI.DrawTexture(Rect(340, 300, 125, 125), avatars[avatarSelected]); // Draw selected avatar
}
if(menu == 3){ // Level Select menu
GUI.DrawTexture(Rect(0, 0, 800, 800), mainMenuBackground, ScaleMode.ScaleToFit, true,0); // Draw texture
GUI.Label(Rect(200, 100, 368, 74), "", "selectlevel"); // Label
//if(GUI.Button(new Rect(10,10,100,24),"press me")){
//Application.ExternalCall("helloWorld");
//}
//GUI.Button(new Rect(10,10,100,24),message);
/*
if(GUI.Button(new Rect(10,30,200,24),"my Picture number")){
Application.ExternalCall("myAlbums");
myPicture();
}*/
/*
if(GUI.Button(new Rect(50,400,350,50),"Get my Albums","levelbutton")){
//Application.ExternalCall("myAlbums");
getMyMaterial();
//Application.ExternalCall("myAlbums");
}*/
/*
if(GUI.Button(new Rect(50,300,350,50),"Get friends'Albums","levelbutton")){
//Application.ExternalCall("myfAlbums");
getFriMaterial();
}*/
//GUI.Label(new Rect(200,10,200,24),message);
GUI.Label(new Rect(500,30,200,24),"myCounter"+myCounter.ToString());
GUI.Label(new Rect(500,50,200,24),"myfCounter"+myfCounter.ToString());
GUI.Label(new Rect(500,70,200,24),"popularNum"+popularCounter.ToString());
GUI.Label(new Rect(500,90,200,24),"recentNum"+recentCounter.ToString());
if(GUI.Button(Rect(300, 300, 196, 44), "Level 1", "levelbutton")){
currentLevel = 1;
audio.PlayOneShot(selection);
CreateLevels(4,3);
}
if(GUI.Button(Rect(300, 400, 196, 44), "Level 2", "levelbutton")){
currentLevel = 2;
audio.PlayOneShot(selection);
CreateLevels(4,4);
}
/*
if(GUI.Button(Rect(500, 430, 194, 44), "Level 3", "levelbutton")){
if(demoMode != true){
currentLevel = 4;
audio.PlayOneShot(selection);
CreateLevels(5,5);
}
}*/
/*
if(GUI.Button(Rect(500, 250, 196, 44), "Level 1", "levelbutton")){ // Select level button
//materialsArray = UnityCommunication.materialsArray;
getMaterial();
currentLevel = 1; // Set current play level
audio.PlayOneShot(selection); // Play sound
CreateLevels(4,3); // Create level 4 in width an 3 in height
}
if(GUI.Button(Rect(500, 250, 196, 44), "Level 2", "levelbutton")){
currentLevel = 2;
audio.PlayOneShot(selection);
CreateLevels(4,4);
}
/*
if(GUI.Button(Rect(114, 390, 196, 44), "Level 3", "levelbutton")){
currentLevel = 3;
audio.PlayOneShot(selection);
CreateLevels(5,4);
}
if(GUI.Button(Rect(114, 454, 196, 44), "Level 4", "levelbutton")){
currentLevel = 4;
audio.PlayOneShot(selection);
CreateLevels(5,5);
}
/*
if(GUI.Button(Rect(114, 518, 196, 44), "Level 5", "levelbutton")){
if(demoMode != true){
currentLevel = 5;
audio.PlayOneShot(selection);
CreateLevels(6,5);
}
}
if(GUI.Button(Rect(490, 262, 194, 44), "Level 6", "levelbutton")){
if(demoMode != true){
currentLevel = 6;
audio.PlayOneShot(selection);
CreateLevels(6,6);
}
}
if(GUI.Button(Rect(490, 326, 196, 44), "Level 7", "levelbutton")){
if(demoMode != true){
currentLevel = 7;
audio.PlayOneShot(selection);
CreateLevels(7,6);
}
}
/*
if(GUI.Button(Rect(490, 390, 196, 44), "Level 8", "levelbutton")){
if(demoMode != true){
currentLevel = 8;
audio.PlayOneShot(selection);
CreateLevels(7,7);
}
}
if(GUI.Button(Rect(490, 454, 196, 44), "Level 9", "levelbutton")){
if(demoMode != true){
currentLevel = 9;
audio.PlayOneShot(selection);
CreateLevels(8,7);
}
}
if(GUI.Button(Rect(490, 518, 196, 44), "Level 10", "levelbutton")){
if(demoMode != true){
currentLevel = 10;
audio.PlayOneShot(selection);
CreateLevels(9,7);
}
}*/
}
if(menu == 0){ // In game GUI
//GUI.Label(Rect(5, 510, 220, 85),"", "memoryavatar"); // Avatar background
GUI.Label(Rect(565, 510, 227, 84),"", "memorytime"); // Play time background
GUI.Label(Rect(50, 559, 200, 40),playerName); // Display player name
//GUI.Label(Rect(550, 559, 200, 40), playTime); // Display play time
GUI.Label(Rect(550, 559, 200, 40), timeLeft);
// GUI.TextField(Rect(250, 510, 230, 88), "press esc to exit", 1);
GUI.Label(Rect(250, 535, 230, 88), "Press esc to exit"); // esc exit
//GUI.DrawTexture(Rect(15,520,64,64),avatarsMini[avatarSelected]); // Display avatar mini
}
if(menu == 4){ // Show Scores menu
var score: float;
if(isScoreSet == false){ // If scores are not set
SetScores(currentLevel); // Set scores for current level
isScoreSet = true; // Scores are set
}
//GUI.DrawTexture(Rect((800-scores_tex.width)/2, 250, scores_tex.width, scores_tex.height), scores_tex); // Draw scores background
//GUI.DrawTexture(Rect(188, 272, 96, 96), avatars[avatarSelected]); // Draw your selected avatar
//GUI.Label(Rect(305, 276, 190, 30), playerName, "score"); // Draw Player name
GUI.Label(Rect(200, 361, 190, 30), "My score:", "score");
GUI.Label(Rect(314, 361, 190, 30), myScore.ToString(), "score"); // Draw your play time
if(GUI.Button(Rect(114, 450, 196, 44), "Continue", "levelbutton")){ // Continue button
audio.PlayOneShot(selection); //
//GetScores(currentLevel);
playTime = "0"; // Reset Play Time
timeLeft = "60";
//menu = 5;
//Application.ExternalCall("myfAlbums"); ///get my friends albums url from html generated by unity
//Application.ExternalCall("myAlbums");
//yield;
menu =2;
ClearLevel();
//Application.ExternalCall("myfAlbums"); ///get my friends albums url from html generated by unity
//Application.ExternalCall("myAlbums"); // Call Get scores function
//playTime = "0.00"; // Reset Play Time
//timeLeft = "60.00";
//menu = 5;
//menu =3; // Set Hall of Fame menu
}
if(GUI.Button(Rect(490, 450, 194, 44), "Play Again", "levelbutton")){ // Play again button
//Application.ExternalCall("myfAlbums"); ///get my friends albums url from html generated by unity
//Application.ExternalCall("myAlbums");
//getFriMaterial();
ClearLevel();
playTime = "0"; //
timeLeft = "60";
audio.PlayOneShot(selection); //
switch(currentLevel){ // Check witch level has been played
case 1:
CreateLevels(4,3); // Create level 4 in width and 3 in height
break;
case 2:
CreateLevels(4,4);
break;
case 3:
CreateLevels(5,4);
break;
case 4:
CreateLevels(5,5);
break;
case 5:
CreateLevels(6,5);
break;
case 6:
CreateLevels(6,6);
break;
case 7:
CreateLevels(7,6);
break;
case 8:
CreateLevels(7,7);
break;
case 9:
CreateLevels(8,7);
break;
case 10:
CreateLevels(9,7);
break;
}
}
}
if(menu == 5){ // Show Hall of Fame scores
print("Hello");
if(GUI.Button(Rect(333, 56, 50, 45), "", "left")){ // Select level to show scores left arrow
audio.PlayOneShot(selection); //
if(currentLevel > 1){ //
currentLevel--; //
GetScores(currentLevel); // Get scores for selected level
}
}
if(GUI.Button(Rect(420, 56, 50, 45), "", "right")){ // Right arrow
audio.PlayOneShot(selection); //
if(currentLevel < 10){ //
currentLevel++; //
GetScores(currentLevel); //
}
}
print("Hi");
GUI.Label(Rect(375, 50, 53, 54), ""+currentLevel, "level"); // Level background
GUI.DrawTexture(Rect(110,15,halloffame.width,halloffame.height),halloffame,ScaleMode.ScaleToFit,true,0); // Draw Hall of Fame background
print("Haha");
// Hall of Fame - Score 1(The Best)
GUI.Label(Rect(202, 166, 200, 40),scores[0][1][0]); // Get Time score from scores array
GUI.Label(Rect(202, 116, 200, 40),scores[0][1][1]); // Get Name from scores array
GUI.DrawTexture(Rect(162,125,64,64),avatarsMini[scores[0][1][2]]); // Get avatar
// Score 2
GUI.Label(Rect(202, 262, 200, 40),scores[0][2][0]);
GUI.Label(Rect(202, 212, 200, 40),scores[0][2][1]);
GUI.DrawTexture(Rect(162,221,64,64),avatarsMini[scores[0][2][2]]);
// Score 3
GUI.Label(Rect(202, 359, 200, 40),scores[0][3][0]);
GUI.Label(Rect(202, 309, 200, 40),scores[0][3][1]);
GUI.DrawTexture(Rect(162,318,64,64),avatarsMini[scores[0][3][2]]);
// Score 4
GUI.Label(Rect(202, 455, 200, 40),scores[0][4][0]);
GUI.Label(Rect(202, 404, 200, 40),scores[0][4][1]);
GUI.DrawTexture(Rect(162,414,64,64),avatarsMini[scores[0][4][2]]);
// Score 5
GUI.Label(Rect(202, 551, 200, 40),scores[0][5][0]);
GUI.Label(Rect(202, 500, 200, 40),scores[0][5][1]);
GUI.DrawTexture(Rect(162,510,64,64),avatarsMini[scores[0][5][2]]);
// Score 6
GUI.Label(Rect(515, 166, 200, 40),scores[0][6][0]);
GUI.Label(Rect(515, 116, 200, 40),scores[0][6][1]);
GUI.DrawTexture(Rect(475,125,64,64),avatarsMini[scores[0][6][2]]);
// Score 7
GUI.Label(Rect(515, 262, 200, 40),scores[0][7][0]);
GUI.Label(Rect(515, 212, 200, 40),scores[0][7][1]);
GUI.DrawTexture(Rect(475,221,64,64),avatarsMini[scores[0][7][2]]);
// Score 8
GUI.Label(Rect(515, 359, 200, 40),scores[0][8][0]);
GUI.Label(Rect(515, 309, 200, 40),scores[0][8][1]);
GUI.DrawTexture(Rect(475,318,64,64),avatarsMini[scores[0][8][2]]);
// Score 9
GUI.Label(Rect(515, 455, 200, 40),scores[0][9][0]);
GUI.Label(Rect(515, 404, 200, 40),scores[0][9][1]);
GUI.DrawTexture(Rect(475,414,64,64),avatarsMini[scores[0][9][2]]);
// Score 10
GUI.Label(Rect(515, 551, 200, 40),scores[0][10][0]);
GUI.Label(Rect(515, 500, 200, 40),scores[0][10][1]);
GUI.DrawTexture(Rect(475,510,64,64),avatarsMini[scores[0][10][2]]);
if(GUI.Button(Rect(760,10,30,30),"","xexit")){ // X Exit button
menu = 1; //
}
}
}
function GetScores(lvl : int){ // Get scores for selected level
scores = new Array(); // All scores are in this array - new is used to reset array
scores.Push(new Array()); // Create a new array in a array
// scores => new array
scores[0].Push(new Array()); // Now add another array in to the 0 index place of an last array, this array has index 0
scores[0].Push(new Array()); // Now add another array, this array has index 1
scores[0][1].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-1 - Time","9999")); // Load player time to index 1 array, if empty then set default value
scores[0][1].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-1 - Name","New Player")); // Load player neme
scores[0][1].Push(PlayerPrefs.GetInt("3DMem L"+lvl.ToString()+"-1 - Avatar",1)); // Load player avatar index
scores[0].Push(new Array()); // Now add another array, this array has index 2
scores[0][2].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-2 - Time","9999")); // Everything is the same like for the index 1 array
scores[0][2].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-2 - Name","New Player")); //
scores[0][2].Push(PlayerPrefs.GetInt("3DMem L"+lvl.ToString()+"-2 - Avatar",1)); //
scores[0].Push(new Array());
scores[0][3].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-3 - Time","9999"));
scores[0][3].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-3 - Name","New Player"));
scores[0][3].Push(PlayerPrefs.GetInt("3DMem L"+lvl.ToString()+"-3 - Avatar",1));
scores[0].Push(new Array());
scores[0][4].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-4 - Time","9999"));
scores[0][4].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-4 - Name","New Player"));
scores[0][4].Push(PlayerPrefs.GetInt("3DMem L"+lvl.ToString()+"-4 - Avatar",1));
scores[0].Push(new Array());
scores[0][5].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-5 - Time","9999"));
scores[0][5].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-5 - Name","New Player"));
scores[0][5].Push(PlayerPrefs.GetInt("3DMem L"+lvl.ToString()+"-5 - Avatar",1));
scores[0].Push(new Array());
scores[0][6].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-6 - Time","9999"));
scores[0][6].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-6 - Name","New Player"));
scores[0][6].Push(PlayerPrefs.GetInt("3DMem L"+lvl.ToString()+"-6 - Avatar",1));
scores[0].Push(new Array());
scores[0][7].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-7 - Time","9999"));
scores[0][7].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-7 - Name","New Player"));
scores[0][7].Push(PlayerPrefs.GetInt("3DMem L"+lvl.ToString()+"-7 - Avatar",1));
scores[0].Push(new Array());
scores[0][8].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-8 - Time","9999"));
scores[0][8].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-8 - Name","New Player"));
scores[0][8].Push(PlayerPrefs.GetInt("3DMem L"+lvl.ToString()+"-8 - Avatar",1));
scores[0].Push(new Array());
scores[0][9].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-9 - Time","9999"));
scores[0][9].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-9 - Name","New Player"));
scores[0][9].Push(PlayerPrefs.GetInt("3DMem L"+lvl.ToString()+"-9 - Avatar",1));
scores[0].Push(new Array());
scores[0][10].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-10 - Time","9999"));
scores[0][10].Push(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-10 - Name","New Player"));
scores[0][10].Push(PlayerPrefs.GetInt("3DMem L"+lvl.ToString()+"-10 - Avatar",1));
}
function SetScores(lvl : int){ // Set scores for played level
//var myScore : float; // This is my score
var score : float; // This is score is from PlayePrefs
var isSet : boolean; // Is score set
var time : float;
//myScore = float.Parse(playTime); // Convert String to float so we can compare them
time=float.Parse(timeLeft);
if(lvl==1){
if (time>30.0){
myScore =time*30+(12-pictureNumber)*15;
}else if(time>=20.0)
{
myScore = time*20+(12-pictureNumber)*15;
}else if (time>0.0){
myScore=time*10;
}else{
myScore=0.0+(12-pictureNumber)*15;
}
}
if(lvl==2){
if (time>45.0){
myScore =time*30+(16-pictureNumber)*15;
}else if(time>=20.0)
{
myScore = time*20+(16-pictureNumber)*15;
}else if (time>0.0){
myScore=time*10;
}else{
myScore=0.0+(16-pictureNumber)*10;
}
}
if(lvl==4){
if (time>75.0){
myScore =time*30;
}else if(time>=50.0)
{
myScore = time*20;
}else if (time>0.0){
myScore=time*10;
}else{
myScore=0.0;
}
}
// Now we must loop thru all 10 scores and compare them with myScore score, if myScore smaller then
// score 1 or any other score then we are setting myScore on the score 1 position and all other scores
// are moved one place down
for(var x = 1; x <= 10; x++){ // Loop thru all 10 high scores
score = float.Parse(PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-"+x.ToString()+" - Time","9999")); // We are just loading every time and converting it to float
if(myScore < score){ // if myScore is smaller then loaded score
if(isSet == false){ // if score has not been set
ChangeScores(lvl,x); // Call function ChangeScores to change high scores, lvl is current level and x is score place
isSet = true; // Score has been set to true
}
}
}
}
function ChangeScores(lvl : int,l : int){ // Change High Scores
if(l < 10){ // If myScore is bigger then 10-th place so we can move every score for one place down
for(var x = 10; x >= l+1; x--){ // Loop thru scores
PlayerPrefs.SetString("3DMem L" + lvl.ToString() + "-" + x.ToString() + " - Name", PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-"+(x-1).ToString()+" - Name","New Player")); // Move Player Name one place down
PlayerPrefs.SetString("3DMem L" + lvl.ToString() + "-" + x.ToString() + " - Time", PlayerPrefs.GetString("3DMem L"+lvl.ToString()+"-"+(x-1).ToString()+" - Time","9999")); // Move Play Time one place down
PlayerPrefs.SetInt("3DMem L"+lvl.ToString()+"-"+x.ToString()+" - Avatar",PlayerPrefs.GetInt("3DMem L"+lvl.ToString()+"-"+(x-1).ToString()+" - Avatar",1)); // Move Avatar
}
}
// Now we need to set our name, play time and avatar to the high score position
PlayerPrefs.SetString("3DMem L"+lvl.ToString()+"-"+l.ToString()+" - Name",playerName); //
PlayerPrefs.SetString("3DMem L"+lvl.ToString()+"-"+l.ToString()+" - Time",myScore.ToString()); //
PlayerPrefs.SetInt("3DMem L"+lvl.ToString()+"-"+l.ToString()+" - Avatar",avatarSelected); //
}
// This function is optional, just to show you how to deal with PlayerPrefs
function DefaultScores(){
var keyString : String; // Key String
var keyStringTime : String; // Key String Time
var keyStringAvatar : String; // Key String Avatar
for(var x = 1; x <= 10; x++){
for(var y = 1; y <= 10; y++){
// Create paths
keyStringName = "3DMem L" + x.ToString() + "-" + y.ToString() + " - Name";
keyStringTime = "3DMem L" + x.ToString() + "-" + y.ToString() + " - Time";
keyStringAvatar = "3DMem L" + x.ToString() + "-" + y.ToString() + " - Avatar";
if(PlayerPrefs.HasKey(keyStringName) == false){ // If there is no key, then create keys and values
PlayerPrefs.SetString(keyStringName,"New Player");
PlayerPrefs.SetString(keyStringTime,"9999");
PlayerPrefs.SetInt(keyStringAvatar,1);
}
// Erase keys
keyStringName = "";
keyStringTime = "";
keyStringAvatar = "";
}
}
}
function OpenPicture1(){ // Open first picture
if(object1 != null && openPic1 == true){ // If first picture in not selected and open picture 1 is possible
if(object1.transform.eulerAngles.y < 180){ // Rotate picture 1 until 180 deg.
object1.transform.Rotate(0, OpenSpeed * Time.deltaTime, 0); // Rotate picture 1 on Y axis
}else{
object1.transform.eulerAngles = Vector3(0,180,0); // Prevent picture to rotate more then 180 deg.
openPic1 = false; // You can't open first picture again
}
}
}
// Same for picture 1
function OpenPicture2(){
if(object2 != null && openPic2 == true){
if(object2.transform.eulerAngles.y < 180){
object2.transform.Rotate(0, OpenSpeed * Time.deltaTime, 0);
}else{
object2.transform.eulerAngles = Vector3(0,180,0);
openPic2 = false;
ComparePictures(); // Call compare pictures function
}
}
}
function ClosePicture1(){
if(object1 != null && closePic1 == true){ // If picture 1 is selected
if(object1.transform.eulerAngles.y < 355 && object1.transform.eulerAngles.y > 10){ // If rotation is smaller then 355 deg. and greater then 10 deg.
object1.transform.Rotate(0, CloseSpeed * Time.deltaTime, 0); // Continue rotation from 180 to 360 deg.
}else{
object1.transform.eulerAngles = Vector3(0,0,0); // Close picture and set rotation to 0 deg.
closePic1 = false; // This prevents picture to be closed
object1 = null; // Set picture 1 reference to empty
}
}
}
// Same for picture 1
function ClosePicture2(){
if(object2 != null && closePic2 == true){
if(object2.transform.eulerAngles.y < 355 && object2.transform.eulerAngles.y > 10){
object2.transform.Rotate(0, CloseSpeed * Time.deltaTime, 0);
}else{
object2.transform.eulerAngles = Vector3(0,0,0);
closePic2 = false;
object2 = null;
openPic1 = true; // You can open picture 1 again
openPic2 = true; //
cam.canClick = true; // You can click on the pictures
}
}
}
function ComparePictures(){
var script1 = object1.GetComponent(pic); // Get access to a first picture script
var script2 = object2.GetComponent(pic); // Get access to a second selected picture script
if(script1.number == script2.number){ // Compare picture 1 number and picture 2 number
Destroy(object1); // Destroy picture 1
Destroy(object2); // Destroy picture 2
audio.PlayOneShot(swish); //
openPic1 = true; // You can open pictures again
openPic2 = true; //
cam.canClick = true; // You can click again
}else{ // If they are not the same pictures
// Close pictures
closePic1 = true;
closePic2 = true;
}
}
function CalculateTime():String{ // Create play time in seconds and convert it to string
var runTime : float; // runTime = play time
var convertedTime : String; // For return
runTime = timeLevelLoad - cam.startTime; // cam.startTime is the time when we first time click on a picture
// and timeLevelLoad is time past since the level load event
convertedTime = runTime.ToString("0"); // Convert time to string and format it to .00
return convertedTime; // Return time
}
function CreateMATERIALS(a : int){ // A is the number of materials
var randomNumber : int; // Random material
var materialNumber = 0; // Materials number
var sameMaterial : boolean; // If the same material
var inMaterials : int; // Is in materials
newMaterials1 = new int[a]; // Created new materials
newMaterials2 = new int[a]; // Number of used new materials
for(var x = 0; x < a; x++){ // Set materials array to 0 created and 2 left per material
newMaterials1[x] = 0;
newMaterials2[x] = 2;
}
while(materialNumber < a){ // If number of created materials are less then we need
sameMaterial = false; //
//randomNumber = Random.Range(0,135); // Pick one random material from our 135 materials
randomNumber = Random.Range(0,20);
for(inMaterials in newMaterials1){ // Check array of created materials does is exists
if(randomNumber == inMaterials){ // If exists
sameMaterial = true; // That is the same materials
}
}
if(sameMaterial == false){ // If does not exists then we can create a material
newMaterials1[materialNumber] = randomNumber; //
materialNumber++; // Materials count
}
}
}
function CreateLevels(hCount : int, vCount : int){ // Create a play level
var xObjectPos : float; // Grid X position
var yObjectPos : float; // Grid Y position
var pictureObject1 : GameObject; // object prefab
var pictureObject2 : GameObject; //
var script : pic; // Script reference
var randomMaterial : int; // Random material for a new created picture
var next : boolean; // We can create next picture
var suf : int; // Sufficient picture
var matNo : int; // Material number
var count : int; // Count
var rem : int; // Remaining picture number
// Now we must see is there a remaining picture in our level
// Number of pictures must be an even number so we can clear the level
// like 4x4 = 16, 8x8 = 64... If we have 5x5 = 25 then one picture remains
// You can use that last picture for some hidden power up or something like that
suf = (hCount * vCount) % 2; // Check is there a remainder
if(suf == 1){ // If there is
rem = ((hCount * vCount) - 1) / 2 + 1; // Get the middle picture number
matNo = ((hCount * vCount) - 1) / 2; // Calculate material number needed for the level
}else{ //
matNo = hCount * vCount / 2; //
rem = -1; // Remaining picture number to -1 so all the pictures are created
}
//materialsArray = UnityCommunication.materialsArray;
CreateMATERIALS(matNo); // Create materials for the level
for(xObjectPos = -((hCount-1)*22.0)/2; xObjectPos <= ((hCount-1)*22.0)/2; xObjectPos += 22.0){ // Calculate X position
for(yObjectPos = ((vCount-1)*22.0)/2; yObjectPos >= -((vCount-1)*22.0)/2; yObjectPos -= 22.0){ // Calculate Y position
count++; // Count created pictures
if(count != rem){ // If not equal Remaining picture number then create picture
next = false; //
while(next == false){ // Create new material when this one is created
randomMaterial = Random.Range(0,matNo); // Random material from created materials
if(newMaterials2[randomMaterial] > 0){ // Must be valid
newMaterials2[randomMaterial] -= 1; // We need only 2 same materials
// The picture objects I have created is created from two parts
// This is the hard way. You can create one model with two materials
// then just change picture material.
frameObject = Instantiate(framePrefab, Vector3(xObjectPos,yObjectPos,0), Quaternion.identity); // Quaternion.identity); // Create prefab
script = frameObject.GetComponent("pic"); // Access script
script.number = randomMaterial; // Set material number
pictureObject = Instantiate(picturePrefab, Vector3(xObjectPos,yObjectPos,0), Quaternion.identity); // Create picture number
pictureObject.renderer.material = materialsArray[newMaterials1[randomMaterial]]; // Asign material to picture
pictureObject.transform.parent = frameObject.transform; // Set picture parent
next = true; // Now we can create a new picture
}
}
}
}
}
yield; // Wait one frame
menu = 0; // In game GUI
isScoreSet = false; // Score is not set yet
openPic1 = true; // We can open pictures
openPic2 = true; //
cam.canClick = true; // We can click
cam.finish = false; // Its not game finish
}
function ClearLevel(){
var ob : GameObject; // Reference object
var objectsArray = GameObject.FindGameObjectsWithTag("picture"); // Find all remaining pictures in the game
for(ob in objectsArray){ // Loop thru all objects
Destroy(ob); // Destroy each object
}
}
function myPicture(url:String){
myurl.push(url);
myCounter++;
}
function myfPicture (url: String){
//Application.ExternalCall("Check",":"+url);
furl.push(url);
myfCounter++;
}
function popularPicture(url:String){
popularUrl.push(url);
popularCounter++;
}
function recentPicture(url:String){
//Application.ExternalCall("Check",":"+url);
recentUrl.push(url);
recentCounter++;
}
function getFriMaterial(){
funiqueUrl=unique(furl);
//Application.ExternalCall("Check","You got "+funiqueUrl.length+" pictures from your friends!");
for(var i=0; i<funiqueUrl.length;i++){
var www:WWW = new WWW(funiqueUrl[i]);
yield www;
materialsArray[i].mainTexture=www.texture;
}
}
function getMyMaterial(){
myuniqueUrl=unique(myurl);
//Application.ExternalCall("Check","You got "+myuniqueUrl.length+" pictures from your Facebook Albums!");
for(var i=0; i<myuniqueUrl.length;i++){
var www:WWW = new WWW(myuniqueUrl[i]);
yield www;
materialsArray[i].mainTexture=www.texture;
}
}
function getPopularMaterial(){
//Application.ExternalCall("Check","You got "+popularUrl.length+" pictures from your Facebook Albums!");
for(var i=0;i<popularUrl.length;i++){
var www:WWW = new WWW(popularUrl[i]);
yield www;
materialsArray[i].mainTexture=www.texture;
}
}
function getRecentMaterial(){
//Application.ExternalCall("Check","You got "+recentUrl.length+" pictures from your Facebook Albums!");
for(var i=0;i<recentUrl.length;i++){
var www:WWW = new WWW(recentUrl[i]);
yield www;
materialsArray[i].mainTexture=www.texture;
}
}
// acquire unique urlArray pictures.
function inArray(array, element) {
for(var i = 0; i < array.length; i++) {
if(array[i] == element) {
//Debug.Log("hello");
return true;
}
}
return false;
}
function unique(array) {
if(array.length < 2) return array;
var re = new Array();
re.push(array[0]);
for(var i=0; i < array.length; i++) {
if(!inArray(re, array[i])) {
re.push(array[i]);
}
}
return re;
}