Beispiel #1
7
//RETURNS: 0 on success, -1 o/w
int
shMapLevel::pushCreature (shCreature *c, shDirection dir)
{
    shDirection dirlist[3];
    int r = RNG (1, 2);
    int i;

    dirlist[0] = dir;
    dirlist[r] = (shDirection) ((dir + 1) % 8);
    dirlist[3-r] = (shDirection) ((dir + 7) % 8);

    for (i = 0; i < 3; i++) {
        int x = c->mX;
        int y = c->mY;
        shDirection dir = dirlist[i];

        moveForward (dir, &x, &y);

        if (isObstacle (x, y) or isOccupied (x, y))
            continue;

        return moveCreature (c, x, y);
    }

    if (c->isHero ()) {
        I->p ("You are crushed between the walls!");
    } else if (Hero.canSee (c)) {
        I->p ("%s is crushed!", THE (c));
    }
    c->die (kMisc, "Crushed by a garbage compactor");
    return -1;
}
bool GameTurnTimer::moveCreatureDown(Creature& creature)
{
	std::pair<int,int> loc(creature.getLocation());
	loc.second += 1;
	return moveCreature(creature,loc);
}
bool GameTurnTimer::moveCreatureLeft(Creature& creature)
{
	std::pair<int,int> loc(creature.getLocation());
	loc.first -= 1;
	return moveCreature(creature,loc);
}