diff --git a/location.c b/location.c new file mode 100644 index 0000000000000000000000000000000000000000..36b402e2fd5bd98250ab77cce77f50d5ce0a3fba --- /dev/null +++ b/location.c @@ -0,0 +1,84 @@ +#include "location.h" +#include <string.h> /* strdup */ +#include <stdio.h> /* printf */ +#include <stdlib.h> /* malloc, free */ + +Location *LocationNew(char *name, char *desc) +{ + Location *ret = (Location *)NULL; + if (name && desc) /** && where)**/ + { + ret = malloc(sizeof(Location)); + ret->name = strdup(name); + ret->desc = strdup(desc); + } + return ret; +} + +Location *LocationDelete(Location *m) +{ + if (m) + { + if (m->name) + free(m->name); + if (m->desc) + free(m->desc); + free(m); + } + return (Location *)NULL; +} + +void LocationPrint(Location *m) +{ + if (m) + printf("%s\n%s\n", m->name, m->desc); +} + +Location *LocationInit() +{ + //creation variables for room + Location *Startloc; + Location *OnTheRoadtwo; + Location *OnTheRoadthree; + Location *frontyard; + Location *Entrance; + Location *Diningroom; + Location *Kitchen; + Location *Laundryroom; + Location *Office; + Location *Livingroom; + Location *Atticroom; + Location *Cellarroom; + + //call LocationNew to create the room inisde the game + Startloc = LocationNew("On the road", "The road continues north and south. You can see a house on the west."); + OnTheRoadtwo = LocationNew("On the road", ""); + OnTheRoadthree = LocationNew("On the road", ""); + frontyard = LocationNew("Front yard", ""); + Entrance = LocationNew("Entrance", ""); + Diningroom = LocationNew("Dining room", ""); + Kitchen = LocationNew("Kitchen room", ""); + Laundryroom = LocationNew("Laundry room", ""); + Office = LocationNew("Office", ""); + Livingroom = LocationNew("Living room", ""); + Atticroom = LocationNew("Attic room", ""); + Cellarroom = LocationNew("Cellar room", ""); + + return Startloc; +} + +void LocationSetExit(Location *l1, Direction direction, Location *l2) +{ + if (direction >= NORTH && direction <= DOWN) + { + l1->directions[direction] = l2; + } +} + +// stack LocationDestroy(stack *s) { +// stack tmp = s; +// while(StackIsEmpty(tmp) == false) { +// LocationDestroy(Stackhead(tmp)); +// tmp= stackPop(tmp); +// } +// } \ No newline at end of file