/
map.c
65 lines (51 loc) · 1.41 KB
/
map.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
#include <stdio.h>
#include <stdlib.h>
#include "map.h"
#include "room.h"
#include "monster.h"
struct Map * createMap() {
struct Map * map = malloc(sizeof(struct Map));
return map;
}
void initMap(struct Map * map) {
// make rooms
struct Room * hall = createRoom("The Great Hall");
struct Room * throne = createRoom("The Throne Room");
struct Room * arena = createRoom("The Arena");
struct Room * kitchen = createRoom("The Kitchen");
// link rooms
hall->north = throne;
throne->east = kitchen;
throne->south = hall;
throne->west = arena;
arena->east = throne;
kitchen->west = throne;
// add minotaur to arena
arena->bad_guy = createMonster("Minotaur", 12);
// set starting location
map->start = hall;
map->location = map->start;
}
struct Room * mapMove(struct Map * map, Direction direction) {
struct Room * next = NULL;
if (direction == NORTH && map->location->north) {
next = map->location->north;
} else if (direction == SOUTH && map->location->south) {
next = map->location->south;
} else if (direction == EAST && map->location->east) {
next = map->location->east;
} else if (direction == WEST && map->location->west) {
next = map->location->west;
} else {
printf("You can't go in that direction.");
}
if (next) {
map->location = next;
lookRoom(map->location);
}
return map->location;
}
int attackMap(struct Map * map, int damage) {
attackRoom(map->location, damage);
return 0;
}