adding new object.h for ch.20 ex.19

This commit is contained in:
Dan Buch 2011-10-25 20:11:42 -04:00
parent aab442042b
commit 237f86c62e
2 changed files with 28 additions and 0 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
!Makefile !Makefile
!README.md !README.md
!*.py !*.py
!*.h

27
object.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef _object_h
#define _object_h
typedef enum {
NORTH, SOUTH, EAST, WEST
} Direction;
typedef struct {
char *description;
int (*init)(void *self);
void (*describe)(void *self);
void (*destroy)(void *self);
void *(*move)(void *self, Direction direction);
int (*attack)(void *self, int damage);
} Object;
int Object_init(void *self);
void Object_destroy(void *self);
void Object_describe(void *self);
void *Object_move(void *self, Direction direction);
int Object_attack(void *self, int damage);
void *Object_new(size_t size, Object proto, char *description);
#define NEW(T, N) Object_new(sizeof(T), T##Proto, N)
#define _(N) proto.N
#endif