-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBUNYI_LLANES_S18A_minesweeper.c
2800 lines (2209 loc) · 117 KB
/
BUNYI_LLANES_S18A_minesweeper.c
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
/*
DESCRIPTION:
This program is an imitation of the classic Minesweeper game developed by Microsoft. It is
a single-player game wherein the user navigates through the board and avoids inspecting any
mines to win. The format of the board can vary. With that being said, the user may modify
the board's format through their choice with a range of 5 to 10 rows and 5 to 15 columns
through a custom game. The user may also choose to play a classic game of either easy or
difficult which already has a set number of rows, columns and mines. However, the number
and locations of the mines are randomized and these apply to both modes. Furthermore, the
progam further implements leaderboard, statistics, and game profile features which lets the
program have its own individuality from the original game.
AUTHORS:
Christian Joseph Bunyi
Andre Gabriel Llanes
SECTION:
S18A
LAST MODIFIED:
April 1, 2024
ACKNOWLEDGMENTS:
1. Functions from Ups and Downs, a CCPROG1 Machine Project by Christian Joseph Bunyi
2. ASCII codes from https://theasciicode.com.ar/
3. Local date and time extraction techniques from
https://stackoverflow.com/questions/1442116/how-to-get-the-date-and-time-values-in-a-c-program
*/
// preprocessor directives
#include <conio.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <windows.h>
#define MAX_ROWS 10
#define MAX_COLUMNS 15
#define MAX_PROFILES 10
#define MAX_LEVELS 100
#define MAX_RECORDS 10
#define SHORT_SLEEP 500
#define LONG_SLEEP 1000
#define BOARD_REFRESH 100
#define ENTER_VALUE 13
#define ESCAPE_VALUE 27
#define ARROW_VALUE 224
#define UP_VALUE 72
#define DOWN_VALUE 80
#define LEFT_VALUE 75
#define RIGHT_VALUE 77
#define EASY_MODE "Classic->Easy"
#define DIFFICULT_MODE "Classic->Difficult"
#define CUSTOM_MODE "Custom"
#define WON_OUTCOME "Won"
#define LOST_OUTCOME "Lost"
#define QUIT_OUTCOME "Quit"
#define PROFILES_DIRECTORY "profiles\\profiles.txt"
#define LEADERBOARD_DIRECTORY "profiles\\leaderboard.txt"
#define LEVELS_DIRECTORY "levels\\levels.txt"
typedef char string20[21];
typedef char string100[101];
struct Tile {
int state;
int isFlagged;
int isRevealed;
};
struct Game {
int exists;
int rows;
int columns;
struct Tile Board[MAX_ROWS][MAX_COLUMNS];
string20 mode;
string20 outcome;
int seconds;
};
struct Stats {
int totalSeconds;
int won;
int lost;
};
struct Profile {
string20 name;
int creationDate;
int lifetimeGames;
struct Stats EasyStats;
struct Stats DifficultStats;
struct Stats CustomStats;
struct Game CurrentGame;
struct Game RecentGame1;
struct Game RecentGame2;
struct Game RecentGame3;
};
struct Records {
int numRecords;
string20 names[MAX_RECORDS];
int times[MAX_RECORDS];
};
struct Leaderboard {
struct Records EasyRecords;
struct Records DifficultRecords;
struct Records CustomRecords;
};
/*
@brief: prints the title screen ASCII
@param: theme - integer that dictates the color (cyan/bright red/bright green/purple)
Precondition: assumes theme is between 1 to 4, inclusive
*/
void printTitle(int theme) {
printf("\n");
if (theme == 1) { // cyan
printf(" \x1b[1m\x1b[36m%c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c %c%c%c %c%c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c\x1b[0m\n", 219,219, 219, 219, 219, 223, 223, 219, 219, 223, 223, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219, 223, 223, 223, 223, 219, 219, 220, 219,219,219,219, 220, 223, 219, 219, 219, 219, 223, 219, 219, 223, 223, 223, 223, 219, 219, 219, 219, 223, 223, 223, 223, 219, 219, 223, 219, 219, 219, 219, 219, 220, 219, 219, 223, 223, 223, 223, 219, 219, 223, 219, 219, 219, 219, 219, 220);
printf(" \x1b[1m\x1b[33m%c%c%c%c %c%c%c%c %c%c %c%c %c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 220, 220, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf(" \x1b[1m\x1b[37m%c%c %c %c%c %c%c %c%c %c %c%c %c%c%c%c%c%c %c%c%c%c%c %c%c %c%c %c%c%c%c%c%c %c%c%c%c%c%c %c%c %c%c %c%c%c%c%c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 223, 223, 223, 223, 223, 219, 219, 219, 220, 219, 219, 219, 219, 219, 219, 223, 223, 223, 223, 219, 219, 223, 223, 223, 223, 219, 219, 219, 219, 219, 219, 223, 223, 223, 223, 219, 219, 219, 219);
printf(" \x1b[1m\x1b[37m%c%c %c%c %c%c %c%c %c %c%c %c%c %c%c %c%c %c %c%c %c%c %c%c %c%c%c%c%c%c %c%c %c%c%c%c%c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 223, 219, 219, 219, 219, 219, 219, 219, 223);
printf(" \x1b[1m\x1b[33m%c%c %c%c %c%c %c%c %c %c%c %c%c %c %c%c %c%c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219, 219, 223, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 220);
printf(" \x1b[1m\x1b[36m%c%c%c%c %c%c%c%c %c%c%c%c%c%c%c%c %c%c %c%c%c%c %c%c%c%c%c%c%c%c %c%c%c%c%c %c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c %c%c%c%c %c%c%c%c%c%c%c%c %c%c%c %c%c%c%c\x1b[0m\n", 220, 219, 219, 220, 220, 219, 219, 220, 219, 220, 220, 219, 219, 220, 220, 219, 219, 219, 223, 219, 219, 219, 219, 219, 220, 220, 220, 220, 219, 219, 223, 219, 219, 219, 223, 219, 219, 219, 219, 219, 219, 220, 220, 220, 220, 219, 219, 219, 219, 220, 220, 220, 220, 219, 219, 220, 219, 219, 220, 219, 219, 220, 220, 220, 220, 219, 219, 220, 219, 219, 220, 219, 219, 220);
}
else if (theme == 2) { // bright red
printf(" \x1b[1m\x1b[31m%c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c %c%c%c %c%c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c\x1b[0m\n", 219,219, 219, 219, 219, 223, 223, 219, 219, 223, 223, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219, 223, 223, 223, 223, 219, 219, 220, 219,219,219,219, 220, 223, 219, 219, 219, 219, 223, 219, 219, 223, 223, 223, 223, 219, 219, 219, 219, 223, 223, 223, 223, 219, 219, 223, 219, 219, 219, 219, 219, 220, 219, 219, 223, 223, 223, 223, 219, 219, 223, 219, 219, 219, 219, 219, 220);
printf(" \x1b[1m\x1b[33m%c%c%c%c %c%c%c%c %c%c %c%c %c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 220, 220, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf(" \x1b[1m\x1b[37m%c%c %c %c%c %c%c %c%c %c %c%c %c%c%c%c%c%c %c%c%c%c%c %c%c %c%c %c%c%c%c%c%c %c%c%c%c%c%c %c%c %c%c %c%c%c%c%c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 223, 223, 223, 223, 223, 219, 219, 219, 220, 219, 219, 219, 219, 219, 219, 223, 223, 223, 223, 219, 219, 223, 223, 223, 223, 219, 219, 219, 219, 219, 219, 223, 223, 223, 223, 219, 219, 219, 219);
printf(" \x1b[1m\x1b[37m%c%c %c%c %c%c %c%c %c %c%c %c%c %c%c %c%c %c %c%c %c%c %c%c %c%c%c%c%c%c %c%c %c%c%c%c%c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 223, 219, 219, 219, 219, 219, 219, 219, 223);
printf(" \x1b[1m\x1b[33m%c%c %c%c %c%c %c%c %c %c%c %c%c %c %c%c %c%c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219, 219, 223, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 220);
printf(" \x1b[1m\x1b[31m%c%c%c%c %c%c%c%c %c%c%c%c%c%c%c%c %c%c %c%c%c%c %c%c%c%c%c%c%c%c %c%c%c%c%c %c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c %c%c%c%c %c%c%c%c%c%c%c%c %c%c%c %c%c%c%c\x1b[0m\n", 220, 219, 219, 220, 220, 219, 219, 220, 219, 220, 220, 219, 219, 220, 220, 219, 219, 219, 223, 219, 219, 219, 219, 219, 220, 220, 220, 220, 219, 219, 223, 219, 219, 219, 223, 219, 219, 219, 219, 219, 219, 220, 220, 220, 220, 219, 219, 219, 219, 220, 220, 220, 220, 219, 219, 220, 219, 219, 220, 219, 219, 220, 220, 220, 220, 219, 219, 220, 219, 219, 220, 219, 219, 220);
}
else if (theme == 3) { // bright green
printf(" \x1b[1m\x1b[32m%c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c %c%c%c %c%c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c\x1b[0m\n", 219,219, 219, 219, 219, 223, 223, 219, 219, 223, 223, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219, 223, 223, 223, 223, 219, 219, 220, 219,219,219,219, 220, 223, 219, 219, 219, 219, 223, 219, 219, 223, 223, 223, 223, 219, 219, 219, 219, 223, 223, 223, 223, 219, 219, 223, 219, 219, 219, 219, 219, 220, 219, 219, 223, 223, 223, 223, 219, 219, 223, 219, 219, 219, 219, 219, 220);
printf(" \x1b[1m\x1b[33m%c%c%c%c %c%c%c%c %c%c %c%c %c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 220, 220, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf(" \x1b[1m\x1b[37m%c%c %c %c%c %c%c %c%c %c %c%c %c%c%c%c%c%c %c%c%c%c%c %c%c %c%c %c%c%c%c%c%c %c%c%c%c%c%c %c%c %c%c %c%c%c%c%c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 223, 223, 223, 223, 223, 219, 219, 219, 220, 219, 219, 219, 219, 219, 219, 223, 223, 223, 223, 219, 219, 223, 223, 223, 223, 219, 219, 219, 219, 219, 219, 223, 223, 223, 223, 219, 219, 219, 219);
printf(" \x1b[1m\x1b[37m%c%c %c%c %c%c %c%c %c %c%c %c%c %c%c %c%c %c %c%c %c%c %c%c %c%c%c%c%c%c %c%c %c%c%c%c%c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 223, 219, 219, 219, 219, 219, 219, 219, 223);
printf(" \x1b[1m\x1b[33m%c%c %c%c %c%c %c%c %c %c%c %c%c %c %c%c %c%c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219, 219, 223, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 220);
printf(" \x1b[1m\x1b[32m%c%c%c%c %c%c%c%c %c%c%c%c%c%c%c%c %c%c %c%c%c%c %c%c%c%c%c%c%c%c %c%c%c%c%c %c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c %c%c%c%c %c%c%c%c%c%c%c%c %c%c%c %c%c%c%c\x1b[0m\n", 220, 219, 219, 220, 220, 219, 219, 220, 219, 220, 220, 219, 219, 220, 220, 219, 219, 219, 223, 219, 219, 219, 219, 219, 220, 220, 220, 220, 219, 219, 223, 219, 219, 219, 223, 219, 219, 219, 219, 219, 219, 220, 220, 220, 220, 219, 219, 219, 219, 220, 220, 220, 220, 219, 219, 220, 219, 219, 220, 219, 219, 220, 220, 220, 220, 219, 219, 220, 219, 219, 220, 219, 219, 220);
}
else if (theme == 4) { // dark purple
printf(" \x1b[1m\x1b[35m%c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c %c%c%c %c%c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c\x1b[0m\n", 219,219, 219, 219, 219, 223, 223, 219, 219, 223, 223, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219, 223, 223, 223, 223, 219, 219, 220, 219,219,219,219, 220, 223, 219, 219, 219, 219, 223, 219, 219, 223, 223, 223, 223, 219, 219, 219, 219, 223, 223, 223, 223, 219, 219, 223, 219, 219, 219, 219, 219, 220, 219, 219, 223, 223, 223, 223, 219, 219, 223, 219, 219, 219, 219, 219, 220);
printf(" \x1b[1m\x1b[33m%c%c%c%c %c%c%c%c %c%c %c%c %c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 220, 220, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf(" \x1b[1m\x1b[37m%c%c %c %c%c %c%c %c%c %c %c%c %c%c%c%c%c%c %c%c%c%c%c %c%c %c%c %c%c%c%c%c%c %c%c%c%c%c%c %c%c %c%c %c%c%c%c%c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 223, 223, 223, 223, 223, 219, 219, 219, 220, 219, 219, 219, 219, 219, 219, 223, 223, 223, 223, 219, 219, 223, 223, 223, 223, 219, 219, 219, 219, 219, 219, 223, 223, 223, 223, 219, 219, 219, 219);
printf(" \x1b[1m\x1b[37m%c%c %c%c %c%c %c%c %c %c%c %c%c %c%c %c%c %c %c%c %c%c %c%c %c%c%c%c%c%c %c%c %c%c%c%c%c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 223, 219, 219, 219, 219, 219, 219, 219, 223);
printf(" \x1b[1m\x1b[33m%c%c %c%c %c%c %c%c %c %c%c %c%c %c %c%c %c%c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219, 219, 223, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 220);
printf(" \x1b[1m\x1b[35m%c%c%c%c %c%c%c%c %c%c%c%c%c%c%c%c %c%c %c%c%c%c %c%c%c%c%c%c%c%c %c%c%c%c%c %c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c %c%c%c%c %c%c%c%c%c%c%c%c %c%c%c %c%c%c%c\x1b[0m\n", 220, 219, 219, 220, 220, 219, 219, 220, 219, 220, 220, 219, 219, 220, 220, 219, 219, 219, 223, 219, 219, 219, 219, 219, 220, 220, 220, 220, 219, 219, 223, 219, 219, 219, 223, 219, 219, 219, 219, 219, 219, 220, 220, 220, 220, 219, 219, 219, 219, 220, 220, 220, 220, 219, 219, 220, 219, 219, 220, 219, 219, 220, 220, 220, 220, 219, 219, 220, 219, 219, 220, 219, 219, 220);
}
}
/*
@brief: prints the main menu ASCII
@param: theme - integer that dictates the color (cyan/bright red/bright green/purple)
Precondition: assumes theme is between 1 to 4
*/
void printMenu(int theme) {
if (theme == 1) { // cyan
printf ("\x1b[1m\x1b[37m _.-=-._.-=-._.-=-._.-=-._.-=-._.-=-._\x1b[0m\n");
printf ("\x1b[1m\x1b[37m .-'--- - --- -- --- ---- '-.\x1b[0m\n");
printf ("\x1b[1m\x1b[37m ( )\x1b[0m\n");
printf("\x1b[1m\x1b[37m (\x1b[0m \x1b[1m\x1b[36m%c%c%c %c%c%c %c%c%c%c%c%c%c %c%c%c%c%c%c%c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[37m)\x1b[0m\n", 219, 219, 220, 220, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf("\x1b[1m\x1b[37m (\x1b[0m \x1b[1m\x1b[37m%c%c%c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[37m)\x1b[0m\n", 219, 219, 219, 220, 220, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf("\x1b[1m\x1b[37m (\x1b[0m \x1b[1m\x1b[33m%c%c %c%c %c%c %c%c%c%c%c %c%c %c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[37m)\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 223, 223, 223, 219, 219, 219, 219, 219, 219, 219, 219);
printf("\x1b[1m\x1b[37m (\x1b[0m \x1b[1m\x1b[36m%c%c %c%c %c%c%c%c%c%c%c %c%c %c%c %c%c%c%c%c%c%c%c\x1b[0m \x1b[1m\x1b[37m)\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf("\x1b[1m\x1b[37m ( )\x1b[0m\n");
printf("\x1b[1m\x1b[37m `-._.-' ( __ _) `-._.-' (__ _ ) `-._.-'\x1b[0m\n");
printf("\x1b[1m\x1b[37m `-._.-' `-._.-' `-._.-'\x1b[0m\n");
printf("\x1b[1m\x1b[37m `-._.-'\x1b[0m\n");
}
else if (theme == 2) { // bright red
printf ("\x1b[1m\x1b[37m _.-=-._.-=-._.-=-._.-=-._.-=-._.-=-._\x1b[0m\n");
printf ("\x1b[1m\x1b[37m .-'--- - --- -- --- ---- '-.\x1b[0m\n");
printf ("\x1b[1m\x1b[37m ( )\x1b[0m\n");
printf("\x1b[1m\x1b[37m (\x1b[0m \x1b[1m\x1b[31m%c%c%c %c%c%c %c%c%c%c%c%c%c %c%c%c%c%c%c%c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[37m)\x1b[0m\n", 219, 219, 220, 220, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf("\x1b[1m\x1b[37m (\x1b[0m \x1b[1m\x1b[37m%c%c%c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[37m)\x1b[0m\n", 219, 219, 219, 220, 220, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf("\x1b[1m\x1b[37m (\x1b[0m \x1b[1m\x1b[33m%c%c %c%c %c%c %c%c%c%c%c %c%c %c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[37m)\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 223, 223, 223, 219, 219, 219, 219, 219, 219, 219, 219);
printf("\x1b[1m\x1b[37m (\x1b[0m \x1b[1m\x1b[31m%c%c %c%c %c%c%c%c%c%c%c %c%c %c%c %c%c%c%c%c%c%c%c\x1b[0m \x1b[1m\x1b[37m)\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf("\x1b[1m\x1b[37m ( )\x1b[0m\n");
printf("\x1b[1m\x1b[37m `-._.-' ( __ _) `-._.-' (__ _ ) `-._.-'\x1b[0m\n");
printf("\x1b[1m\x1b[37m `-._.-' `-._.-' `-._.-'\x1b[0m\n");
printf("\x1b[1m\x1b[37m `-._.-'\x1b[0m\n");
}
else if (theme == 3) { // bright green
printf ("\x1b[1m\x1b[37m _.-=-._.-=-._.-=-._.-=-._.-=-._.-=-._\x1b[0m\n");
printf ("\x1b[1m\x1b[37m .-'--- - --- -- --- ---- '-.\x1b[0m\n");
printf ("\x1b[1m\x1b[37m ( )\x1b[0m\n");
printf("\x1b[1m\x1b[37m (\x1b[0m \x1b[1m\x1b[32m%c%c%c %c%c%c %c%c%c%c%c%c%c %c%c%c%c%c%c%c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[37m)\x1b[0m\n", 219, 219, 220, 220, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf("\x1b[1m\x1b[37m (\x1b[0m \x1b[1m\x1b[37m%c%c%c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[37m)\x1b[0m\n", 219, 219, 219, 220, 220, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf("\x1b[1m\x1b[37m (\x1b[0m \x1b[1m\x1b[33m%c%c %c%c %c%c %c%c%c%c%c %c%c %c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[37m)\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 223, 223, 223, 219, 219, 219, 219, 219, 219, 219, 219);
printf("\x1b[1m\x1b[37m (\x1b[0m \x1b[1m\x1b[32m%c%c %c%c %c%c%c%c%c%c%c %c%c %c%c %c%c%c%c%c%c%c%c\x1b[0m \x1b[1m\x1b[37m)\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf("\x1b[1m\x1b[37m ( )\x1b[0m\n");
printf("\x1b[1m\x1b[37m `-._.-' ( __ _) `-._.-' (__ _ ) `-._.-'\x1b[0m\n");
printf("\x1b[1m\x1b[37m `-._.-' `-._.-' `-._.-'\x1b[0m\n");
printf("\x1b[1m\x1b[37m `-._.-'\x1b[0m\n");
}
else if (theme == 4) { // dark purple
printf ("\x1b[1m\x1b[37m _.-=-._.-=-._.-=-._.-=-._.-=-._.-=-._\x1b[0m\n");
printf ("\x1b[1m\x1b[37m .-'--- - --- -- --- ---- '-.\x1b[0m\n");
printf ("\x1b[1m\x1b[37m ( )\x1b[0m\n");
printf("\x1b[1m\x1b[37m (\x1b[0m \x1b[1m\x1b[35m%c%c%c %c%c%c %c%c%c%c%c%c%c %c%c%c%c%c%c%c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[37m)\x1b[0m\n", 219, 219, 220, 220, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf("\x1b[1m\x1b[37m (\x1b[0m \x1b[1m\x1b[37m%c%c%c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[37m)\x1b[0m\n", 219, 219, 219, 220, 220, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf("\x1b[1m\x1b[37m (\x1b[0m \x1b[1m\x1b[33m%c%c %c%c %c%c %c%c%c%c%c %c%c %c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[37m)\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 223, 223, 223, 219, 219, 219, 219, 219, 219, 219, 219);
printf("\x1b[1m\x1b[37m (\x1b[0m \x1b[1m\x1b[35m%c%c %c%c %c%c%c%c%c%c%c %c%c %c%c %c%c%c%c%c%c%c%c\x1b[0m \x1b[1m\x1b[37m)\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf("\x1b[1m\x1b[37m ( )\x1b[0m\n");
printf("\x1b[1m\x1b[37m `-._.-' ( __ _) `-._.-' (__ _ ) `-._.-'\x1b[0m\n");
printf("\x1b[1m\x1b[37m `-._.-' `-._.-' `-._.-'\x1b[0m\n");
printf("\x1b[1m\x1b[37m `-._.-'\x1b[0m\n");
}
}
/*
@brief: prints the leaderboard ASCII
@param: theme - integer that dictates the color (cyan/bright red/bright green/purple)
Precondition: assumes theme is between 1 to 4, inclusive
*/
void printLeaderboard(int theme) {
if (theme == 1) { // cyan
printf ("\x1b[1m\x1b[36m%c%c %c%c %c%c%c%c%c%c%c %c%c %c%c %c%c%c%c%c%c %c%c%c%c%c %c%c%c%c%c %c%c%c%c%c%c%c %c%c%c%c%c%c%c%c%c%c %c%c%c%c%c\x1b[0m\n", 219, 219, 219, 219, 220, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219, 219, 219, 223, 223, 219, 219, 219, 219 ,223, 223, 223, 219, 219, 223, 223, 223, 220, 219, 219, 219, 219, 219, 220, 220, 219, 219, 219, 220, 220, 219, 219, 219, 220, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[33m%c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[37m%c%c%c%c%c%c%c %c%c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c%c%c%c %c%c%c%c%c %c%c%c%c%c%c%c %c%c %c%c %c%c %c%c%c%c\x1b[0m\n", 219, 219, 223, 223, 223, 219, 219, 219, 219, 223, 223, 223, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 223, 223, 223, 219, 219, 223, 223, 223, 219, 219, 223, 223, 223, 219 ,219, 219, 219, 223, 223, 219, 219, 219, 219, 223, 223);
printf ("\x1b[1m\x1b[33m%c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[36m%c%c %c%c %c%c %c%c %c%c%c%c%c %c%c%c%c%c %c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c%c%c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 220, 220, 220, 219, 219, 220, 220, 220, 219, 219, 220, 220, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
}
else if (theme == 2) { // bright red
printf ("\x1b[1m\x1b[31m%c%c %c%c %c%c%c%c%c%c%c %c%c %c%c %c%c%c%c%c%c %c%c%c%c%c %c%c%c%c%c %c%c%c%c%c%c%c %c%c%c%c%c%c%c%c%c%c %c%c%c%c%c\x1b[0m\n", 219, 219, 219, 219, 220, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219, 219, 219, 223, 223, 219, 219, 219, 219 ,223, 223, 223, 219, 219, 223, 223, 223, 220, 219, 219, 219, 219, 219, 220, 220, 219, 219, 219, 220, 220, 219, 219, 219, 220, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[33m%c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[37m%c%c%c%c%c%c%c %c%c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c%c%c%c %c%c%c%c%c %c%c%c%c%c%c%c %c%c %c%c %c%c %c%c%c%c\x1b[0m\n", 219, 219, 223, 223, 223, 219, 219, 219, 219, 223, 223, 223, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 223, 223, 223, 219, 219, 223, 223, 223, 219, 219, 223, 223, 223, 219 ,219, 219, 219, 223, 223, 219, 219, 219, 219, 223, 223);
printf ("\x1b[1m\x1b[33m%c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[31m%c%c %c%c %c%c %c%c %c%c%c%c%c %c%c%c%c%c %c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c%c%c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 220, 220, 220, 219, 219, 220, 220, 220, 219, 219, 220, 220, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
}
else if (theme == 3) { // bright green
printf ("\x1b[1m\x1b[32m%c%c %c%c %c%c%c%c%c%c%c %c%c %c%c %c%c%c%c%c%c %c%c%c%c%c %c%c%c%c%c %c%c%c%c%c%c%c %c%c%c%c%c%c%c%c%c%c %c%c%c%c%c\x1b[0m\n", 219, 219, 219, 219, 220, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219, 219, 219, 223, 223, 219, 219, 219, 219 ,223, 223, 223, 219, 219, 223, 223, 223, 220, 219, 219, 219, 219, 219, 220, 220, 219, 219, 219, 220, 220, 219, 219, 219, 220, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[33m%c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[37m%c%c%c%c%c%c%c %c%c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c%c%c%c %c%c%c%c%c %c%c%c%c%c%c%c %c%c %c%c %c%c %c%c%c%c\x1b[0m\n", 219, 219, 223, 223, 223, 219, 219, 219, 219, 223, 223, 223, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 223, 223, 223, 219, 219, 223, 223, 223, 219, 219, 223, 223, 223, 219 ,219, 219, 219, 223, 223, 219, 219, 219, 219, 223, 223);
printf ("\x1b[1m\x1b[33m%c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[32m%c%c %c%c %c%c %c%c %c%c%c%c%c %c%c%c%c%c %c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c%c%c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 220, 220, 220, 219, 219, 220, 220, 220, 219, 219, 220, 220, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
}
else if (theme == 4) { // dark purple
printf ("\x1b[1m\x1b[35m%c%c %c%c %c%c%c%c%c%c%c %c%c %c%c %c%c%c%c%c%c %c%c%c%c%c %c%c%c%c%c %c%c%c%c%c%c%c %c%c%c%c%c%c%c%c%c%c %c%c%c%c%c\x1b[0m\n", 219, 219, 219, 219, 220, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219, 219, 219, 223, 223, 219, 219, 219, 219 ,223, 223, 223, 219, 219, 223, 223, 223, 220, 219, 219, 219, 219, 219, 220, 220, 219, 219, 219, 220, 220, 219, 219, 219, 220, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[33m%c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[37m%c%c%c%c%c%c%c %c%c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c%c%c%c %c%c%c%c%c %c%c%c%c%c%c%c %c%c %c%c %c%c %c%c%c%c\x1b[0m\n", 219, 219, 223, 223, 223, 219, 219, 219, 219, 223, 223, 223, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 223, 223, 223, 219, 219, 223, 223, 223, 219, 219, 223, 223, 223, 219 ,219, 219, 219, 223, 223, 219, 219, 219, 219, 223, 223);
printf ("\x1b[1m\x1b[33m%c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[35m%c%c %c%c %c%c %c%c %c%c%c%c%c %c%c%c%c%c %c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c%c%c%c\x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 220, 220, 220, 219, 219, 220, 220, 220, 219, 219, 220, 220, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
}
}
/*
@brief: prints the termination sequence ASCII
@param: theme - integer that dictates the color (cyan/bright red/bright green/purple)
Precondition: assumes theme is between 1 to 4, inclusive
*/
void printEnd(int theme) {
if (theme == 1) { // cyan
printf (" \x1b[1m\x1b[36m%c%c %c%c\n", 220, 220, 220, 220);
printf ("\x1b[1m\x1b[37m %c%c%c %c %c %c%c%c%c %c%c%c%c %c %c%c %c %c %c%c%c %c %c\x1b[0m\x1b[1m\x1b[36m %c%c%c%c%c%c%c%c%c\n", 223, 219, 223, 219, 219, 219, 223, 223, 219, 219, 223, 223, 219, 219, 220, 223, 219, 219, 219, 223, 219, 219, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[37m %c %c%c%c%c %c%c%c%c %c %c %c%c%c %c%c%c %c %c %c %c\x1b[0m\x1b[1m\x1b[36m %c%c%c%c%c%c%c \n", 219, 219, 223, 223, 219, 219, 223, 223, 219, 219, 219, 219, 223, 220, 223, 220, 223, 219, 219, 219, 219, 223, 219, 219, 219, 219, 219, 223);
printf ("\x1b[1m\x1b[37m %c %c %c %c %c %c %c %c %c %c %c%c%c %c%c%c\x1b[0m\x1b[1m\x1b[36m %c%c%c \n\x1b[0m", 219, 219 ,219, 219, 219, 219, 219, 219, 219, 219, 219, 220, 219, 219, 220, 219, 223, 219, 223);
}
else if (theme == 2) { // bright red
printf (" \x1b[1m\x1b[31m%c%c %c%c\n", 220, 220, 220, 220);
printf ("\x1b[1m\x1b[37m %c%c%c %c %c %c%c%c%c %c%c%c%c %c %c%c %c %c %c%c%c %c %c\x1b[0m\x1b[1m\x1b[31m %c%c%c%c%c%c%c%c%c\n", 223, 219, 223, 219, 219, 219, 223, 223, 219, 219, 223, 223, 219, 219, 220, 223, 219, 219, 219, 223, 219, 219, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[37m %c %c%c%c%c %c%c%c%c %c %c %c%c%c %c%c%c %c %c %c %c\x1b[0m\x1b[1m\x1b[31m %c%c%c%c%c%c%c \n", 219, 219, 223, 223, 219, 219, 223, 223, 219, 219, 219, 219, 223, 220, 223, 220, 223, 219, 219, 219, 219, 223, 219, 219, 219, 219, 219, 223);
printf ("\x1b[1m\x1b[37m %c %c %c %c %c %c %c %c %c %c %c%c%c %c%c%c\x1b[0m\x1b[1m\x1b[31m %c%c%c \n\x1b[0m", 219, 219 ,219, 219, 219, 219, 219, 219, 219, 219, 219, 220, 219, 219, 220, 219, 223, 219, 223);
}
else if (theme == 3) { // bright green
printf (" \x1b[1m\x1b[32m%c%c %c%c\n", 220, 220, 220, 220);
printf ("\x1b[1m\x1b[37m %c%c%c %c %c %c%c%c%c %c%c%c%c %c %c%c %c %c %c%c%c %c %c\x1b[0m\x1b[1m\x1b[32m %c%c%c%c%c%c%c%c%c\n", 223, 219, 223, 219, 219, 219, 223, 223, 219, 219, 223, 223, 219, 219, 220, 223, 219, 219, 219, 223, 219, 219, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[37m %c %c%c%c%c %c%c%c%c %c %c %c%c%c %c%c%c %c %c %c %c\x1b[0m\x1b[1m\x1b[32m %c%c%c%c%c%c%c \n", 219, 219, 223, 223, 219, 219, 223, 223, 219, 219, 219, 219, 223, 220, 223, 220, 223, 219, 219, 219, 219, 223, 219, 219, 219, 219, 219, 223);
printf ("\x1b[1m\x1b[37m %c %c %c %c %c %c %c %c %c %c %c%c%c %c%c%c\x1b[0m\x1b[1m\x1b[32m %c%c%c \n\x1b[0m", 219, 219 ,219, 219, 219, 219, 219, 219, 219, 219, 219, 220, 219, 219, 220, 219, 223, 219, 223);
}
else if (theme == 4) { // dark purple
printf (" \x1b[1m\x1b[35m%c%c %c%c\n", 220, 220, 220, 220);
printf ("\x1b[1m\x1b[37m %c%c%c %c %c %c%c%c%c %c%c%c%c %c %c%c %c %c %c%c%c %c %c\x1b[0m\x1b[1m\x1b[35m %c%c%c%c%c%c%c%c%c\n", 223, 219, 223, 219, 219, 219, 223, 223, 219, 219, 223, 223, 219, 219, 220, 223, 219, 219, 219, 223, 219, 219, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[37m %c %c%c%c%c %c%c%c%c %c %c %c%c%c %c%c%c %c %c %c %c\x1b[0m\x1b[1m\x1b[35m %c%c%c%c%c%c%c \n", 219, 219, 223, 223, 219, 219, 223, 223, 219, 219, 219, 219, 223, 220, 223, 220, 223, 219, 219, 219, 219, 223, 219, 219, 219, 219, 219, 223);
printf ("\x1b[1m\x1b[37m %c %c %c %c %c %c %c %c %c %c %c%c%c %c%c%c\x1b[0m\x1b[1m\x1b[35m %c%c%c \n\x1b[0m", 219, 219 ,219, 219, 219, 219, 219, 219, 219, 219, 219, 220, 219, 219, 220, 219, 223, 219, 223);
}
}
/*
@brief: prints the "evade the mine" ASCII
@param: theme - integer that dictates the color (cyan/bright red/bright green/purple)
Precondition: assumes theme is between 1 to 4, inclusive
*/
void printEvade(int theme) {
printf("\n");
if (theme == 1) { // cyan
printf (" \x1b[1m\x1b[31m_------*\x1b[0m\n");
printf ("\x1b[1m\x1b[36m %c%c%c%c%c %c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c %c%c%c%c%c%c %c%c%c%c%c%c %c%c %c%c %c%c%c%c%c\x1b[0m \x1b[1m\x1b[31m_/ \x1b[0m\n", 219, 219, 223, 223, 223, 219, 219, 219, 219, 220, 219, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219, 220, 219, 219, 223, 223, 223, 223, 223, 223, 219, 219, 223, 223, 219, 219, 219, 219, 219, 219, 223, 223, 223);
printf ("\x1b[1m\x1b[37m %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[31m/ / \x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[37m %c%c%c%c %c%c%c %c%c%c %c%c%c%c%c%c%c%c %c%c %c %c%c%c%c %c%c %c%c%c%c%c%c %c%c%c%c\x1b[0m \x1b[1m\x1b[31m/ / \x1b[0m\n", 219, 219, 223, 223, 223, 219, 220, 220, 219, 223, 219, 219, 223, 223, 223, 223, 219 ,219, 219, 219, 219, 219, 219, 223, 223, 219, 219, 219, 219, 223, 223, 219, 219, 219, 219, 223, 223);
printf ("\x1b[1m\x1b[33m %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[31m/ / \x1b[0m\n", 219, 219, 223, 219, 219, 223, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[36m %c%c%c%c%c %c%c%c %c%c %c%c %c%c%c%c%c %c%c%c%c%c%c %c%c %c%c %c%c %c%c%c%c%c\x1b[0m \x1b[1m\x1b[31m/ / \x1b[0m\n", 219, 219, 220, 220, 220, 223, 219, 223, 219, 219, 219, 219, 219, 219, 219, 219, 223, 219, 219, 220, 220, 220, 220, 219, 219, 219, 219, 219 ,219, 219, 219, 220, 220, 220);
printf (" \x1b[1m\x1b[31m(_)\x1b[0m\n");
}
else if (theme == 2) { // bright red
printf (" \x1b[1m\x1b[31m_------*\x1b[0m\n");
printf ("\x1b[1m\x1b[31m %c%c%c%c%c %c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c %c%c%c%c%c%c %c%c%c%c%c%c %c%c %c%c %c%c%c%c%c\x1b[0m \x1b[1m\x1b[31m_/ \x1b[0m\n", 219, 219, 223, 223, 223, 219, 219, 219, 219, 220, 219, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219, 220, 219, 219, 223, 223, 223, 223, 223, 223, 219, 219, 223, 223, 219, 219, 219, 219, 219, 219, 223, 223, 223);
printf ("\x1b[1m\x1b[37m %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[31m/ / \x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[37m %c%c%c%c %c%c%c %c%c%c %c%c%c%c%c%c%c%c %c%c %c %c%c%c%c %c%c %c%c%c%c%c%c %c%c%c%c\x1b[0m \x1b[1m\x1b[31m/ / \x1b[0m\n", 219, 219, 223, 223, 223, 219, 220, 220, 219, 223, 219, 219, 223, 223, 223, 223, 219 ,219, 219, 219, 219, 219, 219, 223, 223, 219, 219, 219, 219, 223, 223, 219, 219, 219, 219, 223, 223);
printf ("\x1b[1m\x1b[33m %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[31m/ / \x1b[0m\n", 219, 219, 223, 219, 219, 223, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[31m %c%c%c%c%c %c%c%c %c%c %c%c %c%c%c%c%c %c%c%c%c%c%c %c%c %c%c %c%c %c%c%c%c%c\x1b[0m \x1b[1m\x1b[31m/ / \x1b[0m\n", 219, 219, 220, 220, 220, 223, 219, 223, 219, 219, 219, 219, 219, 219, 219, 219, 223, 219, 219, 220, 220, 220, 220, 219, 219, 219, 219, 219 ,219, 219, 219, 220, 220, 220);
printf (" \x1b[1m\x1b[31m(_)\x1b[0m\n");
}
else if (theme == 3) { // bright green
printf (" \x1b[1m\x1b[31m_------*\x1b[0m\n");
printf ("\x1b[1m\x1b[32m %c%c%c%c%c %c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c %c%c%c%c%c%c %c%c%c%c%c%c %c%c %c%c %c%c%c%c%c\x1b[0m \x1b[1m\x1b[31m_/ \x1b[0m\n", 219, 219, 223, 223, 223, 219, 219, 219, 219, 220, 219, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219, 220, 219, 219, 223, 223, 223, 223, 223, 223, 219, 219, 223, 223, 219, 219, 219, 219, 219, 219, 223, 223, 223);
printf ("\x1b[1m\x1b[37m %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[31m/ / \x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[37m %c%c%c%c %c%c%c %c%c%c %c%c%c%c%c%c%c%c %c%c %c %c%c%c%c %c%c %c%c%c%c%c%c %c%c%c%c\x1b[0m \x1b[1m\x1b[31m/ / \x1b[0m\n", 219, 219, 223, 223, 223, 219, 220, 220, 219, 223, 219, 219, 223, 223, 223, 223, 219 ,219, 219, 219, 219, 219, 219, 223, 223, 219, 219, 219, 219, 223, 223, 219, 219, 219, 219, 223, 223);
printf ("\x1b[1m\x1b[33m %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[31m/ / \x1b[0m\n", 219, 219, 223, 219, 219, 223, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[32m %c%c%c%c%c %c%c%c %c%c %c%c %c%c%c%c%c %c%c%c%c%c%c %c%c %c%c %c%c %c%c%c%c%c\x1b[0m \x1b[1m\x1b[31m/ / \x1b[0m\n", 219, 219, 220, 220, 220, 223, 219, 223, 219, 219, 219, 219, 219, 219, 219, 219, 223, 219, 219, 220, 220, 220, 220, 219, 219, 219, 219, 219 ,219, 219, 219, 220, 220, 220);
printf (" \x1b[1m\x1b[31m(_)\x1b[0m\n");
}
else if (theme == 4) { // dark purple
printf (" \x1b[1m\x1b[31m_------*\x1b[0m\n");
printf ("\x1b[1m\x1b[35m %c%c%c%c%c %c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c %c%c%c%c%c%c %c%c%c%c%c%c %c%c %c%c %c%c%c%c%c\x1b[0m \x1b[1m\x1b[31m_/ \x1b[0m\n", 219, 219, 223, 223, 223, 219, 219, 219, 219, 220, 219, 219, 219, 219, 219, 219, 220, 219, 219, 219, 219, 220, 219, 219, 223, 223, 223, 223, 223, 223, 219, 219, 223, 223, 219, 219, 219, 219, 219, 219, 223, 223, 223);
printf ("\x1b[1m\x1b[37m %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[31m/ / \x1b[0m\n", 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[37m %c%c%c%c %c%c%c %c%c%c %c%c%c%c%c%c%c%c %c%c %c %c%c%c%c %c%c %c%c%c%c%c%c %c%c%c%c\x1b[0m \x1b[1m\x1b[31m/ / \x1b[0m\n", 219, 219, 223, 223, 223, 219, 220, 220, 219, 223, 219, 219, 223, 223, 223, 223, 219 ,219, 219, 219, 219, 219, 219, 223, 223, 219, 219, 219, 219, 223, 223, 219, 219, 219, 219, 223, 223);
printf ("\x1b[1m\x1b[33m %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c\x1b[0m \x1b[1m\x1b[31m/ / \x1b[0m\n", 219, 219, 223, 219, 219, 223, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219);
printf ("\x1b[1m\x1b[35m %c%c%c%c%c %c%c%c %c%c %c%c %c%c%c%c%c %c%c%c%c%c%c %c%c %c%c %c%c %c%c%c%c%c\x1b[0m \x1b[1m\x1b[31m/ / \x1b[0m\n", 219, 219, 220, 220, 220, 223, 219, 223, 219, 219, 219, 219, 219, 219, 219, 219, 223, 219, 219, 220, 220, 220, 220, 219, 219, 219, 219, 219 ,219, 219, 219, 220, 220, 220);
printf (" \x1b[1m\x1b[31m(_)\x1b[0m\n");
}
}
/*
@brief: extracts the current date and formats it as an integer code
@return: integer of the format MMDDYYYY (MM - month, DD - day, YYYY - year)
*/
int getDateCode() {
time_t t = time(NULL);
struct tm tm = *localtime(&t);
return (tm.tm_mon + 1) * 1000000 + tm.tm_mday * 10000 + tm.tm_year + 1900;
}
/*
@brief: updates the current profile struct's statistics based on the current game outcome
@param: CurrentProfile - pointer to the current profile structure holding profile information
Precondition: assumes a game has recently concluded
*/
void updateStatistics(struct Profile *CurrentProfile) {
string20 mode;
strcpy(mode, CurrentProfile->CurrentGame.mode);
int seconds = CurrentProfile->CurrentGame.seconds;
if (strcmp(CurrentProfile->CurrentGame.outcome, WON_OUTCOME) == 0) { // won
if (strcmp(mode, EASY_MODE) == 0) {
CurrentProfile->EasyStats.won++;
CurrentProfile->EasyStats.totalSeconds += seconds;
}
else if (strcmp(mode, DIFFICULT_MODE) == 0) {
CurrentProfile->DifficultStats.won++;
CurrentProfile->DifficultStats.totalSeconds += seconds;
}
else if (strcmp(mode, CUSTOM_MODE) == 0) {
CurrentProfile->CustomStats.won++;
CurrentProfile->CustomStats.totalSeconds += seconds;
}
}
else { // lost/quit
if (strcmp(mode, EASY_MODE) == 0) {
CurrentProfile->EasyStats.lost++;
}
else if (strcmp(mode, DIFFICULT_MODE) == 0) {
CurrentProfile->DifficultStats.lost++;
}
else if (strcmp(mode, CUSTOM_MODE) == 0) {
CurrentProfile->CustomStats.lost++;
}
}
}
/*
@brief: updates the current profile's struct's recent games
@param: CurrentProfile - pointer to the current profile structure holding profile information
Precondition: assumes a game has recently concluded
*/
void updateRecentGames(struct Profile *CurrentProfile) {
int i, j;
// set recent game 3's details to that of recent game 2's
if (CurrentProfile->RecentGame2.exists) {
CurrentProfile->RecentGame3 = CurrentProfile->RecentGame2;
}
// set recent game 2's details to that of recent game 1's
if (CurrentProfile->RecentGame1.exists) {
CurrentProfile->RecentGame2 = CurrentProfile->RecentGame1;
}
// set recent game 1's details to that of the current game's
if (CurrentProfile->CurrentGame.exists) {
CurrentProfile->RecentGame1 = CurrentProfile->CurrentGame;
// reset current board's details
CurrentProfile->CurrentGame.rows = 0;
CurrentProfile->CurrentGame.columns = 0;
for (i = 0; i < MAX_ROWS; i++) {
for (j = 0; j < MAX_COLUMNS; j++) {
CurrentProfile->CurrentGame.Board[i][j].state = 0;
CurrentProfile->CurrentGame.Board[i][j].isFlagged = 0;
CurrentProfile->CurrentGame.Board[i][j].isRevealed = 0;
}
}
strcpy(CurrentProfile->CurrentGame.mode, "");
strcpy(CurrentProfile->CurrentGame.outcome, "");
CurrentProfile->CurrentGame.seconds = 0;
}
}
/*
@brief: converts a tile into a 3-4 digit code for storing information
@param: row - the row of the tile
@param: column - the column of the tile
@param: Board - a 2-dimensional array of tiles representing the board where the tile belongs
@return: 3-4 digit integer representing the tile's code
Precondition: assumes row and column are not out of bounds
*/
int getTileCode(int row, int column, struct Tile Board[][MAX_COLUMNS]) {
int code = 0;
code += Board[row][column].state * 100;
code += Board[row][column].isFlagged * 10;
code += Board[row][column].isRevealed;
return code;
}
/*
@brief: access the current profile's text file and update it in accordance with the struct's
contents
@param: CurrentProfile - pointer to the current profile struct that we will be using to update
their text file
Precondition: the current profile name corresponds with the actual profile being updated
*/
void updateProfile(struct Profile *CurrentProfile) {
FILE *fp;
int i, j;
string100 directory = "profiles\\";
strcat(directory, CurrentProfile->name);
strcat(directory, ".txt");
updateStatistics(CurrentProfile);
updateRecentGames(CurrentProfile);
fp = fopen(directory, "w");
if (fp == NULL) return;
struct Game *RecentGame1 = &CurrentProfile->RecentGame1;
struct Game *RecentGame2 = &CurrentProfile->RecentGame2;
struct Game *RecentGame3 = &CurrentProfile->RecentGame3;
// player information and statistics
fprintf(fp, "%s\n%d\n%d\n\n", CurrentProfile->name, CurrentProfile->creationDate, CurrentProfile->lifetimeGames);
fprintf(fp, "%d\n%d\n%d\n\n", CurrentProfile->EasyStats.totalSeconds, CurrentProfile->EasyStats.won,
CurrentProfile->EasyStats.lost);
fprintf(fp, "%d\n%d\n%d\n\n", CurrentProfile->DifficultStats.totalSeconds, CurrentProfile->DifficultStats.won,
CurrentProfile->DifficultStats.lost);
fprintf(fp, "%d\n%d\n%d\n\n", CurrentProfile->CustomStats.totalSeconds, CurrentProfile->CustomStats.won,
CurrentProfile->CustomStats.lost);
// recent game 1
fprintf(fp, "%d\n", RecentGame1->exists);
if (RecentGame1->exists) {
fprintf(fp, "%d %d\n", RecentGame1->rows, RecentGame1->columns);
for (i = 0; i < RecentGame1->rows; i++) {
for (j = 0; j < RecentGame1->columns; j++) {
fprintf(fp, "%d ", getTileCode(i, j, RecentGame1->Board));
}
fprintf(fp, "\n");
}
fprintf(fp, "%s\n%s\n", RecentGame1->mode, RecentGame1->outcome);
fprintf(fp, "%d\n", RecentGame1->seconds);
}
// recent game 2
fprintf(fp, "\n%d\n", RecentGame2->exists);
if (RecentGame2->exists) {
fprintf(fp, "%d %d\n", RecentGame2->rows, RecentGame2->columns);
for (i = 0; i < RecentGame2->rows; i++) {
for (j = 0; j < RecentGame2->columns; j++) {
fprintf(fp, "%d ", getTileCode(i, j, RecentGame2->Board));
}
fprintf(fp, "\n");
}
fprintf(fp, "%s\n%s\n", RecentGame2->mode, RecentGame2->outcome);
fprintf(fp, "%d\n", RecentGame2->seconds);
}
// recent game 3
fprintf(fp, "\n%d\n", RecentGame3->exists);
if (RecentGame3->exists) {
fprintf(fp, "%d %d\n", RecentGame3->rows, RecentGame3->columns);
for (i = 0; i < RecentGame3->rows; i++) {
for (j = 0; j < RecentGame3->columns; j++) {
fprintf(fp, "%d ", getTileCode(i, j, RecentGame3->Board));
}
fprintf(fp, "\n");
}
fprintf(fp, "%s\n%s\n", RecentGame3->mode, RecentGame3->outcome);
fprintf(fp, "%d\n", RecentGame3->seconds);
}
fclose(fp);
}
/*
@brief: initializes the values of the current profile's information and statistics to default
values, except for the creation date
@param: CurrentProfile - pointer to the current profile's struct that we want to initialize
@param: name - the profile's name
Precondition: The profile is being created or reset. MAX_ROWS and MAX_COLUMNS are accurate.
*/
void initializeProfile(struct Profile *CurrentProfile, char name[]) {
int i, j;
struct Game *CurrentGame = &CurrentProfile->CurrentGame;
strcpy(CurrentProfile->name, name);
CurrentProfile->lifetimeGames = 0;
CurrentProfile->EasyStats.totalSeconds = 0;
CurrentProfile->EasyStats.won = 0;
CurrentProfile->EasyStats.lost = 0;
CurrentProfile->DifficultStats.totalSeconds = 0;
CurrentProfile->DifficultStats.won = 0;
CurrentProfile->DifficultStats.lost = 0;
CurrentProfile->CustomStats.totalSeconds = 0;
CurrentProfile->CustomStats.won = 0;
CurrentProfile->CustomStats.lost = 0;
CurrentGame->exists = 0;
CurrentGame->rows = 0;
CurrentGame->columns = 0;
for (i = 0; i < MAX_ROWS; i++) {
for (j = 0; j < MAX_COLUMNS; j++) {
CurrentGame->Board[i][j].state = 0;
CurrentGame->Board[i][j].isFlagged = 0;
CurrentGame->Board[i][j].isRevealed = 0;
}
}
strcpy(CurrentGame->mode, "");
strcpy(CurrentGame->outcome, "");
CurrentGame->seconds = 0;
CurrentProfile->RecentGame1.exists = 0;
CurrentProfile->RecentGame2.exists = 0;
CurrentProfile->RecentGame3.exists = 0;
updateProfile(CurrentProfile);
}
/*
@brief: initializes the values of the current leaderboard's statistics to default values
@param: CurrentLeaderboard - pointer to the leaderboard struct containing information regarding
the top records for each game mode
Precondition: MAX_RECORDS is accurate.
*/
void initializeLeaderboard(struct Leaderboard *CurrentLeaderboard) {
int i;
struct Records *EasyRecords = &CurrentLeaderboard->EasyRecords;
struct Records *DifficultRecords = &CurrentLeaderboard->DifficultRecords;
struct Records *CustomRecords = &CurrentLeaderboard->CustomRecords;
EasyRecords->numRecords = 0;
DifficultRecords->numRecords = 0;
CustomRecords->numRecords = 0;
for (i = 0; i < MAX_RECORDS; i++) {
strcpy(EasyRecords->names[i], "");
EasyRecords->times[i] = 0;
strcpy(DifficultRecords->names[i], "");
DifficultRecords->times[i] = 0;
strcpy(CustomRecords->names[i], "");
CustomRecords->times[i] = 0;
}
}
/*
@brief: extracts information from leaderboard.txt and stores it into leaderboard struct
@param: CurrentLeaderboard - pointer to the current leaderboard struct that we want to store
information into
Precondition: The leaderboard text file is formatted correctly. LEADERBOARD_DIRECTORY is
accurate.
*/
void loadLeaderboard(struct Leaderboard *CurrentLeaderboard) {
FILE *fp;
int i;
fp = fopen(LEADERBOARD_DIRECTORY, "r");
if (fp == NULL) {
fp = fopen(LEADERBOARD_DIRECTORY, "w");
fprintf(fp, "0\n\n0\n\n0\n");
fclose(fp);
loadLeaderboard(CurrentLeaderboard);
return;
}
// easy leaderboard
fscanf(fp, "%d", &CurrentLeaderboard->EasyRecords.numRecords);
for (i = 0; i < CurrentLeaderboard->EasyRecords.numRecords; i++) {
fscanf(fp, "%s", CurrentLeaderboard->EasyRecords.names[i]);
fscanf(fp, "%d", &CurrentLeaderboard->EasyRecords.times[i]);
}
// difficult leaderboard
fscanf(fp, "%d", &CurrentLeaderboard->DifficultRecords.numRecords);
for (i = 0; i < CurrentLeaderboard->DifficultRecords.numRecords; i++) {
fscanf(fp, "%s", CurrentLeaderboard->DifficultRecords.names[i]);
fscanf(fp, "%d", &CurrentLeaderboard->DifficultRecords.times[i]);
}
// custom leaderboard
fscanf(fp, "%d", &CurrentLeaderboard->CustomRecords.numRecords);
for (i = 0; i < CurrentLeaderboard->CustomRecords.numRecords; i++) {
fscanf(fp, "%s", CurrentLeaderboard->CustomRecords.names[i]);
fscanf(fp, "%d", &CurrentLeaderboard->CustomRecords.times[i]);
}
fclose(fp);
}
/*
@brief: clears the input buffer after a user response
*/
void clearInputBuffer() {
char c;
do {
c = getchar();
} while (c != '\n' && c != EOF);
}
/*
@brief: sorts the profile names in alphabetical order using the selection sort algorithm
@param: ProfileNames - array containing the list of existing profiles
@param: n - indicates how many profiles are in the array
*/
void sortProfileNames(string20 ProfileNames[], int n) {
int i, j;
int index;
string20 temp;
for (i = 0; i < n - 1; i++) {
index = i;
for (j = i + 1; j < n; j++) {
if (strcmp(ProfileNames[j], ProfileNames[index]) < 0) {
index = j;
}
}
if (i != index) {
strcpy(temp, ProfileNames[i]);
strcpy(ProfileNames[i], ProfileNames[index]);
strcpy(ProfileNames[index], temp);
}
}
}
/*
@brief: stores the profiles in profiles directory into the ProfileNames[] array
@param: ProfileNames - array of strings containing the existing profile names
Precondition: PROFILES_DIRECTORY is accurate.
@return: the number of profiles successfully read from the profiles text file
*/
int getProfileNames(string20 ProfileNames[]) {
FILE *fp;
string20 name;
int numProfiles = 0;
fp = fopen(PROFILES_DIRECTORY, "r");
if (fp == NULL) {
fp = fopen(PROFILES_DIRECTORY, "w");
fclose(fp);
return getProfileNames(ProfileNames);
}
while (fscanf(fp, "%s", name) == 1) {
if (strcmp(name, "") != 0) {
strcpy(ProfileNames[numProfiles++], name);
}
}
sortProfileNames(ProfileNames, numProfiles);
fclose(fp);
return numProfiles;
}
/*
@brief: prints a divider consisting of several dashes to aid in display formatting
*/
void printDivider() {
printf(" \x1b[1m\x1b[37m----------------------------------------------------------------------------\x1b[0m");
}
/*
@brief: prints a list of existing profiles
@param: theme - integer that dictates the color (cyan/bright red/bright green/purple)
*/
void printProfiles(int theme) {
int i;
string20 profileNames[MAX_PROFILES];
int numProfiles = getProfileNames(profileNames);
printEvade(theme);
printf("\n Here are the existing profiles:\n\n");
for (i = 0; i < numProfiles; i++) {
printf(" %d.) %s\n", i + 1, profileNames[i]);
}
}
/*
@brief: capitalizes all the letters of a string
@param: string - the string to be capitalized
Precondition: The string only consists of letters from the English alphabet.
*/
void toUpperCaseString(string20 string) {
for (int i = 0; i < strlen(string); i++) {
string[i] = toupper(string[i]);
}
}
/*
@brief: checks if a particular profile exists
@param: name - the name being checked
@return: 1 - profile exists
0 - profile does not exist
*/
int profileExists(string20 name) {
int i;
string20 ProfileNames[10];
int numProfiles = getProfileNames(ProfileNames);
toUpperCaseString(name);
for (i = 0; i < numProfiles; i++) {
if (strcmp(name, ProfileNames[i]) == 0) {
return 1;
}
}
return 0;
}
/*
@brief: extracts information from the current profile's text file and stores it into the current
profile structure
@param: CurrentProfile - pointer to the structure holding the current profile information
@param: name - name of the profile
Precondition: The profile text file being loaded stores the profile information in a correct,
accurate format.
*/
void loadProfile(struct Profile *CurrentProfile, string20 name) {
FILE *fp;
int i, j;
int code;
struct Game *RecentGame1 = &CurrentProfile->RecentGame1;
struct Game *RecentGame2 = &CurrentProfile->RecentGame2;
struct Game *RecentGame3 = &CurrentProfile->RecentGame3;
string100 directory = "profiles\\";
strcat(directory, name);
strcat(directory, ".txt");
fp = fopen(directory, "r");
if (fp == NULL) {
CurrentProfile->creationDate = getDateCode();
initializeProfile(CurrentProfile, name);
loadProfile(CurrentProfile, name);
return;
}
// current profile information
fscanf(fp, "%s", CurrentProfile->name);
fscanf(fp, "%d", &CurrentProfile->creationDate);
fscanf(fp, "%d", &CurrentProfile->lifetimeGames);
// easy statistics
fscanf(fp, "%d", &CurrentProfile->EasyStats.totalSeconds);
fscanf(fp, "%d", &CurrentProfile->EasyStats.won);
fscanf(fp, "%d", &CurrentProfile->EasyStats.lost);
// difficult statistics
fscanf(fp, "%d", &CurrentProfile->DifficultStats.totalSeconds);
fscanf(fp, "%d", &CurrentProfile->DifficultStats.won);
fscanf(fp, "%d", &CurrentProfile->DifficultStats.lost);
// custom statistics
fscanf(fp, "%d", &CurrentProfile->CustomStats.totalSeconds);
fscanf(fp, "%d", &CurrentProfile->CustomStats.won);
fscanf(fp, "%d", &CurrentProfile->CustomStats.lost);
// recent game 1
fscanf(fp, "%d", &RecentGame1->exists);
if (RecentGame1->exists) {
fscanf(fp, "%d", &RecentGame1->rows);
fscanf(fp, "%d", &RecentGame1->columns);
// recent game 1 board
for (i = 0; i < RecentGame1->rows; i++) {
for (j = 0; j < RecentGame1->columns; j++) {
fscanf(fp, "%d", &code);
RecentGame1->Board[i][j].state = code / 100;
RecentGame1->Board[i][j].isFlagged = code / 10 % 10;
RecentGame1->Board[i][j].isRevealed = code % 10;
}
}
fscanf(fp, "%s", RecentGame1->mode);
fscanf(fp, "%s", RecentGame1->outcome);
fscanf(fp, "%d", &RecentGame1->seconds);
}
// recent game 2
fscanf(fp, "%d", &RecentGame2->exists);
if (RecentGame2->exists) {
fscanf(fp, "%d", &RecentGame2->rows);
fscanf(fp, "%d", &RecentGame2->columns);
// recent game 2 board
for (i = 0; i < RecentGame2->rows; i++) {
for (j = 0; j < RecentGame2->columns; j++) {
fscanf(fp, "%d", &code);
RecentGame2->Board[i][j].state = code / 100;
RecentGame2->Board[i][j].isFlagged = code / 10 % 10;
RecentGame2->Board[i][j].isRevealed = code % 10;
}
}
fscanf(fp, "%s", RecentGame2->mode);
fscanf(fp, "%s", RecentGame2->outcome);
fscanf(fp, "%d", &RecentGame2->seconds);
}
// recent game 3
fscanf(fp, "%d", &RecentGame3->exists);
if (RecentGame3->exists) {
fscanf(fp, "%d", &RecentGame3->rows);
fscanf(fp, "%d", &RecentGame3->columns);
// recent game 3 board
for (i = 0; i < RecentGame3->rows; i++) {
for (j = 0; j < RecentGame3->columns; j++) {
fscanf(fp, "%d", &code);
RecentGame3->Board[i][j].state = code / 100;
RecentGame3->Board[i][j].isFlagged = code / 10 % 10;
RecentGame3->Board[i][j].isRevealed = code % 10;
}
}
fscanf(fp, "%s", RecentGame3->mode);
fscanf(fp, "%s", RecentGame3->outcome);
fscanf(fp, "%d", &RecentGame3->seconds);
}
}
/*
@brief: prompts the user to press enter to return to the main menu
*/
void pressEnter() {
printf(" Press 'Enter' to return to the Main Menu.");
clearInputBuffer();
}
/*
@brief: prompts the user to select an existing profile from the profile directory
@param: CurrentProfile - pointer to the structure holding the current profile information
@param: theme - integer that dictates the color (cyan/bright red/bright green/purple)
Precondition: The list of profiles is accurate.
*/
void selectProfile(struct Profile *CurrentProfile, int theme) {
string20 profile;
int exists;
do {
Sleep(SHORT_SLEEP);
system("cls");
printf("\n");
printDivider();
printf("\n");
printProfiles(theme);
printf("\n");
printDivider();
printf("\n\n Enter an existing profile to load (or '0' to return to the main menu): ");
scanf("%s", profile);
clearInputBuffer();
if (strcmp(profile, "0") == 0) {
return;
}
exists = profileExists(profile);
if (!exists) {
printf("\n The profile '%s' does not exist.", profile);
}
} while (!exists);
// account change processing
remove("profiles\\GUEST.txt");
Sleep(SHORT_SLEEP);
printf("\n Successful.");
Sleep(SHORT_SLEEP);
printf(" The current profile has been changed from '%s' to '%s'.", CurrentProfile->name, profile);
loadProfile(CurrentProfile, profile); // load the selected profile's information
Sleep(LONG_SLEEP);
printf("\n\n");
pressEnter();
}