Advertisement
HeroBaga

Untitled

Aug 21st, 2021
1,494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.07 KB | None | 0 0
  1. #include <stdio.h>
  2. //Библиотеки которые нужно отключить на маке
  3. #include <conio.h>
  4. #include <stdlib.h>
  5.  
  6. //#define size_x 80
  7. //#define size_y 25
  8.  
  9.  
  10. int size_x = 80, size_y = 25;
  11.  
  12. void game();
  13.  
  14. void simulate();
  15.  
  16. int check(char *core, int y, int x);
  17.  
  18. void display(char *core);
  19.  
  20. int main() {
  21.     game();
  22.     return 0;
  23. }
  24.  
  25. void game() {
  26.     char horizontal = '-';
  27.     char vertical = '|';
  28.     char space = ' ';
  29.     char core[25][80];
  30. //    char help[25][80];
  31.     for (int y = 0; y < size_y; y++) {
  32.         for (int x = 0; x < size_x; x++) {
  33.             if (y == 0 || y == 24) {
  34.                 core[y][x] = horizontal;
  35. //                help[y][x] = horizontal;
  36.             } else if (x == 0 || x == 79) {
  37.                 core[y][x] = vertical;
  38. //                help[y][x] = vertical;
  39.             } else {
  40.                 core[y][x] = space;
  41. //                help[y][x] = space;
  42.             }
  43.         }
  44.     }
  45.     core[4][1] = 'x';
  46.     core[4][2] = 'x';
  47.     core[4][3] = 'x';
  48.     core[3][3] = 'x';
  49.     core[2][2] = 'x';
  50.  
  51.     display(*core);
  52.     //дальше код, который нужно коментить на маке
  53.     int code;
  54.  
  55.     while(1) {
  56.         code = getch();
  57.         if (code == 32) {
  58.             system("@cls||clear");
  59.             simulate(*core);
  60.         }
  61.     }
  62. }
  63.  
  64. void display(char *core) {
  65.     char (*p_array)[size_x] = core;
  66.     for (int y = 0; y < size_y; y++) {
  67.         for (int x = 0; x < size_x; x++) {
  68.             printf("%c", p_array[y][x]);
  69.         }
  70.         printf("%c", '\n');
  71.     }
  72. }
  73.  
  74. void simulate(char *core) {
  75.     // TODO массив support создается через малок, он динамичсеки
  76.     // TODO дописать чтоб перезаписывал core
  77.     int support[size_y][size_x];
  78.     char (*array)[size_x] = core;
  79.     for (int y = 1; y < size_y - 2; y++) {
  80.         for (int x = 1; x < size_x - 2; x++) {
  81.             support[y][x] = check(*array, y, x);
  82.         }
  83.     }
  84.     for(int y = 1; y < size_y-1; y++){
  85.         for(int x = 1; x < size_x-1; x++){
  86.             if(support[y][x] == 3){
  87.                 array[y][x] = 'x';
  88.             }else if(support[y][x] == 2 && array[y][x]== 'x'){
  89.                 array[y][x] = 'x';
  90.             }else{
  91.                 array[y][x] = ' ';
  92.             }
  93.         }
  94.     }
  95.     display(*array);
  96. //    for (int y = 0; y < size_y; y++) {
  97. //        for (int x = 0; x < size_x; x++) {
  98. //            printf("%c", support[y][x]);
  99. //        }
  100. //        printf("%c", '\n');
  101. //    }
  102. //    int a = check(*array, 2,2);
  103. //    printf("%d",a);
  104. }
  105.  
  106. int check(char *core, int y, int x) {
  107.     char (*array)[size_x] = core;
  108.     int count = 0;
  109.     if (array[y - 1][x - 1] == 'x') count++;
  110.     if (array[y - 1][x] == 'x') count++;
  111.     if (array[y - 1][x + 1] == 'x') count++;
  112.     if (array[y][x - 1] == 'x') count++;
  113.     if (array[y][x + 1] == 'x') count++;
  114.     if (array[y + 1][x - 1] == 'x') count++;
  115.     if (array[y + 1][x] == 'x') count++;
  116.     if (array[y + 1][x + 1] == 'x') count++;
  117.     return count;
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement