-
Notifications
You must be signed in to change notification settings - Fork 1
/
mapGenerate.c
77 lines (67 loc) · 1.9 KB
/
mapGenerate.c
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
/* This includes the functions for printing the map and generating the map
Program written on 8/04/15
revised on 04/05 with addition of stair placement
*/
#include "mapGenerate.h"
#include <stdio.h>
#include "main.h"
/*
int main () {
int i=0,j=0;
char mapArray[15][15];
for (i = 0; i < MAP_SIZE; i++) { //populates array with empty tiles
for (j = 0; j < MAP_SIZE; j++) {
mapArray[i][j] = '.';
}
}
int roomWidth;
int roomHeight;
generateMap(&roomWidth, &roomHeight);
printMap(mapArray,roomWidth,roomHeight);
return EXIT_SUCCESS;
}
*/
//This main function is for testing purposes only.
void printMap(char mapArray[MAP_SIZE][MAP_SIZE], char entityArray[MAP_SIZE][MAP_SIZE], int roomWidth, int roomHeight) {
int widthcount = 0;
int heightcount = 0;
printHorizontalBound(roomWidth);
printf("\n");
while (heightcount < roomHeight) {
printf(VERTICAL_WALL);
while (widthcount < roomWidth) {
if (entityArray[widthcount][heightcount] == NO_ENTITY) {
printf("%c",mapArray[widthcount][heightcount]);
} else {
printf("%c",entityArray[widthcount][heightcount]);
}
widthcount++;
}
printf(VERTICAL_WALL);
printf("\n");
widthcount = 0;
heightcount++;
}
printHorizontalBound(roomWidth);
printf("\n");
return;
}
void generateMap(int* width, int* height) { //generates random dimensions of room
srand(time(NULL));
*width = randint(12) + 3;
*height = randint(12) +3;
// printf("%d, %d", *width, *height);
return;
}
void printHorizontalBound(int roomWidth) {
int widthcount = 0;
printf(" ");
while (widthcount < roomWidth) {
printf(HORIZONTAL_WALL);
widthcount++;
}
return;
}
void placeStairs(char mapArray[MAP_SIZE][MAP_SIZE], int roomWidth, int roomHeight) {
mapArray[randint(roomWidth)][randint(roomHeight)] = STAIRS;
}