|
|
|
@ -3,11 +3,13 @@
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include "ex19.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Monster_attack(void *self, int damage)
|
|
|
|
|
{
|
|
|
|
|
assert(self != NULL);
|
|
|
|
|
Monster *monster = self;
|
|
|
|
|
|
|
|
|
|
printf("You attack %s!\n", monster->_(description));
|
|
|
|
@ -25,6 +27,7 @@ int Monster_attack(void *self, int damage)
|
|
|
|
|
|
|
|
|
|
int Monster_init(void *self)
|
|
|
|
|
{
|
|
|
|
|
assert(self != NULL);
|
|
|
|
|
Monster *monster = self;
|
|
|
|
|
monster->hit_points = 10;
|
|
|
|
|
return 1;
|
|
|
|
@ -38,6 +41,7 @@ Object MonsterProto = {
|
|
|
|
|
|
|
|
|
|
void *Room_move(void *self, Direction direction)
|
|
|
|
|
{
|
|
|
|
|
assert(self != NULL);
|
|
|
|
|
Room *room = self;
|
|
|
|
|
Room *next = NULL;
|
|
|
|
|
|
|
|
|
@ -68,6 +72,7 @@ void *Room_move(void *self, Direction direction)
|
|
|
|
|
|
|
|
|
|
int Room_attack(void *self, int damage)
|
|
|
|
|
{
|
|
|
|
|
assert(self != NULL);
|
|
|
|
|
Room *room = self;
|
|
|
|
|
Monster *monster = room->bad_guy;
|
|
|
|
|
|
|
|
|
@ -89,6 +94,7 @@ Object RoomProto = {
|
|
|
|
|
|
|
|
|
|
void *Map_move(void *self, Direction direction)
|
|
|
|
|
{
|
|
|
|
|
assert(self != NULL);
|
|
|
|
|
Map *map = self;
|
|
|
|
|
Room *location = map->location;
|
|
|
|
|
Room *next = NULL;
|
|
|
|
@ -104,6 +110,7 @@ void *Map_move(void *self, Direction direction)
|
|
|
|
|
|
|
|
|
|
int Map_attack(void *self, int damage)
|
|
|
|
|
{
|
|
|
|
|
assert(self != NULL);
|
|
|
|
|
Map *map = self;
|
|
|
|
|
Room *location = map->location;
|
|
|
|
|
|
|
|
|
@ -113,6 +120,7 @@ int Map_attack(void *self, int damage)
|
|
|
|
|
|
|
|
|
|
int Map_init(void *self)
|
|
|
|
|
{
|
|
|
|
|
assert(self != NULL);
|
|
|
|
|
Map *map = self;
|
|
|
|
|
|
|
|
|
|
// make some rooms for a small map
|
|
|
|
@ -149,6 +157,7 @@ Object MapProto = {
|
|
|
|
|
|
|
|
|
|
int process_input(Map *game)
|
|
|
|
|
{
|
|
|
|
|
assert(game != NULL);
|
|
|
|
|
printf("\n> ");
|
|
|
|
|
|
|
|
|
|
char ch = getchar();
|
|
|
|
@ -204,6 +213,7 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
|
|
|
|
// make our map to work with
|
|
|
|
|
Map *game = NEW(Map, "The Hall of the Minotaur.");
|
|
|
|
|
assert(game != NULL);
|
|
|
|
|
|
|
|
|
|
printf("You enter the ");
|
|
|
|
|
game->location->_(describe)(game->location);
|
|
|
|
|