Example #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;
  }
}
Example #2
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 run in screaming for no reason. Good job.\n");
        return 0;
    }
}
Example #3
0
File: ex19.c Project: 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;
	}
}
Example #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;
	}
}
Example #5
0
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;
	}
}
Example #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;
    }
}
Example #7
0
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;
	}
}
Example #8
0
/*
 * 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;
    }
}
Example #9
0
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;
	}
}
Example #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;
	}
}
Example #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;
	}
}
Example #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;
    }
}
Example #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;
	}
}