|
|
|
@ -7,6 +7,8 @@
|
|
|
|
|
|
|
|
|
|
void Object_destroy(void *self)
|
|
|
|
|
{
|
|
|
|
|
assert(self != NULL);
|
|
|
|
|
|
|
|
|
|
Object *obj = self;
|
|
|
|
|
|
|
|
|
|
if(obj) {
|
|
|
|
@ -18,6 +20,8 @@ void Object_destroy(void *self)
|
|
|
|
|
|
|
|
|
|
void Object_describe(void *self)
|
|
|
|
|
{
|
|
|
|
|
assert(self != NULL);
|
|
|
|
|
|
|
|
|
|
Object *obj = self;
|
|
|
|
|
printf("%s\n", obj->description);
|
|
|
|
|
}
|
|
|
|
@ -25,6 +29,8 @@ void Object_describe(void *self)
|
|
|
|
|
|
|
|
|
|
int Object_init(void *self)
|
|
|
|
|
{
|
|
|
|
|
assert(self != NULL);
|
|
|
|
|
|
|
|
|
|
// do nothing really
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
@ -32,6 +38,9 @@ int Object_init(void *self)
|
|
|
|
|
|
|
|
|
|
void *Object_move(void *self, Direction direction)
|
|
|
|
|
{
|
|
|
|
|
assert(self != NULL);
|
|
|
|
|
assert(direction);
|
|
|
|
|
|
|
|
|
|
printf("You can't go that direction.\n");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
@ -39,6 +48,9 @@ void *Object_move(void *self, Direction direction)
|
|
|
|
|
|
|
|
|
|
int Object_attack(void *self, int damage)
|
|
|
|
|
{
|
|
|
|
|
assert(self != NULL);
|
|
|
|
|
assert(damage);
|
|
|
|
|
|
|
|
|
|
printf("You can't attack that.\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -46,7 +58,9 @@ int Object_attack(void *self, int damage)
|
|
|
|
|
|
|
|
|
|
void *Object_new(size_t size, Object proto, char *description)
|
|
|
|
|
{
|
|
|
|
|
assert(size);
|
|
|
|
|
assert(description != NULL);
|
|
|
|
|
|
|
|
|
|
// setup the default functions in case they aren't set
|
|
|
|
|
if(!proto.init) proto.init = Object_init;
|
|
|
|
|
if(!proto.describe) proto.describe = Object_describe;
|
|
|
|
@ -62,6 +76,7 @@ void *Object_new(size_t size, Object proto, char *description)
|
|
|
|
|
|
|
|
|
|
// copy the description over
|
|
|
|
|
el->description = strdup(description);
|
|
|
|
|
assert(el->description != NULL);
|
|
|
|
|
|
|
|
|
|
// initialize it with whatever init we were given
|
|
|
|
|
if(!el->init(el)) {
|
|
|
|
|