Sapper

Форк
0
/
main.c 
1516 строк · 66.9 Кб
1
/*             С версия            */
2
#include <locale.h>
3
#include <stdarg.h>
4
#include <stdbool.h>
5
#include <stdio.h>
6
#include <stdlib.h>
7
#include <string.h>
8
#include <time.h>
9

10
bool victory = false;
11

12
struct result
13
{
14
    char* name;
15
    unsigned short games;
16
    unsigned short victories;
17
    double percent;
18
    unsigned short izzy;/*успешно пройденный просто*/
19
    unsigned short hard;/*успешно пройденный не просто*/
20
    unsigned short doom_guy;/*успешно пройденный ХАРДКОР*/
21
};
22
int scanf_rng(const char* const _Format, ...)
23
{
24
    int _Result;
25
    va_list _ArgList;
26
    va_start(_ArgList, _Format);
27
    _Result = vfscanf(stdin, _Format, _ArgList);
28
    va_end(_ArgList);
29
    scanf("%*[^\n]");
30
    fflush(stdin);
31
    return _Result;
32
}
33
int compare_games(const void* a, const void* b)
34
{
35
    const struct result* k = (const struct result*)a;
36
    const struct result* l = (const struct result*)b;
37
    return ((k->games) - (l->games));
38
}
39
int compare_izzy(const void* a, const void* b)
40
{
41
    const struct result* k = (const struct result*)a;
42
    const struct result* l = (const struct result*)b;
43
    return ((k->izzy) - (l->izzy));
44
}
45
int compare_hard(const void* a, const void* b)
46
{
47
    const struct result* k = (const struct result*)a;
48
    const struct result* l = (const struct result*)b;
49
    return ((k->hard) - (l->hard));
50
}
51
int compare_doom(const void* a, const void* b)
52
{
53
    const struct result* k = (const struct result*)a;
54
    const struct result* l = (const struct result*)b;
55
    return ((k->doom_guy) - (l->doom_guy));
56
}
57
int compare_percent(const void* a, const void* b)
58
{
59
    const struct result* k = (const struct result*)a;
60
    const struct result* l = (const struct result*)b;
61
    return ((k->percent) - (l->percent));
62
}
63
void save(struct result* save, const unsigned short f)
64
{
65
    FILE* fout = fopen("results.bin", "wbe");
66
    for (unsigned short q = 0; q < f; q++)
67
    {
68
        const unsigned short sz = strlen(save[q].name);
69
        fwrite(&sz, sizeof(unsigned short), 1, fout);
70
        fwrite(save[q].name, sizeof(char), sz, fout);
71
        fwrite(&save[q].games, sizeof(unsigned short), 1, fout);
72
        fwrite(&save[q].victories, sizeof(unsigned short), 1, fout);
73
        fwrite(&save[q].percent, sizeof(double), 1, fout);
74
        fwrite(&save[q].izzy, sizeof(unsigned short), 1, fout);
75
        fwrite(&save[q].hard, sizeof(unsigned short), 1, fout);
76
        fwrite(&save[q].doom_guy, sizeof(unsigned short), 1, fout);
77
    }
78
    fclose(fout);
79
}
80
void printdesk(char** deskgr, const unsigned short x, const unsigned short y)
81
{
82
    printf("  ");
83
    for (unsigned short i = 1; i < y + 1; i++)
84
        printf(" %d", i % 10);
85
    printf("\n");
86
    for (unsigned short i = 0; i < x; i++)
87
    {
88
        printf("  ");
89
        for (unsigned short q = 1; q < y + 1; q++)
90
            printf(" _");
91
        printf("\n");
92
        printf("%d ", (i + 1) % 10);
93
        for (unsigned short q = 0; q < y; q++)
94
            printf("|%c", deskgr[i][q]);
95
        printf("|\n");
96
    }
97
    printf("  ");
98
    for (unsigned short q = 1; q < y + 1; q++)
99
        printf(" _");
100
    printf("\n");
101
}
102
char opencl(const unsigned short num)
103
{
104
    switch (num)
105
    {
106
        case 0:
107
            return 48;
108
            break;
109
        case 1:
110
            return 49;
111
            break;
112
        case 2:
113
            return 50;
114
            break;
115
        case 3:
116
            return 51;
117
            break;
118
        case 4:
119
            return 52;
120
            break;
121
        case 5:
122
            return 53;
123
            break;
124
        case 6:
125
            return 54;
126
            break;
127
        case 7:
128
            return 55;
129
            break;
130
        default:
131
            return 56;
132
            break;
133
    }
134
}
135
short to_hu(char* XM)
136
{
137
    unsigned short xm = 0;
138
    bool correct = true;
139
    if (XM[1] == 49 || XM[1] == 50 || XM[1] == 51 || XM[1] == 52 || XM[1] == 53 || XM[1] == 54 || XM[1] == 55 || XM[1] == 56 || XM[1] == 57 || XM[1] == 58)
140
    {
141
        switch (XM[0])
142
        {
143
            case 49:
144
                xm = 10;
145
                break;
146
            case 50:
147
                xm = 20;
148
                break;
149
            case 51:
150
                xm = 30;
151
                break;
152
            default:
153
                printf("Ввод не корректен.\n");
154
                correct = false;
155
                break;
156
        }
157
        if (correct)
158
        {
159
            switch (XM[1])
160
            {
161
                case 48:
162
                    break;
163
                case 49:
164
                    xm++;
165
                    break;
166
                case 50:
167
                    xm += 2;
168
                    break;
169
                case 51:
170
                    xm += 3;
171
                    break;
172
                case 52:
173
                    xm += 4;
174
                    break;
175
                case 53:
176
                    xm += 5;
177
                    break;
178
                case 54:
179
                    xm += 6;
180
                    break;
181
                case 55:
182
                    xm += 7;
183
                    break;
184
                case 56:
185
                    xm += 8;
186
                    break;
187
                case 57:
188
                    xm += 9;
189
                    break;
190
                default:
191
                    printf("Ввод не корректен.\n");
192
                    correct = false;
193
                    break;
194
            }
195
        }
196
        if (correct && XM[2] != 0)
197
        {
198
            printf("Ввод не корректен.\n");
199
            correct = false;
200
        }
201
    }
202
    else if (XM[1] == 0)
203
    {
204
        switch (*XM)
205
        {
206
            case 48:
207
                break;
208
            case 49:
209
                xm++;
210
                break;
211
            case 50:
212
                xm += 2;
213
                break;
214
            case 51:
215
                xm += 3;
216
                break;
217
            case 52:
218
                xm += 4;
219
                break;
220
            case 53:
221
                xm += 5;
222
                break;
223
            case 54:
224
                xm += 6;
225
                break;
226
            case 55:
227
                xm += 7;
228
                break;
229
            case 56:
230
                xm += 8;
231
                break;
232
            case 57:
233
                xm += 9;
234
                break;
235
            default:
236
                printf("Ввод не корректен.\n");
237
                correct = false;
238
                break;
239
        }
240
    }
241
    else
242
    {
243
        printf("Ввод не корректен.\n");
244
        correct = false;
245
    }
246
    return correct ? xm : -1;
247
}
248
void game(struct result* p, struct result player, const unsigned short type)
249
{
250
    unsigned short x = 0, y = 0;/*custom*/
251
    unsigned short mines = 0;
252
    char** deskgr = 0;
253
    unsigned short** bnum = 0;
254
    unsigned short count = 0;/*кол-во мин*/
255
    unsigned short* position = 0;
256
    if (type != 1)
257
    {
258
        deskgr = (char**)malloc(type * sizeof(char*));
259
        for (unsigned short i = 0; i < type; i++)
260
            deskgr[i] = (char*)malloc(type * sizeof(char));
261
        for (unsigned short i = 0; i < type; i++)
262
            for (unsigned short q = 0; q < type; q++)
263
                deskgr[i][q] = 32;
264
        /*то, что отображается*/
265
        bnum = (unsigned short**)malloc(type * sizeof(unsigned short*));
266
        for (unsigned short i = 0; i < type; i++)
267
            bnum[i] = (unsigned short*)malloc(type * sizeof(unsigned short));
268
        for (unsigned short i = 0; i < type; i++)
269
            for (unsigned short q = 0; q < type; q++)
270
                bnum[i][q] = 0;
271
        /*номера(рядом с минами)*/
272
        switch (type)
273
        {
274
            case 8:
275
                printdesk(deskgr, 8, 8);
276
                break;
277
            case 16:
278
                printdesk(deskgr, 16, 16);
279
                break;
280
            default:
281
                printdesk(deskgr, 32, 32);
282
                break;
283
        }
284
        srand(time(NULL));
285
        count = 0;
286
        position = (unsigned short*)malloc(type * 2 * sizeof(unsigned short));/*номера мин*/
287
        while (count != type * 2)
288
        {
289
            bool test = false;
290
            unsigned short place = rand() % ((type * type - 1) - 0 + 1) + 0; /*позиция мины*/
291
            for (unsigned short i = 0; i < count; i++)
292
            {
293
                if (place == position[i])
294
                {
295
                    test = true;
296
                    break;
297
                }
298
            }
299
            if (!test)
300
            {
301
                count++;
302
                position[count - 1] = place;
303
            }
304
        }/*создали мины*/
305
        unsigned short xc = 0, yc = 0;
306
        for (unsigned short q = 0; q < count; q++)
307
        {
308
            xc = position[q] / type;/*строка с миной*/
309
            yc = position[q] - (type * xc);/*столбец с миной*/
310
            /*определили положение мины*/
311
            if (xc > 0)
312
                bnum[xc - 1][yc]++;
313
            if (xc < type - 1)
314
                bnum[xc + 1][yc]++;
315
            if (yc > 0)
316
                bnum[xc][yc - 1]++;
317
            if (yc < type - 1)
318
                bnum[xc][yc + 1]++;
319
            if (xc > 0 && yc > 0)
320
                bnum[xc - 1][yc - 1]++;
321
            if (xc < type - 1 && yc > 0)
322
                bnum[xc + 1][yc - 1]++;
323
            if (xc > 0 && yc < type - 1)
324
                bnum[xc - 1][yc + 1]++;
325
            if (xc < type - 1 && yc < type - 1)
326
                bnum[xc + 1][yc + 1]++;
327
        }/*Заполнили номерами для мин*/
328
    }
329
    else
330
    {
331
        char* X = (char*)malloc(0);
332
        char* Y = (char*)malloc(0);
333
        printf("Задайте размер доски.\n");
334
        do
335
        {
336
            printf("Кол-во строк(не больше 50, минимум 3): ");
337
            scanf_rng("%3s", X);
338
            x = atoi(X);
339
            if (x < 3 || x > 50)
340
                printf("Ввод не корректен\n");
341
        }
342
        while (x < 3 || x > 50);
343
        do
344
        {
345
            printf("Кол-во столбцов(не больше 50, минимум 3): ");
346
            scanf_rng("%3s", Y);
347
            y = atoi(Y);
348
            if (y < 3 || y > 50)
349
                printf("Ввод не корректен\n");
350
        }
351
        while (y < 3 || y > 50);
352
        deskgr = (char**)malloc(x * sizeof(char*));
353
        for (unsigned short i = 0; i < x; i++)
354
            deskgr[i] = (char*)malloc(y * sizeof(char));
355
        for (unsigned short i = 0; i < x; i++)
356
            for (unsigned short q = 0; q < y; q++)
357
                deskgr[i][q] = 32;
358
        /*то, что отображается*/
359
        bnum = (unsigned short**)malloc(x * sizeof(unsigned short*));
360
        for (unsigned short i = 0; i < x; i++)
361
            bnum[i] = (unsigned short*)malloc(y * sizeof(unsigned short));
362
        for (unsigned short i = 0; i < x; i++)
363
            for (unsigned short q = 0; q < y; q++)
364
                bnum[i][q] = 0;
365
        /*номера(рядом с минами)*/
366
        printdesk(deskgr, x, y);
367
        do
368
        {
369
            mines = 0;
370
            char* MINES = (char*)malloc(0);
371
            printf("Задайте кол-во мин (минимум 5%% от площади доски и максимум 95%%): ");
372
            scanf_rng("%4s", MINES);
373
            mines = atoi(MINES);
374
            if (mines < (x * y) / 100.0 * 5 || mines >(x * y) / 100.0 * 95)
375
                printf("Ввод не корректен\n");
376
        }
377
        while (mines < (x * y) / 100.0 * 5 || mines >(x * y) / 100.0 * 95);
378
        srand(time(NULL));
379
        count = 0;
380
        position = (unsigned short*)malloc(mines * sizeof(unsigned short));/*номера мин*/
381
        while (count != mines)
382
        {
383
            bool test = false;
384
            unsigned short place = rand() % ((x * y - 1) - 0 + 1) + 0; /*позиция мины*/
385
            for (unsigned short i = 0; i < count; i++)
386
            {
387
                if (place == position[i])
388
                {
389
                    test = true;
390
                    break;
391
                }
392
            }
393
            if (!test)
394
            {
395
                count++;
396
                position[count - 1] = place;
397
            }
398
        } /*создали мины*/
399
        unsigned short xc = 0, yc = 0;
400
        for (unsigned short q = 0; q < count; q++)
401
        {
402
            xc = position[q] / y;/*строка с миной*/
403
            yc = position[q] - y * xc;/*столбец с миной*/
404
            /*определили положение мины*/
405
            if (xc > 0)
406
                bnum[xc - 1][yc]++;
407
            if (xc < x - 1)
408
                bnum[xc + 1][yc]++;
409
            if (yc > 0)
410
                bnum[xc][yc - 1]++;
411
            if (yc < y - 1)
412
                bnum[xc][yc + 1]++;
413
            if (xc > 0 && yc > 0)
414
                bnum[xc - 1][yc - 1]++;
415
            if (xc < x - 1 && yc > 0)
416
                bnum[xc + 1][yc - 1]++;
417
            if (xc > 0 && yc < y - 1)
418
                bnum[xc - 1][yc + 1]++;
419
            if (xc < x - 1 && yc < y - 1)
420
                bnum[xc + 1][yc + 1]++;
421
        }/*Заполнили номерами для мин*/
422
    }
423
    unsigned short xh = 0, yh = 0, mch = 0, mv = 0;
424
    bool lose = false;
425
    unsigned short space = type != 1 ? type * type - type * 2 : x * y - mines;/*не мины*/;
426
    char* MV = (char*)malloc(0);
427
    char* YESf = (char*)malloc(0);
428
    char* YESd = (char*)malloc(0);
429
    char* YESm = (char*)malloc(0);
430
    char* XM = (char*)malloc(0);
431
    char* YM = (char*)malloc(0);
432
    char* XD = (char*)malloc(0);
433
    char* YD = (char*)malloc(0);
434
    char* XH = (char*)malloc(0);
435
    char* YH = (char*)malloc(0);
436
    time_t start = time(NULL);
437
    do
438
    {
439
        do
440
        {
441
            printf("1. Поставить метку\n2. Убрать метку\n3. Сделать ход\n");
442
            printf("Выберите ЦИФРУ: ");
443
            scanf_rng("%2s", MV);
444
            if (*MV != 49 && *MV != 50 && *MV != 51 || MV[1] != 0)
445
                printf("Ввод не коректен\n");
446
        }
447
        while (*MV != 49 && *MV != 50 && *MV != 51 || MV[1] != 0);
448
        switch (*MV)
449
        {
450
            case 49:
451
                mv = 1;
452
                break;
453
            case 50:
454
                mv = 2;
455
                break;
456
            default:
457
                mv = 3;
458
                break;
459
        }
460
        switch (mv)
461
        {
462
            case 1:
463
                do
464
                {
465
                    printf("Если у вас есть предположение о месте мин, то можете поставить + на это место. Если хотите это сделать, то введите YES, иначе что-то другое: ");
466
                    scanf_rng("%4s", YESf);
467
                    if (strcmp(YESf, "YES") == 0)
468
                    {
469
                        unsigned short xm = 0, ym = 0;/*координаты мин*/
470
                        short xt = 0, yt = 0;/*тест*/
471
                        printf("Введите координаты мины.\n");
472
                        do
473
                        {
474
                            xm = 0;
475
                            printf("Введите номер строки: ");
476
                            scanf_rng("%3s", XM);
477
                            xt = to_hu(XM);
478
                        }
479
                        while (xt == -1);
480
                        xm = xt;
481
                        do
482
                        {
483
                            ym = 0;
484
                            printf("Введите номер столбца: ");
485
                            scanf_rng("%3s", YM);
486
                            yt = to_hu(YM);
487
                        }
488
                        while (yt == -1);
489
                        ym = yt;
490
                        if (type != 1)
491
                        {
492
                            if ((xm > type || xm < 1) && (ym > type || ym < 1))
493
                            {
494
                                printf("Вы вышли за рамки доски\n");
495
                                break;
496
                            }
497
                        }
498
                        else if ((xm > x || xm < 1) && (ym > y || ym < 1))
499
                        {
500
                            printf("Вы вышли за рамки доски\n");
501
                            break;
502
                        }
503
                        if (deskgr[xm - 1][ym - 1] != 32)
504
                        {
505
                            printf("Сомневаюсь, что вы хотите поставить сюда метку...\n");
506
                            break;
507
                        }
508
                        deskgr[xm - 1][ym - 1] = 43;
509
                        switch (type)
510
                        {
511
                            case 8:
512
                                printdesk(deskgr, 8, 8);
513
                                break;
514
                            case 16:
515
                                printdesk(deskgr, 16, 16);
516
                                break;
517
                            case 32:
518
                                printdesk(deskgr, 32, 32);
519
                                break;
520
                            default:
521
                                printdesk(deskgr, x, y);
522
                                break;
523
                        }
524
                    }
525
                }
526
                while (strcmp(YESf, "YES") == 0);
527
                break;
528
            case 2:
529
                do
530
                {
531
                    printf("Вы можете убрать метку на мину. Если хотите это сделать, то введите YES, иначе что-то другое: ");
532
                    scanf_rng("%4s", YESd);
533
                    if (strcmp(YESd, "YES") == 0)
534
                    {
535
                        unsigned short xm = 0, ym = 0;/*координаты мин*/
536
                        short xt = 0, yt = 0;/*тест*/
537
                        printf("Введите координаты мины.\n");
538
                        do
539
                        {
540
                            xm = 0;
541
                            printf("Введите номер строки: ");
542
                            scanf_rng("%3s", XD);
543
                            xt = to_hu(XD);
544
                        }
545
                        while (xt == -1);
546
                        xm = xt;
547
                        do
548
                        {
549
                            ym = 0;
550
                            printf("Введите номер столбца: ");
551
                            scanf_rng("%3s", YD);
552
                            yt = to_hu(YD);
553
                        }
554
                        while (yt == -1);
555
                        ym = yt;
556
                        if (type != 1)
557
                        {
558
                            if ((xm > type || xm < 1) && (ym > type || ym < 1))
559
                            {
560
                                printf("Вы вышли за рамки доски\n");
561
                                break;
562
                            }
563
                        }
564
                        else if ((xm > x || xm < 1) && (ym > y || ym < 1))
565
                        {
566
                            printf("Вы вышли за рамки доски\n");
567
                            break;
568
                        }
569
                        if (deskgr[xm - 1][ym - 1] != 43)
570
                        {
571
                            printf("Здесь нет метки...\n");
572
                            break;
573
                        }
574
                        deskgr[xm - 1][ym - 1] = 32;
575
                        switch (type)
576
                        {
577
                            case 8:
578
                                printdesk(deskgr, 8, 8);
579
                                break;
580
                            case 16:
581
                                printdesk(deskgr, 16, 16);
582
                                break;
583
                            case 32:
584
                                printdesk(deskgr, 32, 32);
585
                                break;
586
                            default:
587
                                printdesk(deskgr, x, y);
588
                                break;
589
                        }
590
                    }
591
                }
592
                while (strcmp(YESd, "YES") == 0);
593
                break;
594
            default:
595
                printf("Вы уверены, что хотите совершить ход? Если да, то введите YES, иначе что-то другое: ");
596
                scanf_rng("%4s", YESm);
597
                if (strcmp(YESm, "YES") != 0)
598
                    break;
599
                short xt = 0, yt = 0;/*тест*/
600
                bool beyond = false;
601
                do
602
                {
603
                    printf("Введите координаты мины\n");
604
                    do
605
                    {
606
                        xh = 0;
607
                        printf("Введите номер строки: ");
608
                        scanf_rng("%3s", XH);
609
                        xt = to_hu(XH);
610
                    }
611
                    while (xt == -1);
612
                    xh = xt;
613
                    do
614
                    {
615
                        yh = 0;
616
                        printf("Введите номер столбца: ");
617
                        scanf_rng("%3s", YH);
618
                        yt = to_hu(YH);
619
                    }
620
                    while (yt == -1);
621
                    yh = yt;
622
                    beyond = false;
623
                    if (type != 1)
624
                    {
625
                        if ((xh > type || xh < 1) && (yh > type || yh < 1))
626
                        {
627
                            printf("Вы вышли за рамки доски\n");
628
                            beyond = true;
629
                        }
630
                    }
631
                    else if ((xh > x || xh < 1) && (yh > y || yh < 1))
632
                    {
633
                        printf("Вы вышли за рамки доски\n");
634
                        beyond = true;
635
                    }
636
                }
637
                while (beyond);
638
                for (unsigned short c = 0; c < count; c++)
639
                {
640
                    if (type != 1)
641
                    {
642
                        if ((xh - 1) * type + yh - 1 == position[c]) /*просрали*/
643
                        {
644
                            for (unsigned short o = 0; o < count; o++)
645
                                deskgr[position[o] / type][position[o] - (position[o] / type) * type] = 120;
646
                            switch (type)
647
                            {
648
                                case 8:
649
                                    printdesk(deskgr, 8, 8);
650
                                    break;
651
                                case 16:
652
                                    printdesk(deskgr, 16, 16);
653
                                    break;
654
                                default:
655
                                    printdesk(deskgr, 32, 32);
656
                                    break;
657
                            }
658
                            printf("Вы взорвались :(\n");
659
                            lose = true;
660
                            break;
661
                        }
662
                    }
663
                    else if ((xh - 1) * y + yh - 1 == position[c]) /*просрали*/
664
                    {
665
                        for (unsigned short o = 0; o < count; o++)
666
                            deskgr[position[o] / y][position[o] - (position[o] / y) * y] = 120;
667
                        printdesk(deskgr, x, y);
668
                        printf("Вы взорвались :(\n");
669
                        lose = true;
670
                        break;
671
                    }
672
                }
673
                if (!lose && deskgr[xh - 1][yh - 1] != 32)
674
                    printf("Эта клетка уже открыта\n");
675
                else if (!lose && deskgr[xh - 1][yh - 1] == 32) /*не просрали*/
676
                {
677
                    unsigned short i = 0;
678
                    unsigned short amount = 0;
679
                    if (bnum[xh - 1][yh - 1] == 0) /*открытие клеток*/
680
                    {
681
                        unsigned short* eternal_x = (unsigned short*)malloc(1 * sizeof(unsigned short));/*строки 0*/
682
                        *eternal_x = xh - 1;
683
                        unsigned short* eternal_y = (unsigned short*)malloc(1 * sizeof(unsigned short));/*столбцы 0*/
684
                        *eternal_y = yh - 1;
685
                        unsigned short eternal_size = 1;
686
                        for (i = 0; i < eternal_size; i++)
687
                        {
688
                            deskgr[eternal_x[i]][eternal_y[i]] = 48;
689
                            amount++;
690
                            if (eternal_x[i] > 0)
691
                            {
692
                                if (bnum[eternal_x[i] - 1][eternal_y[i]] == 0)
693
                                {
694
                                    bool potato = false;
695
                                    for (unsigned short c = 0; c < eternal_size; c++)
696
                                    {
697
                                        if (eternal_x[c] == eternal_x[i] - 1 && eternal_y[c] == eternal_y[i])
698
                                        {
699
                                            potato = true;
700
                                            break;
701
                                        }
702
                                    }
703
                                    if (!potato)
704
                                    {
705
                                        eternal_size++;
706
                                        eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
707
                                        eternal_x[eternal_size - 1] = eternal_x[i] - 1;
708
                                        eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
709
                                        eternal_y[eternal_size - 1] = eternal_y[i];
710
                                    }
711
                                }
712
                                else if (deskgr[eternal_x[i] - 1][eternal_y[i]] == 32)
713
                                {
714
                                    deskgr[eternal_x[i] - 1][eternal_y[i]] = opencl(bnum[eternal_x[i] - 1][eternal_y[i]]);
715
                                    amount++;
716
                                }
717
                            }
718
                            if (type != 1)
719
                            {
720
                                if (eternal_x[i] < type - 1)
721
                                {
722
                                    if (bnum[eternal_x[i] + 1][eternal_y[i]] == 0)
723
                                    {
724
                                        bool potato = false;
725
                                        for (unsigned short c = 0; c < eternal_size; c++)
726
                                        {
727
                                            if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i])
728
                                            {
729
                                                potato = true;
730
                                                break;
731
                                            }
732
                                        }
733
                                        if (!potato)
734
                                        {
735
                                            eternal_size++;
736
                                            eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
737
                                            eternal_x[eternal_size - 1] = eternal_x[i] + 1;
738
                                            eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
739
                                            eternal_y[eternal_size - 1] = eternal_y[i];
740
                                        }
741
                                    }
742
                                    else if (deskgr[eternal_x[i] + 1][eternal_y[i]] == 32)
743
                                    {
744
                                        deskgr[eternal_x[i] + 1][eternal_y[i]] = opencl(bnum[eternal_x[i] + 1][eternal_y[i]]);
745
                                        amount++;
746
                                    }
747
                                }
748
                            }
749
                            else
750
                            {
751
                                if (eternal_x[i] < x - 1)
752
                                {
753
                                    if (bnum[eternal_x[i] + 1][eternal_y[i]] == 0)
754
                                    {
755
                                        bool potato = false;
756
                                        for (unsigned short c = 0; c < eternal_size; c++)
757
                                        {
758
                                            if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i])
759
                                            {
760
                                                potato = true;
761
                                                break;
762
                                            }
763
                                        }
764
                                        if (!potato)
765
                                        {
766
                                            eternal_size++;
767
                                            eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
768
                                            eternal_x[eternal_size - 1] = eternal_x[i] + 1;
769
                                            eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
770
                                            eternal_y[eternal_size - 1] = eternal_y[i];
771
                                        }
772
                                    }
773
                                    else if (deskgr[eternal_x[i] + 1][eternal_y[i]] == 32)
774
                                    {
775
                                        deskgr[eternal_x[i] + 1][eternal_y[i]] = opencl(bnum[eternal_x[i] + 1][eternal_y[i]]);
776
                                        amount++;
777
                                    }
778
                                }
779
                            }
780
                            if (eternal_y[i] > 0)
781
                            {
782
                                if (bnum[eternal_x[i]][eternal_y[i] - 1] == 0)
783
                                {
784
                                    bool potato = false;
785
                                    for (unsigned short c = 0; c < eternal_size; c++)
786
                                    {
787
                                        if (eternal_x[c] == eternal_x[i] && eternal_y[c] == eternal_y[i] - 1)
788
                                        {
789
                                            potato = true;
790
                                            break;
791
                                        }
792
                                    }
793
                                    if (!potato)
794
                                    {
795
                                        eternal_size++;
796
                                        eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
797
                                        eternal_x[eternal_size - 1] = eternal_x[i];
798
                                        eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
799
                                        eternal_y[eternal_size - 1] = eternal_y[i] - 1;
800
                                    }
801
                                }
802
                                else if (deskgr[eternal_x[i]][eternal_y[i] - 1] == 32)
803
                                {
804
                                    deskgr[eternal_x[i]][eternal_y[i] - 1] = opencl(bnum[eternal_x[i]][eternal_y[i] - 1]);
805
                                    amount++;
806
                                }
807
                            }
808
                            if (type != 1)
809
                            {
810
                                if (eternal_y[i] < type - 1)
811
                                {
812
                                    if (bnum[eternal_x[i]][eternal_y[i] + 1] == 0)
813
                                    {
814
                                        bool potato = false;
815
                                        for (unsigned short c = 0; c < eternal_size; c++)
816
                                        {
817
                                            if (eternal_x[c] == eternal_x[i] && eternal_y[c] == eternal_y[i] + 1)
818
                                            {
819
                                                potato = true;
820
                                                break;
821
                                            }
822
                                        }
823
                                        if (!potato)
824
                                        {
825
                                            eternal_size++;
826
                                            eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
827
                                            eternal_x[eternal_size - 1] = eternal_x[i];
828
                                            eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
829
                                            eternal_y[eternal_size - 1] = eternal_y[i] + 1;
830
                                        }
831
                                    }
832
                                    else if (deskgr[eternal_x[i]][eternal_y[i] + 1] == 32)
833
                                    {
834
                                        deskgr[eternal_x[i]][eternal_y[i] + 1] = opencl(bnum[eternal_x[i]][eternal_y[i] + 1]);
835
                                        amount++;
836
                                    }
837
                                }
838
                            }
839
                            else
840
                            {
841
                                if (eternal_y[i] < y - 1)
842
                                {
843
                                    if (bnum[eternal_x[i]][eternal_y[i] + 1] == 0)
844
                                    {
845
                                        bool potato = false;
846
                                        for (unsigned short c = 0; c < eternal_size; c++)
847
                                        {
848
                                            if (eternal_x[c] == eternal_x[i] && eternal_y[c] == eternal_y[i] + 1)
849
                                            {
850
                                                potato = true;
851
                                                break;
852
                                            }
853
                                        }
854
                                        if (!potato)
855
                                        {
856
                                            eternal_size++;
857
                                            eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
858
                                            eternal_x[eternal_size - 1] = eternal_x[i];
859
                                            eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
860
                                            eternal_y[eternal_size - 1] = eternal_y[i] + 1;
861
                                        }
862
                                    }
863
                                    else if (deskgr[eternal_x[i]][eternal_y[i] + 1] == 32)
864
                                    {
865
                                        deskgr[eternal_x[i]][eternal_y[i] + 1] = opencl(bnum[eternal_x[i]][eternal_y[i] + 1]);
866
                                        amount++;
867
                                    }
868
                                }
869
                            }
870
                            if (eternal_x[i] > 0 && eternal_y[i] > 0)
871
                            {
872
                                if (bnum[eternal_x[i] - 1][eternal_y[i] - 1] == 0)
873
                                {
874
                                    bool potato = false;
875
                                    for (unsigned short c = 0; c < eternal_size; c++)
876
                                    {
877
                                        if (eternal_x[c] == eternal_x[i] - 1 && eternal_y[c] == eternal_y[i] - 1)
878
                                        {
879
                                            potato = true;
880
                                            break;
881
                                        }
882
                                    }
883
                                    if (!potato)
884
                                    {
885
                                        eternal_size++;
886
                                        eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
887
                                        eternal_x[eternal_size - 1] = eternal_x[i] - 1;
888
                                        eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
889
                                        eternal_y[eternal_size - 1] = eternal_y[i] - 1;
890
                                    }
891
                                }
892
                                else if (deskgr[eternal_x[i] - 1][eternal_y[i] - 1] == 32)
893
                                {
894
                                    deskgr[eternal_x[i] - 1][eternal_y[i] - 1] = opencl(bnum[eternal_x[i] - 1][eternal_y[i] - 1]);
895
                                    amount++;
896
                                }
897
                            }
898
                            if (type != 1)
899
                            {
900
                                if (eternal_x[i] < type - 1 && eternal_y[i] > 0)
901
                                {
902
                                    if (bnum[eternal_x[i] + 1][eternal_y[i] - 1] == 0)
903
                                    {
904
                                        bool potato = false;
905
                                        for (unsigned short c = 0; c < eternal_size; c++)
906
                                        {
907
                                            if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i] - 1)
908
                                            {
909
                                                potato = true;
910
                                                break;
911
                                            }
912
                                        }
913

914
                                        if (!potato)
915
                                        {
916
                                            eternal_size++;
917
                                            eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
918
                                            eternal_x[eternal_size - 1] = eternal_x[i] + 1;
919
                                            eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
920
                                            eternal_y[eternal_size - 1] = eternal_y[i] - 1;
921
                                        }
922
                                    }
923
                                    else if (deskgr[eternal_x[i] + 1][eternal_y[i] - 1] == 32)
924
                                    {
925
                                        deskgr[eternal_x[i] + 1][eternal_y[i] - 1] = opencl(bnum[eternal_x[i] + 1][eternal_y[i] - 1]);
926
                                        amount++;
927
                                    }
928
                                }
929
                            }
930
                            else
931
                            {
932
                                if (eternal_x[i] < x - 1 && eternal_y[i] > 0)
933
                                {
934
                                    if (bnum[eternal_x[i] + 1][eternal_y[i] - 1] == 0)
935
                                    {
936
                                        bool potato = false;
937
                                        for (unsigned short c = 0; c < eternal_size; c++)
938
                                        {
939
                                            if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i] - 1)
940
                                            {
941
                                                potato = true;
942
                                                break;
943
                                            }
944
                                        }
945
                                        if (!potato)
946
                                        {
947
                                            eternal_size++;
948
                                            eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
949
                                            eternal_x[eternal_size - 1] = eternal_x[i] + 1;
950
                                            eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
951
                                            eternal_y[eternal_size - 1] = eternal_y[i] - 1;
952
                                        }
953
                                    }
954
                                    else if (deskgr[eternal_x[i] + 1][eternal_y[i] - 1] == 32)
955
                                    {
956
                                        deskgr[eternal_x[i] + 1][eternal_y[i] - 1] = opencl(bnum[eternal_x[i] + 1][eternal_y[i] - 1]);
957
                                        amount++;
958
                                    }
959
                                }
960
                            }
961
                            if (type != 1)
962
                            {
963
                                if (eternal_x[i] > 0 && eternal_y[i] < type - 1)
964
                                {
965
                                    if (bnum[eternal_x[i] - 1][eternal_y[i] + 1] == 0)
966
                                    {
967
                                        bool potato = false;
968
                                        for (unsigned short c = 0; c < eternal_size; c++)
969
                                        {
970
                                            if (eternal_x[c] == eternal_x[i] - 1 && eternal_y[c] == eternal_y[i] + 1)
971
                                            {
972
                                                potato = true;
973
                                                break;
974
                                            }
975
                                        }
976
                                        if (!potato)
977
                                        {
978
                                            eternal_size++;
979
                                            eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
980
                                            eternal_x[eternal_size - 1] = eternal_x[i] - 1;
981
                                            eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
982
                                            eternal_y[eternal_size - 1] = eternal_y[i] + 1;
983
                                        }
984
                                    }
985
                                    else if (deskgr[eternal_x[i] - 1][eternal_y[i] + 1] == 32)
986
                                    {
987
                                        deskgr[eternal_x[i] - 1][eternal_y[i] + 1] = opencl(bnum[eternal_x[i] - 1][eternal_y[i] + 1]);
988
                                        amount++;
989
                                    }
990
                                }
991
                            }
992
                            else
993
                            {
994
                                if (eternal_x[i] > 0 && eternal_y[i] < y - 1)
995
                                {
996
                                    if (bnum[eternal_x[i] - 1][eternal_y[i] + 1] == 0)
997
                                    {
998
                                        bool potato = false;
999
                                        for (unsigned short c = 0; c < eternal_size; c++)
1000
                                        {
1001
                                            if (eternal_x[c] == eternal_x[i] - 1 && eternal_y[c] == eternal_y[i] + 1)
1002
                                            {
1003
                                                potato = true;
1004
                                                break;
1005
                                            }
1006
                                        }
1007
                                        if (!potato)
1008
                                        {
1009
                                            eternal_size++;
1010
                                            eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
1011
                                            eternal_x[eternal_size - 1] = eternal_x[i] - 1;
1012
                                            eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
1013
                                            eternal_y[eternal_size - 1] = eternal_y[i] + 1;
1014
                                        }
1015
                                    }
1016
                                    else if (deskgr[eternal_x[i] - 1][eternal_y[i] + 1] == 32)
1017
                                    {
1018
                                        deskgr[eternal_x[i] - 1][eternal_y[i] + 1] = opencl(bnum[eternal_x[i] - 1][eternal_y[i] + 1]);
1019
                                        amount++;
1020
                                    }
1021
                                }
1022
                            }
1023
                            if (type != 1)
1024
                            {
1025
                                if (eternal_x[i] < type - 1 && eternal_y[i] < type - 1)
1026
                                {
1027
                                    if (bnum[eternal_x[i] + 1][eternal_y[i] + 1] == 0)
1028
                                    {
1029
                                        bool potato = false;
1030
                                        for (unsigned short c = 0; c < eternal_size; c++)
1031
                                        {
1032
                                            if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i] + 1)
1033
                                            {
1034
                                                potato = true;
1035
                                                break;
1036
                                            }
1037
                                        }
1038
                                        if (!potato)
1039
                                        {
1040
                                            eternal_size++;
1041
                                            eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
1042
                                            eternal_x[eternal_size - 1] = eternal_x[i] + 1;
1043
                                            eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
1044
                                            eternal_y[eternal_size - 1] = eternal_y[i] + 1;
1045
                                        }
1046
                                    }
1047
                                    else if (deskgr[eternal_x[i] + 1][eternal_y[i] + 1] == 32)
1048
                                    {
1049
                                        deskgr[eternal_x[i] + 1][eternal_y[i] + 1] = opencl(bnum[eternal_x[i] + 1][eternal_y[i] + 1]);
1050
                                        amount++;
1051
                                    }
1052
                                }
1053
                            }
1054
                            else
1055
                            {
1056
                                if (eternal_x[i] < x - 1 && eternal_y[i] < y - 1)
1057
                                {
1058
                                    if (bnum[eternal_x[i] + 1][eternal_y[i] + 1] == 0)
1059
                                    {
1060
                                        bool potato = false;
1061
                                        for (unsigned short c = 0; c < eternal_size; c++)
1062
                                        {
1063
                                            if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i] + 1)
1064
                                            {
1065
                                                potato = true;
1066
                                                break;
1067
                                            }
1068
                                        }
1069
                                        if (!potato)
1070
                                        {
1071
                                            eternal_size++;
1072
                                            eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
1073
                                            eternal_x[eternal_size - 1] = eternal_x[i] + 1;
1074
                                            eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
1075
                                            eternal_y[eternal_size - 1] = eternal_y[i] + 1;
1076
                                        }
1077
                                    }
1078
                                    else if (deskgr[eternal_x[i] + 1][eternal_y[i] + 1] == 32)
1079
                                    {
1080
                                        deskgr[eternal_x[i] + 1][eternal_y[i] + 1] = opencl(bnum[eternal_x[i] + 1][eternal_y[i] + 1]);
1081
                                        amount++;
1082
                                    }
1083
                                }
1084
                            }
1085
                        }
1086
                        free(eternal_x);
1087
                        free(eternal_y);
1088
                    }
1089
                    else
1090
                    {
1091
                        deskgr[xh - 1][yh - 1] = opencl(bnum[xh - 1][yh - 1]);
1092
                        amount++;
1093
                    }
1094
                    switch (type)
1095
                    {
1096
                        case 8:
1097
                            printdesk(deskgr, 8, 8);
1098
                            break;
1099
                        case 16:
1100
                            printdesk(deskgr, 16, 16);
1101
                            break;
1102
                        case 32:
1103
                            printdesk(deskgr, 32, 32);
1104
                            break;
1105
                        default:
1106
                            printdesk(deskgr, x, y);
1107
                            break;
1108
                    }
1109
                    space -= amount;
1110
                }
1111
                break;
1112
        }
1113
    }
1114
    while (!lose && space != 0);
1115
    if (!lose)
1116
    {
1117
        printf("ВЫ ВЫЖИЛИ!\n");
1118
        victory = true;
1119
    }
1120
    time_t finish = time(NULL);
1121
    printf("Ваше время: %.0lf секунд\n", difftime(finish, start));
1122
    free(position);
1123
    for (unsigned short i = 0; i < type; i++)
1124
        free(deskgr[i]);
1125
    free(deskgr);
1126
    for (unsigned short i = 0; i < type; i++)
1127
        free(bnum[i]);
1128
    free(bnum);
1129
}
1130
int main()
1131
{
1132
    setlocale(LC_ALL, "Russian");
1133
    unsigned short list_size = 0;
1134
    struct result* list = (struct result*)malloc(list_size * sizeof(struct result));
1135
    FILE* fin = fopen("results.bin", "rbe");
1136
    if (fin == NULL)
1137
    {
1138
        FILE* create = fopen("results.bin", "wbe");
1139
        fclose(create);
1140
    }
1141
    else
1142
    {
1143
        while (!feof(fin))
1144
        {
1145
            struct result guy;
1146
            unsigned short name_sz = 0, games = 0, vic = 0, iz = 0, hrd = 0, slayer = 0;
1147
            double pr = 0.0;
1148
            char x = 0;
1149
            fread(&name_sz, sizeof(unsigned short), 1, fin);
1150
            if (name_sz != 0)
1151
            {
1152
                char* namez = (char*)malloc((name_sz + 1) * sizeof(char));
1153
                for (unsigned short i = 0; i < name_sz; i++)
1154
                {
1155
                    fread(&x, sizeof(char), 1, fin);
1156
                    namez[i] = x;
1157
                }
1158
                namez[name_sz] = '\0';
1159
                fread(&games, sizeof(unsigned short), 1, fin);
1160
                fread(&vic, sizeof(unsigned short), 1, fin);
1161
                fread(&pr, sizeof(double), 1, fin);
1162
                fread(&iz, sizeof(unsigned short), 1, fin);
1163
                fread(&hrd, sizeof(unsigned short), 1, fin);
1164
                fread(&slayer, sizeof(unsigned short), 1, fin);
1165
                guy.name = namez;
1166
                guy.games = games;
1167
                guy.victories = vic;
1168
                guy.percent = pr;
1169
                guy.izzy = iz;
1170
                guy.hard = hrd;
1171
                guy.doom_guy = slayer; /*ОСТОРОЖНО, СПОЙЛЕР К DOOM ETERNAL :)*/
1172
                list_size++;
1173
                list = (struct result*)realloc(list, list_size * sizeof(struct result));
1174
                list[list_size - 1] = guy;
1175
            }
1176
            else
1177
                break;
1178
        }
1179
        fclose(fin);
1180
    }
1181
    unsigned short choice = 0, gm_ch = 0, res_ch = 0;
1182
    char* CHOICE = (char*)malloc(0);
1183
    char* GAME_CH = (char*)malloc(0);
1184
    char* RES_CH = (char*)malloc(0);
1185
    char* away = (char*)malloc(0);
1186
    char* resaw = (char*)malloc(0);
1187
    bool g8sch = false;
1188
    bool g16sch = false;
1189
    bool g32sch = false;
1190
    do
1191
    {
1192
        g8sch = false;
1193
        g16sch = false;
1194
        g32sch = false;
1195
        do
1196
        {
1197
            printf("ххххх_САПЁР_ххххх\n");
1198
            printf("1.Играть\n2.Рекорды\n3.Выход\n");
1199
            printf("Введите ЦИФРУ, чтобы выполнить действие: ");
1200
            scanf_rng("%2s", CHOICE);
1201
            if (*CHOICE != 49 && *CHOICE != 50 && *CHOICE != 51 || CHOICE[1] != 0)
1202
                printf("Ввод не корректен\n");
1203
        }
1204
        while (*CHOICE != 49 && *CHOICE != 50 && *CHOICE != 51 || CHOICE[1] != 0);
1205
        switch (*CHOICE)
1206
        {
1207
            case 49:
1208
                choice = 1;
1209
                break;
1210
            case 50:
1211
                choice = 2;
1212
                break;
1213
            default:
1214
                choice = 3;
1215
                break;
1216
        }
1217
        struct result player;
1218
        switch (choice)
1219
        {
1220
            case 1:
1221
                printf("Введите ваше имя (максимум 15 символов): ");
1222
                char* name = (char*)malloc(15 * sizeof(char));
1223
                scanf_rng("%15s", name);
1224
                player.name = name;
1225
                do
1226
                {
1227
                    printf("Выберите уровень сложности: 1.Просто(доска 8x8, 16 мин); 2.Не так просто(доска 16x16, 32 мины); 3.ХАРДКОР(доска 32x32, 64 мины); 4.Своя игра: ");
1228
                    scanf_rng("%2s", GAME_CH);
1229
                    if (*GAME_CH != 49 && *GAME_CH != 50 && *GAME_CH != 51 && *GAME_CH != 52 || GAME_CH[1] != 0)
1230
                        printf("Ввод не корректен\n");
1231
                }
1232
                while (*GAME_CH != 49 && *GAME_CH != 50 && *GAME_CH != 51 && *GAME_CH != 52 || GAME_CH[1] != 0);
1233
                switch (*GAME_CH)
1234
                {
1235
                    case 49:
1236
                        gm_ch = 1;
1237
                        break;
1238
                    case 50:
1239
                        gm_ch = 2;
1240
                        break;
1241
                    case 51:
1242
                        gm_ch = 3;
1243
                        break;
1244
                    default:
1245
                        gm_ch = 4;
1246
                        break;
1247
                }
1248
                switch (gm_ch)
1249
                {
1250
                    case 1:
1251
                        for (unsigned short e = 0; e < list_size; e++)
1252
                        {
1253
                            if (strcmp(list[e].name, player.name) == 0)
1254
                            {
1255
                                g8sch = true;
1256
                                game(list, list[e], 8);
1257
                                if (victory)
1258
                                {
1259
                                    list[e].victories++;
1260
                                    list[e].izzy++;
1261
                                    victory = false;
1262
                                }
1263
                                list[e].games++;
1264
                                list[e].percent = (list[e].victories / (list[e].games / 100.0));
1265
                                break;
1266
                            }
1267
                        }
1268
                        if (!g8sch)
1269
                        {
1270
                            player.victories = 0;
1271
                            player.izzy = 0;
1272
                            player.hard = 0;
1273
                            player.doom_guy = 0;
1274
                            game(list, player, 8);
1275
                            if (victory)
1276
                            {
1277
                                player.victories = 1;
1278
                                player.izzy = 1;
1279
                                victory = false;
1280
                            }
1281
                            player.games = 1;
1282
                            player.percent = (player.victories / (player.games / 100.0));
1283
                            list_size++;
1284
                            list = (struct result*)realloc(list, list_size * sizeof(struct result));
1285
                            list[list_size - 1] = player;
1286
                        }
1287
                        save(list, list_size);
1288
                        break;
1289
                    case 2:
1290
                        for (unsigned short e = 0; e < list_size; e++)
1291
                        {
1292
                            if (strcmp(list[e].name, player.name) == 0)
1293
                            {
1294
                                g16sch = true;
1295
                                game(list, list[e], 16);
1296
                                if (victory)
1297
                                {
1298
                                    list[e].victories++;
1299
                                    list[e].hard++;
1300
                                    victory = false;
1301
                                }
1302
                                list[e].games++;
1303
                                list[e].percent = (list[e].victories / (list[e].games / 100.0));
1304
                                break;
1305
                            }
1306
                        }
1307
                        if (!g16sch)
1308
                        {
1309
                            player.victories = 0;
1310
                            player.izzy = 0;
1311
                            player.hard = 0;
1312
                            player.doom_guy = 0;
1313
                            game(list, player, 16);
1314
                            if (victory)
1315
                            {
1316
                                player.victories = 1;
1317
                                player.hard = 1;
1318
                                victory = false;
1319
                            }
1320
                            player.games = 1;
1321
                            player.percent = (player.victories / (player.games / 100.0));
1322
                            list_size++;
1323
                            list = (struct result*)realloc(list, list_size * sizeof(struct result));
1324
                            list[list_size - 1] = player;
1325
                        }
1326
                        save(list, list_size);
1327
                        break;
1328
                    case 3:
1329
                        for (unsigned short e = 0; e < list_size; e++)
1330
                        {
1331
                            if (strcmp(list[e].name, player.name) == 0)
1332
                            {
1333
                                g32sch = true;
1334
                                game(list, list[e], 32);
1335
                                if (victory)
1336
                                {
1337
                                    list[e].victories++;
1338
                                    list[e].doom_guy++;
1339
                                    victory = false;
1340
                                }
1341
                                list[e].games++;
1342
                                list[e].percent = (list[e].victories / (list[e].games / 100.0));
1343
                                break;
1344
                            }
1345
                        }
1346
                        if (!g32sch)
1347
                        {
1348
                            player.victories = 0;
1349
                            player.izzy = 0;
1350
                            player.hard = 0;
1351
                            player.doom_guy = 0;
1352
                            game(list, player, 32);
1353
                            if (victory)
1354
                            {
1355
                                player.victories++;
1356
                                player.doom_guy++;
1357
                                victory = false;
1358
                            }
1359
                            player.games = 1;
1360
                            player.percent = (player.victories / (player.games / 100.0));
1361
                            list_size++;
1362
                            list = (struct result*)realloc(list, list_size * sizeof(struct result));
1363
                            list[list_size - 1] = player;
1364
                        }
1365
                        save(list, list_size);
1366
                        break;
1367
                    default:
1368
                        for (unsigned short e = 0; e < list_size; e++)
1369
                        {
1370
                            if (strcmp(list[e].name, player.name) == 0)
1371
                            {
1372
                                g8sch = true;
1373
                                game(list, list[e], 1);
1374
                                if (victory)
1375
                                {
1376
                                    list[e].victories++;
1377
                                    victory = false;
1378
                                }
1379
                                list[e].games++;
1380
                                list[e].percent = (list[e].victories / (list[e].games / 100.0));
1381
                                break;
1382
                            }
1383
                        }
1384
                        if (!g8sch)
1385
                        {
1386
                            player.victories = 0;
1387
                            player.izzy = 0;
1388
                            player.hard = 0;
1389
                            player.doom_guy = 0;
1390
                            game(list, player, 1);
1391
                            if (victory)
1392
                            {
1393
                                player.victories = 1;
1394
                                victory = false;
1395
                            }
1396
                            player.games = 1;
1397
                            player.percent = (player.victories / (player.games / 100.0));
1398
                            list_size++;
1399
                            list = (struct result*)realloc(list, list_size * sizeof(struct result));
1400
                            list[list_size - 1] = player;
1401
                        }
1402
                        save(list, list_size);
1403
                        break;
1404
                }
1405
                break;
1406
            case 2:
1407
                do
1408
                {
1409
                    printf("Результаты\n");
1410
                    do
1411
                    {
1412
                        printf(
1413
                                "1.Сыграно игр\n2.Побед на сложности 'легко'\n3.Побед на сложности 'не так легко'\n4.Побед на сложности 'ХАРДКОР'\n5.Процент побед.\n6.Выход\n");
1414
                        printf("Выберите ЦИФРУ действия: ");
1415
                        scanf_rng("%2s", RES_CH);
1416
                        if (*RES_CH != 49 && *RES_CH != 50 && *RES_CH != 51 && *RES_CH != 52 && *RES_CH != 53 && *RES_CH !=54 || RES_CH[1] != 0)
1417
                            printf("Ввод не корректен\n");
1418
                    }
1419
                    while (*RES_CH != 49 && *RES_CH != 50 && *RES_CH != 51 && *RES_CH != 52 && *RES_CH != 53 && *RES_CH != 54 || RES_CH[1] != 0);
1420
                    switch (*RES_CH)
1421
                    {
1422
                        case 49:
1423
                            res_ch = 1;
1424
                            break;
1425
                        case 50:
1426
                            res_ch = 2;
1427
                            break;
1428
                        case 51:
1429
                            res_ch = 3;
1430
                            break;
1431
                        case 52:
1432
                            res_ch = 4;
1433
                            break;
1434
                        case 53:
1435
                            res_ch = 5;
1436
                            break;
1437
                        default:
1438
                            res_ch = 6;
1439
                            break;
1440
                    }
1441
                    switch (res_ch)
1442
                    {
1443
                        case 1:
1444
                            if (list_size == 0)
1445
                                printf("Ещё никто не играл...\n");
1446
                            else
1447
                            {
1448
                                qsort(list, list_size, sizeof(*list), compare_games);
1449
                                for (unsigned short i = list_size; i > 0; i--)
1450
                                    printf("%s : %hu\n", list[i - 1].name, list[i - 1].games);
1451
                            }
1452
                            break;
1453
                        case 2:
1454
                            if (list_size == 0)
1455
                                printf("Ещё никто не играл...\n");
1456
                            else
1457
                            {
1458
                                qsort(list, list_size, sizeof(*list), compare_izzy);
1459
                                for (unsigned short i = list_size; i > 0; i--)
1460
                                    printf("%s : %hu\n", list[i - 1].name, list[i - 1].izzy);
1461
                            }
1462
                            break;
1463
                        case 3:
1464
                            if (list_size == 0)
1465
                                printf("Ещё никто не играл...\n");
1466
                            else
1467
                            {
1468
                                qsort(list, list_size, sizeof(*list), compare_hard);
1469
                                for (unsigned short i = list_size; i > 0; i--)
1470
                                    printf("%s : %hu\n", list[i - 1].name, list[i - 1].hard);
1471
                            }
1472
                            break;
1473
                        case 4:
1474
                            if (list_size == 0)
1475
                                printf("Ещё никто не играл...\n");
1476
                            else
1477
                            {
1478
                                qsort(list, list_size, sizeof(*list), compare_doom);
1479
                                for (unsigned short i = list_size; i > 0; i--)
1480
                                    printf("%s : %hu\n", list[i - 1].name, list[i - 1].doom_guy);
1481
                            }
1482
                            break;
1483
                        case 5:
1484
                            if (list_size == 0)
1485
                                printf("Ещё никто не играл...\n");
1486
                            else
1487
                            {
1488
                                qsort(list, list_size, sizeof(*list), compare_percent);
1489
                                for (unsigned short i = list_size; i > 0; i--)
1490
                                {
1491
                                    int perc = list[i - 1].percent;
1492
                                    printf("%s : %d%%\n", list[i - 1].name, perc);
1493
                                }
1494
                            }
1495
                            break;
1496
                        default:
1497
                            printf("Вы точно хотите выйти? Введите YES, если да или что-то другое, если нет.\n");
1498
                            scanf_rng("%4s", resaw);
1499
                            if (strcmp(resaw, "YES") != 0)
1500
                                res_ch = 0;
1501
                            break;
1502
                    }
1503
                }
1504
                while (res_ch != 6);
1505
                break;
1506
            default:
1507
                printf("Вы точно хотите выйти? Введите YES, если да или что-то другое, если нет.\n");
1508
                scanf_rng("%4s", away);
1509
                if (strcmp(away, "YES") != 0)
1510
                    choice = 0;
1511
                break;
1512
        }
1513
    }
1514
    while (choice != 3);
1515
    return 0;
1516
}

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.