示例#1
0
int Room_attack(void *self, int damage) {
  Room *room = self;
  Monster *monster = room->bad_guy;

  if(monster) {
    monster->_(attack)(monster, damage);
    return 1;
  } else {
    printf("You flail in the air at nothing. Idiot.\n");
    return 0;
  }
}
示例#2
0
文件: fourteen.c 项目: aewens/learnc
int Room_attack(void *self, int damage)
{
    Room *room = self;
    Monster *monster = room->bad_guy;
    
    if(monster) {
        monster->_(attack)(monster, damage);
        return 1;
    } else {
        printf("You run in screaming for no reason. Good job.\n");
        return 0;
    }
}
示例#3
0
文件: ex19.c 项目: jadan/LCTHW
int Monster_attack(void *self, int damage){
	Monster* monster = self;
	printf("You attack %s!\n", monster->_(description));
	monster->hit_points -=damage;

	if(monster->hit_points > 0){
		printf("It is still alive.\n");
		return 0;
	}else{
		printf("It is dead!\n");
		return 1;
	}
}
示例#4
0
int Room_attack(void *self, int damage){
	assert(self != NULL);

	Room *room = self;
	Monster *monster = room->bad_guy;

	if(monster){
		monster->_(attack)(monster, damage);
		return 1;
	} else {
		assert(! (printf("You flail in the air at nothing.\n") < 0));
		return 0;
	}
}
示例#5
0
文件: game.c 项目: wolverian/lcthw
bool Room_attack(void *self, int damage) {
	assert(self != NULL);
	assert(damage >= 0);

	Room *room = self;
	Monster *monster = room->bad_guy;

	if (monster) {
		monster->_(attack)(monster, damage);
		return true;
	} else {
		printf("You flail in the air at nothing.\n");
		return false;
	}
}
示例#6
0
int Monster_attack(void *self, int damage) {
    Monster *monster = self;

    // obj->_(func) == obj->proto.func
    printf("You attack %s!\n", monster->_(description));

    monster->hit_points -= damage;

    if (monster->hit_points > 0) {
        puts("It is still alive.");
        return 0;
    }
    else {
        puts("It is dead.");
        return 1;
    }
}
示例#7
0
文件: ex19.c 项目: osynetskyi/hardc
int Monster_attack(void *self, int damage)
{
	assert(damage > 0);
	Monster *monster = self;
	
	printf("You attack %s! You inflict %d damage!\n", monster->_(description), damage);

	monster->hit_points -= damage;

	if(monster->hit_points > 0) {
		printf("It is still alive, it has %d hp left.\n", monster->hit_points);
		return 0;
	} else {
		printf("It is dead!\n");
		return 1;
	}
}
示例#8
0
文件: ex19.c 项目: kylegalloway/LCTHW
/*
 * Asserts:
 *     'damage' is not null.
 *     'damage' is not negative.
 */
int Room_attack(void *self, int damage)
{
    Room *room = self;
    Monster *monster = room->bad_guy;

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

    if(monster) {
        monster->_(attack)(monster, damage);
        return 1;
    } else {
        printf("You flail in the air at nothing. Idiot.\n");
        return 0;
    }
}
示例#9
0
文件: game.c 项目: wolverian/lcthw
bool Monster_attack(void *self, int damage) {
	assert(self != NULL);
	assert(damage >= 0);

	Monster *monster = self;

	printf("You attack %s!\n", monster->_(description));

	monster->hit_points -= damage;

	if (monster->hit_points > 0) {
		printf("It is still alive.\n");
		return false;
	} else {
		printf("It is dead!\n");
		return true;
	}
}
示例#10
0
int Monster_attack(void *self, int damage)
{
	assert(self != NULL);

	Monster *monster = self;

	assert(! (printf("You attack %s!\n", monster->_(description)) < 0));

	monster->hit_points -= damage;

	if(monster->hit_points > 0){
		assert(! (printf("It is still alive.\n") < 0));
		return 0;
	} else {
		assert(! (printf("It is dead!\n") < 0));
		return 1;
	}
}
示例#11
0
int Room_attack(void *self, int damage)
{
	Room *room = self;
	Monster *monster = room->bad_guy;

	if(monster) {
		// monster->proto.attack which is a 
		// function pointer to Monster_attack
		// (or Object_attack if not overriden)
		// which we call with monster and damage
		// as args.
		monster->_(attack) (monster, damage);
		return 1;
	} else {
		printf("You flail in the air at nothin. Idiot.\n");
		return 0;
	}
}
示例#12
0
int Monster_attack(void *self, int damage)
{
    Monster *monster = self;

    printf("You attack %s for %dhp of damage\n", monster->_(description), damage);

    monster->hit_points -= damage;

    if(monster->hit_points > 0) {
        printf("It is still alive and has %dhp remaining\n.",
                monster->hit_points);
        return 0;
    } else {
        printf("It is dead! it drops %d gold coins\n",
                monster->loot);
        return 1;
    }
}
示例#13
0
int Monster_attack(void *self, int damage)
{
	// Store a pointer to our object on the stack
	Monster *monster = self;

	// monster->_(description) macros into
	// monster->proto.description
	printf("You attack %s!\n", monster->_(description));

	monster->hit_points -= damage;

	if(monster->hit_points > 0) {
		printf("It is still alive.\n");
		return 0;
	} else {
		printf("It is dead!\n");
		return 1;
	}
}