forked from syruii/dank-dungeon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapGenerate.c
91 lines (78 loc) · 2.06 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* This includes the functions for printing the map and generating the map
Program written on 8/04/15
*/
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <time.h>
#define VERTICAL_WALL "|"
#define HORIZONTAL_WALL "-"
#define MAP_SIZE 15
void printMap(char mapArray[][MAP_SIZE], int roomWidth, int roomHeight); //have to pass second dimension of array
void generateMap(int* Width, int* Height);
int randint(int n);
void printHorizontalBound(int roomWidth);
/*
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], int roomWidth, int roomHeight) {
int widthcount = 0;
int heightcount = 0;
printHorizontalBound(roomWidth);
printf("\n");
while (heightcount < roomHeight) {
printf(VERTICAL_WALL);
while (widthcount < roomWidth) {
printf("%c",mapArray[heightcount][widthcount]);
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;
}
int randint(int n) { //does this random function even work - it does
if ((n-1) == RAND_MAX) {
return rand();
} else {
long end = RAND_MAX / n;
assert (end > 0L);
end *=n;
int r;
while ((r = rand()) >= end);
return r % n;
}
}
void printHorizontalBound(int roomWidth) {
int widthcount = 0;
while (widthcount < roomWidth) {
printf(HORIZONTAL_WALL);
widthcount++;
}
return;
}/