diff --git a/location.c b/location.c index 36b402e2fd5bd98250ab77cce77f50d5ce0a3fba..a102f101b6f390608b7dc1eaa03e2f7b033bfde9 100644 --- a/location.c +++ b/location.c @@ -1,28 +1,30 @@ #include "location.h" #include <string.h> /* strdup */ -#include <stdio.h> /* printf */ +#include <stdio.h> /* printf */ #include <stdlib.h> /* malloc, free */ + + + Location *LocationNew(char *name, char *desc) { - Location *ret = (Location *)NULL; - if (name && desc) /** && where)**/ + Location *ret=(Location*)NULL; + if (name && desc)/** && where)**/ { - ret = malloc(sizeof(Location)); - ret->name = strdup(name); - ret->desc = strdup(desc); + 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); + if (m->name) free(m->name); + if (m->desc) free(m->desc); free(m); } return (Location *)NULL; @@ -30,13 +32,12 @@ Location *LocationDelete(Location *m) void LocationPrint(Location *m) { - if (m) - printf("%s\n%s\n", m->name, m->desc); + if (m) printf("%s\n%s\n",m->name,m->desc); } -Location *LocationInit() + +Location *LocationInit() { - //creation variables for room Location *Startloc; Location *OnTheRoadtwo; Location *OnTheRoadthree; @@ -49,36 +50,32 @@ Location *LocationInit() 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", ""); - + + + 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) + + if (direction >= NORTH && direction <= DOWN) { - l1->directions[direction] = l2; + 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 +} \ No newline at end of file