本文整理汇总了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.");
}
}
示例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.");
}
}
示例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.");
}
}
示例4: Point
Point operator+(const Direction& dir) const
{
return Point(x_ + dir.dx(), y_ + dir.dy());
}