Skip to content
Snippets Groups Projects
Commit 40ddd973 authored by JANUZI Rinor's avatar JANUZI Rinor
Browse files

Replace location.c

parent 4ba946c3
No related branches found
No related tags found
No related merge requests found
#include "location.h" #include "location.h"
#include <string.h> /* strdup */ #include <string.h> /* strdup */
#include <stdio.h> /* printf */ #include <stdio.h> /* printf */
#include <stdlib.h> /* malloc, free */ #include <stdlib.h> /* malloc, free */
Location *LocationNew(char *name, char *desc) Location *LocationNew(char *name, char *desc)
{ {
Location *ret = (Location *)NULL; Location *ret=(Location*)NULL;
if (name && desc) /** && where)**/ if (name && desc)/** && where)**/
{ {
ret = malloc(sizeof(Location)); ret=malloc(sizeof(Location));
ret->name = strdup(name); ret->name=strdup(name);
ret->desc = strdup(desc); ret->desc=strdup(desc);
} }
return ret; return ret;
} }
Location *LocationDelete(Location *m) Location *LocationDelete(Location *m)
{ {
if (m) if (m)
{ {
if (m->name) if (m->name) free(m->name);
free(m->name); if (m->desc) free(m->desc);
if (m->desc)
free(m->desc);
free(m); free(m);
} }
return (Location *)NULL; return (Location *)NULL;
...@@ -30,13 +32,12 @@ Location *LocationDelete(Location *m) ...@@ -30,13 +32,12 @@ Location *LocationDelete(Location *m)
void LocationPrint(Location *m) void LocationPrint(Location *m)
{ {
if (m) if (m) printf("%s\n%s\n",m->name,m->desc);
printf("%s\n%s\n", m->name, m->desc);
} }
Location *LocationInit()
Location *LocationInit()
{ {
//creation variables for room
Location *Startloc; Location *Startloc;
Location *OnTheRoadtwo; Location *OnTheRoadtwo;
Location *OnTheRoadthree; Location *OnTheRoadthree;
...@@ -49,36 +50,32 @@ Location *LocationInit() ...@@ -49,36 +50,32 @@ Location *LocationInit()
Location *Livingroom; Location *Livingroom;
Location *Atticroom; Location *Atticroom;
Location *Cellarroom; 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."); Startloc= LocationNew("On the road", "The road continues north and south. You can see a house on the west.");
OnTheRoadtwo = LocationNew("On the road", ""); OnTheRoadtwo = LocationNew("On the road", "");
OnTheRoadthree = LocationNew("On the road", ""); OnTheRoadthree = LocationNew("On the road","");
frontyard = LocationNew("Front yard", ""); frontyard = LocationNew("Front yard","");
Entrance = LocationNew("Entrance", ""); Entrance = LocationNew("Entrance","");
Diningroom = LocationNew("Dining room", ""); Diningroom = LocationNew("Dining room","");
Kitchen = LocationNew("Kitchen room", ""); Kitchen = LocationNew("Kitchen room","");
Laundryroom = LocationNew("Laundry room", ""); Laundryroom = LocationNew("Laundry room","");
Office = LocationNew("Office", ""); Office = LocationNew("Office","");
Livingroom = LocationNew("Living room", ""); Livingroom = LocationNew("Living room","");
Atticroom = LocationNew("Attic room", ""); Atticroom = LocationNew("Attic room","");
Cellarroom = LocationNew("Cellar room", ""); Cellarroom = LocationNew("Cellar room","");
return Startloc; return Startloc;
} }
void LocationSetExit(Location *l1, Direction direction, Location *l2) 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; \ No newline at end of file
// while(StackIsEmpty(tmp) == false) {
// LocationDestroy(Stackhead(tmp));
// tmp= stackPop(tmp);
// }
// }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment