forked from larryv/learn-c-the-hard-way
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex19.c
87 lines (64 loc) · 2.09 KB
/
ex19.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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
#include "game.h"
extern Object MapProto;
extern Object MonsterProto;
extern Object RoomProto;
int process_input(Map *game);
int Map_init(void *self)
{
assert(self);
Map *map = self;
/* make some rooms for a small map */
Room *hall = NEW(Room, "The great Hall");
Room *throne = NEW(Room, "The throne room");
Room *arena = NEW(Room, "The arena, with the minotaur");
Room *kitchen = NEW(Room, "Kitchen, you have the knife now");
/* extra credit: add more rooms */
Room *dungeon = NEW(Room, "The dungeon, with the chimera");
Room *keep = NEW(Room, "The keep, with the hydra");
Room *pantry = NEW(Room, "The overflowing pantry");
Room *courtyard = NEW(Room, "The beautiful courtyard, with the troll");
Room *garden = NEW(Room, "The fertile garden");
/* put the bad guy in the arena */
arena->bad_guy = NEW(Monster, "The evil minotaur");
/* extra credit: add more bad guys */
dungeon->bad_guy = NEW(Monster, "the vicious chimera");
keep->bad_guy = NEW(Monster, "the deadly hydra");
courtyard->bad_guy = NEW(Monster, "the ruthless troll");
/* set up the map rooms */
hall->north = throne;
throne->west = arena;
throne->east = kitchen;
throne->south = hall;
arena->east = throne;
kitchen->west = throne;
arena->north = dungeon;
dungeon->south = arena;
throne->north = keep;
keep->south = throne;
kitchen->south = pantry;
pantry->north = kitchen;
hall->south = courtyard;
courtyard->north = hall;
kitchen->east = garden;
garden->west = kitchen;
/* start the map and the character off in the hall */
map->start = hall;
map->location = hall;
return 1;
}
int main(int argc, const char **argv)
{
/* simple way to set up the randomness */
srand(time(NULL));
/* make our map to work with */
Map *game = NEW(Map, "The Hall of the Minotaur.");
printf("You enter the ");
game->location->_(describe)(game->location);
while (process_input(game))
;
return 0;
}