Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- #define MAP_WIDTH 16
- #define MAP_HEIGHT 8
- struct tile {
- uint16_t Population;
- char People[4];
- };
- int main()
- {
- srand(time(NULL));
- struct tile Map[MAP_HEIGHT][MAP_WIDTH];
- // initialize map with random values
- int X = 0; int Y = 0;
- while (Y < MAP_HEIGHT) {
- while (X < MAP_WIDTH) {
- int r = rand() % 512;
- Map[Y][X].Population = r;
- if (r < 16) {
- Map[Y][X].People[0] = '.';
- Map[Y][X].People[1] = ' ';
- Map[Y][X].People[2] = ' ';
- Map[Y][X].People[3] = '\0';
- }
- else if (r < 32)
- {
- Map[Y][X].People[0] = '.';
- Map[Y][X].People[1] = '.';
- Map[Y][X].People[2] = ' ';
- Map[Y][X].People[3] = '\0';
- }
- else if (r < 64)
- {
- Map[Y][X].People[0] = '.';
- Map[Y][X].People[1] = '.';
- Map[Y][X].People[2] = '.';
- Map[Y][X].People[3] = '\0';
- }
- else if (r < 96)
- {
- Map[Y][X].People[0] = '.';
- Map[Y][X].People[1] = '.';
- Map[Y][X].People[2] = ':';
- Map[Y][X].People[3] = '\0';
- }
- else if (r < 128){
- Map[Y][X].People[0] = '.';
- Map[Y][X].People[1] = ':';
- Map[Y][X].People[2] = ':';
- Map[Y][X].People[3] = '\0';
- }
- else if (r == 128){
- Map[Y][X].People[0] = ':';
- Map[Y][X].People[1] = ':';
- Map[Y][X].People[2] = ':';
- Map[Y][X].People[3] = '\0';
- } else {
- Map[Y][X].People[0] = 'W';
- Map[Y][X].People[1] = '=';
- Map[Y][X].People[2] = 'W';
- Map[Y][X].People[3] = '\0';
- }
- ++X;
- }
- ++Y;
- }
- system("cls");
- int x = 0; int y = 0;
- while (y < MAP_HEIGHT) {
- while (x < MAP_WIDTH) {
- printf("%s ", Map[y][x].People);
- ++x;
- }
- printf("\n");
- ++y;
- }
- printf("sizeof map : %zd\n", sizeof(Map));
- x = 0;
- y = 0;
- int x2 = x+MAP_WIDTH;
- int y2 = y+MAP_HEIGHT;
- while (y < y2) {
- while (x < x2) {
- printf("map[%d][%d].Population : %d\n", y, x, Map[y][x].Population);
- ++x;
- }
- ++y;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement