Exemple #1
0
void Game::move(Direction d) {
    if (gameOver) {
        return UI::instance()->say("Game Over. Restart or quit.");
    }
    const int ny = player->getY() + d.dy(),
              nx = player->getX() + d.dx();

    LevelObject* obj = level->objectAt(ny, nx);

    if (obj) {
        // Walked into an object. What to do?
        MoveIntoVisitor visitor(*this, d);
        obj->accept(visitor);
        if (!visitor.keepMoving) {
            // Something happened, so don't do anything more.
            return;
        }
    }

    if (player->moveRelative(d)) {
        // A player action happened, so step.
        step();
    } else {
        UI::instance()->say("You can't pass that way.");
    }
}
Exemple #2
0
void Game::attack(Direction d) {
    if (gameOver) {
        return UI::instance()->say("Game Over. Restart or quit.");
    }
    const int ny = player->getY() + d.dy(),
              nx = player->getX() + d.dx();
    if (level->free(ny, nx)) {
        UI::instance()->say("You swing at open space.");
        return;
    }
    // XXX ?
    Character* target = dynamic_cast<Character*>(level->objectAt(ny, nx));
    if (target) {
        player->attack(target);
        step();
    } else {
        UI::instance()->say("You can't attack that.");
    }
}
Exemple #3
0
void Game::use(Direction d) {
    if (gameOver) {
        return UI::instance()->say("Game Over. Restart or quit.");
    }
    const int ny = player->getY() + d.dy(),
              nx = player->getX() + d.dx();
    // XXX these messages are wrong
    if (level->free(ny, nx)) {
        UI::instance()->say("You drink an imaginary potion.");
        return;
    }
    ItemAdapter* target = dynamic_cast<ItemAdapter*>(level->objectAt(ny, nx));
    if (target) {
        if (player->addToInventory(target)) {
            step();
        }
    } else {
        UI::instance()->say("That doesn't appear to be drinkable.");
    }
}
Exemple #4
0
	Point operator+(const Direction& dir) const
	{
		return Point(x_ + dir.dx(), y_ + dir.dy());
	}