当前位置: 首页>>代码示例>>C++>>正文


C++ Direction::dx方法代码示例

本文整理汇总了C++中Direction::dx方法的典型用法代码示例。如果您正苦于以下问题:C++ Direction::dx方法的具体用法?C++ Direction::dx怎么用?C++ Direction::dx使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Direction的用法示例。


在下文中一共展示了Direction::dx方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: move

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.");
    }
}
开发者ID:goffrie,项目名称:gnarly,代码行数:26,代码来源:game.cpp

示例2: attack

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.");
    }
}
开发者ID:goffrie,项目名称:gnarly,代码行数:19,代码来源:game.cpp

示例3: use

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.");
    }
}
开发者ID:goffrie,项目名称:gnarly,代码行数:20,代码来源:game.cpp

示例4: Point

	Point operator+(const Direction& dir) const
	{
		return Point(x_ + dir.dx(), y_ + dir.dy());
	}
开发者ID:laurbrid,项目名称:codingame,代码行数:4,代码来源:indiana.cpp


注:本文中的Direction::dx方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。