Advertisement
xth

bug

xth
May 31st, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <stdlib.h>
  4. #define     MAP_WIDTH   16
  5. #define     MAP_HEIGHT  8
  6.  
  7. struct tile {
  8.     uint16_t Population;
  9.     char People[4];
  10. };
  11.  
  12. int main()
  13. {
  14.     srand(time(NULL));
  15.     struct tile Map[MAP_HEIGHT][MAP_WIDTH];
  16.     // initialize map with random values
  17.     int X = 0; int Y = 0;
  18.     while (Y < MAP_HEIGHT) {
  19.         while (X < MAP_WIDTH) {
  20.             int r = rand() % 512;
  21.             Map[Y][X].Population = r;
  22.             if (r < 16) {
  23.                 Map[Y][X].People[0] = '.';
  24.                 Map[Y][X].People[1] = ' ';
  25.                 Map[Y][X].People[2] = ' ';
  26.                 Map[Y][X].People[3] = '\0';
  27.             }
  28.             else if (r < 32)
  29.             {
  30.                 Map[Y][X].People[0] = '.';
  31.                 Map[Y][X].People[1] = '.';
  32.                 Map[Y][X].People[2] = ' ';
  33.                 Map[Y][X].People[3] = '\0';
  34.             }
  35.  
  36.             else if (r < 64)
  37.             {
  38.                 Map[Y][X].People[0] = '.';
  39.                 Map[Y][X].People[1] = '.';
  40.                 Map[Y][X].People[2] = '.';
  41.                 Map[Y][X].People[3] = '\0';
  42.             }
  43.             else if (r < 96)
  44.             {
  45.                 Map[Y][X].People[0] = '.';
  46.                 Map[Y][X].People[1] = '.';
  47.                 Map[Y][X].People[2] = ':';
  48.                 Map[Y][X].People[3] = '\0';
  49.             }
  50.             else if (r < 128){
  51.                 Map[Y][X].People[0] = '.';
  52.                 Map[Y][X].People[1] = ':';
  53.                 Map[Y][X].People[2] = ':';
  54.                 Map[Y][X].People[3] = '\0';
  55.             }
  56.             else if (r == 128){
  57.                 Map[Y][X].People[0] = ':';
  58.                 Map[Y][X].People[1] = ':';
  59.                 Map[Y][X].People[2] = ':';
  60.                 Map[Y][X].People[3] = '\0';
  61.             } else {                   
  62.                 Map[Y][X].People[0] = 'W';
  63.                 Map[Y][X].People[1] = '=';
  64.                 Map[Y][X].People[2] = 'W';
  65.                 Map[Y][X].People[3] = '\0';
  66.             }
  67.             ++X;
  68.         }
  69.         ++Y;
  70.     }
  71.  
  72.     system("cls");
  73.     int x = 0; int y = 0;
  74.     while (y < MAP_HEIGHT) {
  75.  
  76.         while (x < MAP_WIDTH) {
  77.             printf("%s ", Map[y][x].People);
  78.             ++x;
  79.         }
  80.         printf("\n");
  81.         ++y;
  82.     }
  83.  
  84.  
  85.     printf("sizeof map : %zd\n", sizeof(Map));
  86.     x = 0;
  87.     y = 0;
  88.     int x2 = x+MAP_WIDTH;
  89.     int y2 = y+MAP_HEIGHT;
  90.     while (y < y2) {
  91.         while (x < x2) {
  92.             printf("map[%d][%d].Population : %d\n", y, x, Map[y][x].Population);
  93.             ++x;
  94.         }
  95.         ++y;
  96.     }
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement