-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.h
More file actions
1224 lines (975 loc) · 30.7 KB
/
Copy pathfunctions.h
File metadata and controls
1224 lines (975 loc) · 30.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Importando o arquivo de constantes
#include "constants.h"
/*
Checa se o começo do string a contém o string b. Bom para comparar as linhas de
dados dos jogadores, que começa com o seu nome
Exemplo: LycalopX 0 0 0 0 0
*/
int StartsWith(const char *a, const char *b)
{
if (strncmp(a, b, strlen(b)) == 0)
{
return 1;
}
return 0;
}
/*
Retorna valores aleatórios no intervalo fornecido
Usado para criar as bombas no mapa do jogo
*/
int printRandoms(int lower, int upper, int count)
{
int i;
for (i = 0; i < count; i++)
{
int num = (rand() %
(upper - lower + 1)) +
lower;
return num;
}
return 0;
}
/*
Interface de seleção do modo de jogo
Altera algumas variáveis que indicam a dificuldade do jogo para o arquivo principal
criar o tabuleiro (i.e. quantidade de bombas, tamanho da matriz, etc...)
*/
void selection(int *pointer1, int *pointer2, char fileName[11])
{
// Retoma os ponteiros, para armazenar o tamanho da matriz
// e a quantidade de bombas selecionado pelo usuário
int option;
// Assegurar que uma dificuldade seja escolhida
int loop = 1;
// Escolher modo de jogo
do
{
// Selecionar modo de jogo
printf("\n\nSeja bem-vindo a campo minado!\n"
"\nEscolha modo de jogo: \n\033[0;36m---------------------------------------------\x1b[0m\n1. \033[0;32mF%ccil \n\x1b[0m2. \033[0;34mIntermedi%crio \n\x1b[0m3. \033[0;31mEspecialista (20 minutos ou mais de jogo)\n\x1b[0m4. \033[0;30mUltranightmare (imposs%cvel)\n\033[0;36m---------------------------------------------\x1b[0m\n\nModo: ", 225, 225, 237);
scanf("%i", &option);
loop = 1;
// Opções escolhidas pelo usuário
switch (option)
{
case 1:
*pointer1 = 9;
*pointer2 = 10;
strcpy(fileName, "stats1.txt");
break;
case 2:
*pointer1 = 16;
*pointer2 = 40;
strcpy(fileName, "stats2.txt");
break;
case 3:
*pointer1 = 30;
*pointer2 = 99;
strcpy(fileName, "stats3.txt");
break;
case 4:
*pointer1 = 81;
*pointer2 = 729;
break;
default:
printf("\nValor invalido!\n");
loop = 0;
}
} while (loop == 0);
}
/*
Imprimir a matriz atual do tabuleiro (útil para encontrar bugs de programação)
Usado toda a vez que o usuário faz um movimento
*/
void printOut(int *pointer1, struct block **Matrix)
{
int uppermatrix = *pointer1;
// Números
printf("\n ");
for (int x = 0; x < uppermatrix; x++)
{
if (x > 9)
{
printf("%3i ", x);
continue;
}
printf("%3i ", x);
}
printf("\n ");
// Player Matrix
for (int i = 0; i < uppermatrix; i++)
{
for (int p = 0; p < uppermatrix; p++)
{
printf("|%c%c%c|", 175, 175, 175);
}
printf("\n%c", alphabet[i]);
for (int j = 0; j < uppermatrix; j++)
{
int type = Matrix[i][j].type;
int revealed = Matrix[i][j].revealed;
int flag = Matrix[i][j].flag;
if (flag)
{
printf("| \033[1m\033[31m%c \x1b[0m|", 254);
continue;
}
if (revealed == 0)
{
printf("| \x1b[1m%c\x1b[0m |", 164);
continue;
}
if (type != 0)
{
printf("| \x1b[%im%i \x1b[0m|", type + 30, type);
}
else
{
printf("| |");
}
}
printf("\n ");
for (int p = 0; p < uppermatrix; p++)
{
printf("|___|");
}
printf("\n ");
}
}
/*
Ler para cada movimento, se as casas ao lado também serão reveladas...
Importante, além de que depende do tabuleiro já ter sido criado para funcionar.
Sintaxe: i, j, uppermatrix, counter, Matrix
*/
void read(int i, int j, int uppermatrix, int *pointer2, struct block **Matrix)
{
// Se existe uma coordenada das matriz em uma das direções
int conditionleft = (j - 1) >= 0;
int conditionright = j + 1 < uppermatrix;
int conditionup = (i - 1) >= 0;
int conditiondown = i + 1 < uppermatrix;
// Se já tiver sido revelado esse bloco, parar imediatamente
if (Matrix[i][j].revealed == 1)
{
return;
}
// Se objeto for entre 1 e 8 pontos, revelar esse, e parar imediatamente
else if (Matrix[i][j].type != 0 && Matrix[i][j].type != 9)
{
Matrix[i][j].revealed = 1;
(*pointer2)++;
return;
}
// Revela o objeto, para que as funções decorrentes dessa não repitam a mesma casa, e o jogo
// inteiro se encontre me um loop infinito...
else
{
Matrix[i][j].revealed = 1;
(*pointer2)++;
}
// Essencialmente, a checagem de casas reveladas surgiu da necessidade de garantir que
// o AI não precisasse revelar a mesma casa mais de uma vez, além de evitar loops
// Por isso, toda a vez que o bloco é checado, ele tem sua propriedade de revealed
// modificada para 1
// Se o bloco a esquerda existir
if (conditionleft)
{
struct block left = Matrix[i][j - 1];
// Se o bloco à esquerda e para cima existir
if (conditionup)
{
struct block upleft = Matrix[i - 1][j - 1];
if (upleft.revealed == 0)
{
if (upleft.type == 0)
{
read(i - 1, (j - 1), uppermatrix, pointer2, Matrix);
}
else
{
Matrix[i - 1][j - 1].revealed = 1;
(*pointer2)++;
}
}
}
// Se o bloco à esquerda e para cima baixo
if (conditiondown)
{
struct block downleft = Matrix[i + 1][j - 1];
if (downleft.revealed == 0)
{
if (downleft.type == 0)
{
read(i + 1, (j - 1), uppermatrix, pointer2, Matrix);
}
else
{
Matrix[i + 1][j - 1].revealed = 1;
(*pointer2)++;
}
}
}
// Se o bloco à esquerda não tiver sido revelado
if (left.revealed == 0)
{
if (left.type == 0)
{
read(i, (j - 1), uppermatrix, pointer2, Matrix);
}
else
{
Matrix[i][j - 1].revealed = 1;
(*pointer2)++;
}
}
}
// Se o bloco a direita existir
if (conditionright)
{
struct block right = Matrix[i][j + 1];
if (conditionup)
{
struct block upright = Matrix[i - 1][j + 1];
if (upright.revealed == 0)
{
if (upright.type == 0)
{
read(i - 1, (j + 1), uppermatrix, pointer2, Matrix);
}
else
{
Matrix[i - 1][j + 1].revealed = 1;
(*pointer2)++;
}
}
}
if (conditiondown)
{
struct block downright = Matrix[i + 1][j + 1];
if (downright.revealed == 0)
{
if (downright.type == 0)
{
read(i + 1, (j + 1), uppermatrix, pointer2, Matrix);
}
else
{
Matrix[i + 1][j + 1].revealed = 1;
(*pointer2)++;
}
}
}
if (right.revealed == 0)
{
if (right.type == 0)
{
read(i, j + 1, uppermatrix, pointer2, Matrix);
}
else
{
Matrix[i][j + 1].revealed = 1;
(*pointer2)++;
}
}
}
// Se o bloco para cima existir
if (conditionup)
{
struct block up = Matrix[i - 1][j];
if (up.revealed == 0)
{
if (up.type == 0)
{
read(i - 1, j, uppermatrix, pointer2, Matrix);
}
else
{
Matrix[i - 1][j].revealed = 1;
(*pointer2)++;
}
}
}
// Se o bloco para baixo existir
if (conditiondown)
{
struct block down = Matrix[i + 1][j];
if (down.revealed == 0)
{
if (down.type == 0)
{
read(i + 1, j, uppermatrix, pointer2, Matrix);
}
else
{
Matrix[i + 1][j].revealed = 1;
(*pointer2)++;
}
}
}
return;
};
// Dar uma função à cada bloco, e já confirmar a soma de bombas em nos 8 blocos à sua volta
// Sintaxe: i, j, uppermatrix, Matrix
void setUp(int i, int j, int *pointer1, struct block **Matrix)
{
int uppermatrix = *pointer1;
// Condições para blocos existirem
int conditionup = (i - 1) >= 0;
int conditiondown = i + 1 < uppermatrix;
int conditionright = j + 1 < uppermatrix;
int conditionleft = (j - 1) >= 0;
// Soma de bombas à sua volta
int sum = 0;
if (conditionright)
{
struct block right = Matrix[i][j + 1];
if (right.type == 9)
{
sum++;
}
if (conditionup)
{
struct block upright = Matrix[i - 1][j + 1];
if (upright.type == 9)
{
sum++;
}
}
if (conditiondown)
{
struct block downright = Matrix[i + 1][j + 1];
if (downright.type == 9)
{
sum++;
}
}
}
if (conditionleft)
{
struct block left = Matrix[i][j - 1];
if (left.type == 9)
{
sum++;
}
if (conditionup)
{
struct block upleft = Matrix[i - 1][j - 1];
if (upleft.type == 9)
{
sum++;
}
}
if (conditiondown)
{
struct block downleft = Matrix[i + 1][j - 1];
if (downleft.type == 9)
{
sum++;
}
}
}
if (conditionup)
{
struct block up = Matrix[i - 1][j];
if (up.type == 9)
{
sum++;
}
}
if (conditiondown)
{
struct block down = Matrix[i + 1][j];
if (down.type == 9)
{
sum++;
}
}
Matrix[i][j].type = sum;
return;
};
/*
Gera todas as bombas no campo, tendo certeza de não colocá-las em um raio de um bloco do jogador
(nos oito à sua volta)
*/
void GeradorDeCampoDeMinas(int c1, int c2, int i, int j, int *pointer1, int *pointer2, struct block **Matrix)
{
int uppermatrix = *pointer1;
int bombcount = *pointer2;
// Mapeando bombas
for (int n = 0; n < bombcount;)
{
c1 = printRandoms(0, uppermatrix - 1, bombcount);
c2 = printRandoms(0, uppermatrix - 1, bombcount);
// Tendo certeza de que não estamos colocando uma bomba duplicata, assim como não criando uma bomba
// no lugar onde já foi revelado (i,j)
if (Matrix[c1][c2].type == 9 || (abs(i - c1) == 1 && abs(j - c2) == 1) || (abs(i - c1) == 1 && abs(j - c2) == 0) || (abs(i - c1) == 0 && abs(j - c2) == 1) || (c1 == i && c2 == j))
{
continue;
}
else
{
Matrix[c1][c2].type = 9;
}
n++;
}
// Preparando os blocos não bomba
for (int i = 0; i < uppermatrix; i++)
{
for (int j = 0; j < uppermatrix; j++)
{
if (Matrix[i][j].type == 9)
{
continue;
}
setUp(i, j, pointer1, Matrix);
}
}
}
// Quando informado tempo em milisegundos, ele converte para o formato desejado
int findSeconds(int time)
{
int seconds = (time) % 60;
return seconds;
}
int findMinutes(int time)
{
int minutes = (time / (60)) % 3600;
return minutes;
}
int findHours(int time)
{
int hours = (time / (60 * 60));
return hours;
}
int findDays(int time)
{
int days = (time / (60 * 60 * 24) - 8) % (24);
return days;
}
int findMonths(int time)
{
int months = (time / (60 * 60 * 24 * 30) + 4) % (12);
return months;
}
int findYears(int time)
{
int years = (time / (60 * 60 * 24 * 30 * 12));
return years;
}
/*
ESTRUTURA USADA: || username time score date gamesWon gamesLost ||
Cria usuário do jogo no arquivo de estatísticas escolhido
*/
void createUser(FILE *file, char username[20])
{
// Extrair todos os jogadores
char linha[40];
// LER - Linha por linha
for (int i = 1; i > 0; i++)
{
if (StartsWith(linha, username))
{
return;
}
if (fgets(linha, 1000, file) == NULL)
{
fputs("\n", file);
fputs(username, file);
fputs(" 0 0 0 0 0", file);
fclose(file);
return;
}
}
}
// Procura usuário do jogo
int findUser(FILE *file, char username[20])
{
if (file == NULL)
{
return 0;
}
// Extrair todos os jogadores
char linha[40];
// LER - Linha por linha
for (int i = 1; i > 0; i++)
{
if (StartsWith(linha, username))
{
return 1;
}
if (fgets(linha, 1000, file) == NULL)
{
return 0;
}
}
return 0;
}
void findStats(char info[40], char fileName[11], char username[20],
int *segundos, int *pontos, int *dia, int *jganhos, int *jperdidos)
{
// "LycalopX 0 0 0 0 0"
char temp_filename[1024];
// LER - Valores
strcpy(temp_filename, "temp_____");
strcat(temp_filename, fileName);
FILE *file = fopen(temp_filename, "w");
fprintf(file, "%s", info);
fclose(file);
// Ler saporra
FILE *readfile = fopen(temp_filename, "r");
fscanf(readfile, "%s %i %i %i %i %i", username, segundos, pontos, dia, jganhos, jperdidos);
}
// Liberar espaço da matriz
void freeMatrix(char **Matrix, int height)
{
for (int i = 0; i < height; i++)
{
Matrix[i] = NULL;
}
Matrix = NULL;
return;
}
int findBiggestScore(char **Matrix, int height, char fileName[11], char username[20],
int *segundos, int *pontos, int *dia, int *jganhos, int *jperdidos)
{
int num = 0;
int index = 0;
for (int i = 0; i < height; i++)
{
if (strlen(Matrix[i]) < 5)
{
continue;
}
// Quando o string está vazio, ele muda o valor de segundos para 0
findStats(Matrix[i], fileName, username, segundos, pontos, dia, jganhos, jperdidos);
if (*pontos > num)
{
index = i;
num = *pontos;
}
}
return index;
}
int findSmallestTime(char **Matrix, int height, char fileName[11], char username[20],
int *segundos, int *pontos, int *dia, int *jganhos, int *jperdidos)
{
int num = 0;
int index = 0;
for (int i = 0; i < height; i++)
{
if (strlen(Matrix[i]) < 5)
{
continue;
}
findStats(Matrix[i], fileName, username, segundos, pontos, dia, jganhos, jperdidos);
if ((*segundos < num || num == 0) && *segundos != 0)
{
index = i;
num = *segundos;
}
}
return index;
}
void organizeByPoints(int type, char fileName[20], char username[20],
int *segundos, int *pontos, int *dia, int *jganhos, int *jperdidos)
{
int i = 0, p = 0, index = 0;
// Checa se o usuário é o mesmo da última iteração
char previousIndex[20];
// Arquivo
FILE *file = fopen(fileName, "r");
// Extrair todos os jogadores
char linha[40];
char **strings = NULL;
if (file == NULL)
{
printf("\n N%co foi possível organizar a leaderboard!! :o", 227);
}
strings = malloc(sizeof(char *));
if (strings == NULL)
{
printf("Memory allocation failed\n");
}
// Essa função serve o propósito de criar uma nova matriz com todos os dados organizados
// de todos os primeiros 10 usuários, dependendo da categoria usada
// Alocação dinâmica é necessária!
for (i = 0; fgets(linha, sizeof(linha), file) != NULL; i++)
{
p = i + 1;
// Alocar memória para cada string que usamos
strings[i] = (char *)malloc((41) * sizeof(char));
// Para criar a matriz...
strcpy(strings[i], linha);
}
// Não precisamos mais do arquivo aberto
fclose(file);
printf("\n\n--------------------------\n");
// Agora vamos comparar todos
for (int j = 0; j < (p - 1); j++)
{
if (type)
{
// Vamos achar o maior, e colocá-lo na posição...
index = findBiggestScore(strings, p, fileName, username, segundos, pontos, dia, jganhos, jperdidos);
findStats(strings[index], fileName, username, segundos, pontos, dia, jganhos, jperdidos);
// Caso seja a mesma pessoa, quer dizer que o resto tem pontuação zero...
if (!strcmp(username, previousIndex))
{
break;
}
else
{
strcpy(previousIndex, username);
}
if (!pontos)
{
// Remover da lista que precisa ser checada
strcpy(strings[index], "a");
j--;
continue;
}
printf("\n %.2d. %s \nTempo: %is Pontua%c%co: %i\nDia: %.2i/%.2i/%i\nJogos ganhos: %i\nJogos perdidos: %i \n\n",
j + 1, username, *segundos, 231, 227, *pontos, findDays(*dia), findMonths(*dia), findYears(*dia) + 1969, *jganhos, *jperdidos);
// Remover da lista que precisa ser checada
strcpy(strings[index], "a");
}
else
{
// Vamos achar o menor tempo, e colocá-lo na posição...
index = findSmallestTime(strings, p, fileName, username, segundos, pontos, dia, jganhos, jperdidos);
// Achando os dados
findStats(strings[index], fileName, username, segundos, pontos, dia, jganhos, jperdidos);
// Caso seja a mesma pessoa, quer dizer que o resto tem pontuação zero...
if (!strcmp(username, previousIndex))
{
break;
}
else
{
strcpy(previousIndex, username);
}
if (!*segundos)
{
// Remover da lista que precisa ser checada
strcpy(strings[index], "a");
j--;
continue;
}
printf("\n %.2d. %s \nTempo: %is Pontua%c%co: %i\nDia: %.2i/%.2i/%i\nJogos ganhos: %i\nJogos perdidos: %i \n\n",
j + 1, username, *segundos, 231, 227, *pontos, findDays(*dia), findMonths(*dia), findYears(*dia) + 1969, *jganhos, *jperdidos);
// Remover da lista que precisa ser checada
strcpy(strings[index], "a");
}
}
printf("--------------------------");
freeMatrix(strings, p);
}
// Muitas variáveis, pois há muita coisa a ser passada...
// Sintaxe: newTime, score, newDay, ganhos, perdas, fileName, username, segundos, pontos, dia, jganhos, jperdidos
void updateUser(
int newTime, int score, int newDay, int ganhos, int perdas,
char fileName[11], char username[20],
int *pointer1, int *pointer2, int *pointer3, int *pointer4, int *pointer5)
{
int p, i;
// Arquivo
FILE *file = fopen(fileName, "r");
if (file == NULL)
{
printf("\nNão foi possível atualizar os seus novos pontos!! :o");
return;
}
// Extrair todos os jogadores
char linha[40];
char **strings = NULL;
strings = malloc(sizeof(char *));
if (strings == NULL)
{
printf("Memory allocation failed\n");
return;
}
// Essa função serve o propósito de criar um novo arquivo que contém as novas
// informações, sem alterar as outras, e isso é feito transportando todos os
// dados para uma array, e os sobrescrevendo no arquivo
// Alocação dinâmica é necessária!
for (i = 0; fgets(linha, sizeof(linha), file) != NULL; i++)
{
// variáveis
p = i + 1;
// Realocar para caber a nova linha do arquivo
strings = realloc(strings, p * (sizeof(char *)));
// Alocar memória para cada string que usamos
strings[i] = (char *)malloc((41) * sizeof(char));
// Agora precisamos escrever na "nova linha" os novos dados de jogador!
if (StartsWith(linha, username))
{
findStats(linha, fileName, username, pointer1, pointer2, pointer3, pointer4, pointer5);
if (*pointer1 > newTime || *pointer1 == 0)
{
*pointer1 = newTime;
*pointer3 = newDay;
}
*pointer2 = *pointer2 + score;
*pointer4 = *pointer4 + ganhos;
*pointer5 = *pointer5 + perdas;
char charNumber[20];
// precisamos escrever todos os dados novos!
// Lembrando que elas são variáveis globais
strcat(strings[i], username);
strcat(strings[i], " ");
// Usaremos o mesmo string (charNumber) para transformar de int para char...
sprintf(charNumber, "%d", *pointer1);
strcat(strings[i], charNumber);
strcat(strings[i], " ");
sprintf(charNumber, "%d", *pointer2);
strcat(strings[i], charNumber);
strcat(strings[i], " ");
sprintf(charNumber, "%d", *pointer3);
strcat(strings[i], charNumber);
strcat(strings[i], " ");
sprintf(charNumber, "%d", *pointer4);
strcat(strings[i], charNumber);
strcat(strings[i], " ");
sprintf(charNumber, "%d", *pointer5);
strcat(strings[i], charNumber);
strcat(strings[i], "\n");
continue;
};
// Se os dados não forem alterados, só o incluir o string nessa casa i.
strcpy(strings[i], linha);
}
fclose(file);
// Arquivo
FILE *writefile = fopen(fileName, "w");
for (i = 0; i < p; i++)
{
fputs(strings[i], writefile);
};
fclose(writefile);
freeMatrix(strings, p);
}
void SelectionScreen(int option, char fileName[11], int *uppermatrix, int *bombcount,
char username[20], int *segundos, int *pontos, int *dia, int *jganhos, int *jperdidos)
{
// Caso tenha sido selecionado: jogar ou ver placar, ele age com base nessas duas escolhas
// Case 1 é o caso da pessoa ter escolhido jogar
// Case 2 é o caso da pessoa ter escolhido placar
// Case 3 é o caso da pessoa ter escolhido sair do jogo
int loop3, loop2 = 0;
// Repetir até valor coerente...
do
{
loop3 = 1;
switch (option)
{
case 1:
// Leva à tela de seleção da dificuldade, para jogar
selection(uppermatrix, bombcount, fileName);
break;
case 2:
while (loop2 == 0)
{
// Leva à tela de seleção da dificuldade, para ver a leaderboard
selection(uppermatrix, bombcount, fileName);
// Imprime as opções de placar (por tempo ou pontuação)
printf("\n\nModo de placar: \n---------------------------------------------\n1. \033[1;30mTop 10 Tempos\x1b[0m \n2. \033[0;30mTop 10 Pontua%c%ces \x1b[0m\n---------------------------------------------\n\nOp%c%co: ", 231, 245, 231, 227);
scanf("%d", &option);
// Arquivo em que estão armazenadas as estatísticas
FILE *file = fopen(fileName, "r");
// Ninguém jogou ainda...
if (!file)
{
printf("\nNão há pontuações registradas nesse modo de jogo.");
}
// Inicia protocolo de achar os top 10 melhores jogadores e imprimir um a um
// suas estaísticas
else
{
organizeByPoints(option - 1, fileName, username, segundos, pontos, dia, jganhos, jperdidos);
}
// Depois que isso se encerrou, ele pergunta novamente
printf("\n\nE agora? Gostaria de: \n---------------------------------------------\n1. Jogar \n2. Consultar placar de jogadores \n3. Sair \n---------------------------------------------\n\nOp%c%co: ", 231, 227);
scanf("%d", &option);
// Usa a mesma variável para o case
switch (option)
{
case 1:
selection(uppermatrix, bombcount, fileName);