コード例 #1
0
void *Room_move(void *self, Direction direction)
{
    Room *room = self;
    Room *next = NULL;

    if(direction == NORTH && room->north) {
        printf("You go north, into:\n");
        next = room->north;
    } else if(direction == SOUTH && room->south) {
        printf("You go south, into:\n");
        next = room->south;
    } else if(direction == EAST && room->east) {
        printf("You go east, into:\n");
        next = room->east;
    } else if(direction == WEST && room->west) {
        printf("You go west, into:\n");
        next = room->west;
    } else {
        printf("You can't go that direction.");
        next = NULL;
    }

    if(next) {
        next->_(describe)(next);
    }

    return next;
}
コード例 #2
0
void *Room_move(void *self, Direction direction)
{
	assert(self != NULL);
	assert(direction == NORTH || direction == SOUTH ||
		   direction == EAST  || direction == WEST);

	Room *room = self;
	Room *next = NULL;

	if(direction == NORTH && room->north){
		assert(! (printf("You go north, into:\n") < 0));
		next = room->north;
	} else if(direction == SOUTH && room->south){
		assert(! (printf("You go south into:\n") < 0));
		next = room->south;
	} else if(direction == EAST && room->east){
		assert(! (printf("You go east into:\n") < 0));
		next = room->east;
	} else if(direction == WEST && room->west){
		assert(! (printf("You go west into:\n") < 0));
		next = room->west;
	} else {
		assert(! (printf("You can't go in that direction!\n") < 0));
		next = NULL;
	}

	if(next){
		next->_(describe)(next);
	}

	return next;
}
コード例 #3
0
int Map_attack(void *self, int damage)
{
    Map* map = self;
    Room *location = map->location;

    return location->_(attack)(location, damage);
}
コード例 #4
0
ファイル: game.c プロジェクト: wolverian/lcthw
bool Map_attack(void *self, int damage) {
	assert(self != NULL);
	assert(damage >= 0);

	Map *map = self;
	Room *location = map->location;

	return location->_(attack)(location, damage);
}
コード例 #5
0
ファイル: ex19.c プロジェクト: beepscore/LearnCTheHardWay
int Map_attack(void *self, int damage)
{
    Map* map = self;
    Room *location = map->location;

    // macro expands statement to location->proto.attack(location, damage)
    // this calls Room_attack
    return location->_(attack)(location, damage);
}
コード例 #6
0
ファイル: ex19.c プロジェクト: OlegIvanov/lcthw
int Map_attack(void *self, int damage)
{
	assert(self);
	assert(((Map*)self)->location);

	Map *map = self;
	Room *location = map->location;

	return location->_(attack)(location, damage);
}
コード例 #7
0
ファイル: ex19.c プロジェクト: kylegalloway/LCTHW
/*
 * Asserts:
 *     'damage' is not null.
 *     'damage' is not negative.
 */
int Map_attack(void *self, int damage)
{
    Map *map = self;
    Room *location = map->location;

    // Error Catching
    assert(damage != NULL);
    assert(damage >= 0);

    return location->_(attack)(location, damage);
}
コード例 #8
0
ファイル: ex19.c プロジェクト: edek437/LCTHW-Exercises
void *Map_move(void *self, Direction direction) {
    Map *map = self;
    Room *location = map->location;
    Room *next = NULL;

    next = location->_(move)(location, direction);

    if (next)
        map->location = next;

    return next;
}
コード例 #9
0
ファイル: game.c プロジェクト: cdarne/lcthw
void *Map_move(void *self, Direction direction) {
  assert(self != NULL);
  Map *map = self;
  Room *location = map->location;
  Room *next = NULL;

  next = location->_(move)(location, direction);

  if(next) {
    map->location = next;
  }

  return next;
}
コード例 #10
0
ファイル: ex19.c プロジェクト: kylegalloway/LCTHW
/*
 * Asserts:
 *     'direction' is not null.
 */
void *Map_move(void *self, Direction direction)
{
    Map *map = self;
    Room *location = map->location;
    Room *next = NULL;

    // Error Catching
    assert(direction != NULL);

    next = location->_(move)(location, direction);

    if(next) {
        map->location = next;
    }

    return next;
}
コード例 #11
0
ファイル: ex19.c プロジェクト: Micaiah-Chang/LCTHW
void *Map_move(void *self, Direction direction)
{
	 assert(self != NULL);

	 // Should always be in some valid location
	 Map *map = self;
	 Room *location = map->location;
	 Room *next = NULL;
	 assert(map->location != NULL);
	 
	 next = location->_(move)(location, direction);

	 if(next) {
		  map->location = next;
	 }
	 
	 return next;
}
コード例 #12
0
ファイル: ex19.c プロジェクト: toonketels/Learncthehardway
void *Map_move(void *self, Direction direction)
{
	Map *map = self;
	Room *location = map->location;
	Room *next = NULL;

	// We ask a room for it's room in x direction
	// and set that room as the location of the map.
	next = location->_(move)(location, direction);

	if(next) {
		map->location = next;
	}

	// To be on par we return somthing, but we
	// don't really need it.
	return next;
}