bool Map::pushBomb(Character &pusher, unsigned int destX, unsigned int destY) { unsigned int pushX = pusher.getX(); unsigned int pushY = pusher.getY(); unsigned int bombX; unsigned int bombY; int index; if (!pusher.getKickBomb()) return (false); printMap(); if ((index = findBomb(destX, destY)) == -1) return (false); bombX = _bomb[index]->getX(); bombY = _bomb[index]->getY(); if (bombX == pushX) { if ((bombY > pushY) && (canMove(bombX, bombY, 1))) return (_bomb[index]->startMoving(1)); // UP else if ((bombY < pushY) && (canMove(bombX, bombY, 2))) return (_bomb[index]->startMoving(2)); // DOWN else return (false); //ERROR; } else if (bombY == pushY) { if ((bombX > pushX) && (canMove(bombX, bombY, 3))) return (_bomb[index]->startMoving(3)); // RIGHT else if ((bombX < pushX) && (canMove(bombX, bombY, 4))) return (_bomb[index]->startMoving(4)); // LEFT else return (false); //ERROR; } return (false); }
bool Board::endGame() { if (canMove(PLAYER_1) || canMove(PLAYER_2)) { return false; } return true; }
bool AStarFindPath::canStartFind() { if (!m_pArrMapData || m_iCol > MAP_MAX_COL || m_iRow > MAP_MAX_ROW) { m_eAstarError = EAStarError::Error_Map; return false; } if (!canMove(m_iStartX, m_iStartY)) { m_eAstarError = EAStarError::Error_StartNotValid; return false; } if (!canMove(m_iEndX, m_iEndY)) { m_eAstarError = EAStarError::Error_DestNotValid; return false; } if (m_iStartX == m_iEndX && m_iStartY == m_iEndY) { m_eAstarError = EAStarError::Error_ErrorSamePoint; return false; } return true; }
voxel* getNextDirection() { voxel* nextDirection; // Mostly reuse the same direction but sometimes turn at random if (canMove(snakeDirection) && random(0, 100) < 80) { nextDirection = &snakeDirection; return nextDirection; } std::vector<voxel*> allowedDirections; for(auto it = possibleDirections.begin(); it != possibleDirections.end(); ++it) { if (canMove(*it)) { allowedDirections.push_back(&(*it)); } } if (allowedDirections.size() == 0) { return NULL; } double leastDistance = 65536.0; double distance; voxel next; for(auto it = allowedDirections.begin(); it != allowedDirections.end(); ++it) { next = snake[0] + **it; distance = next.distance(treats[0]); if (distance < leastDistance) { leastDistance = distance; nextDirection = *it; } } return nextDirection; }
int System::Move::update(float const timer __attribute__((unused))) { Component::Move *move; int j; for (unsigned int i = 0; i < _entities.size(); ++i) { if ((move = static_cast<Component::Move *>(_entities[i][Component::MOVE])) && move->getDir() != Component::Move::NONE) { Component::Position *pos = static_cast<Component::Position *>(_entities[i][Component::POSITION]); (this->*_ptr[move->getDir()])(i); if (_entities[i].getType() == Entity::PLAYER) { for (unsigned int k = 0; k < _entities.size(); ++k) { if (_entities[k].getType() == Entity::POWERUP) { Component::Position *posPower = static_cast<Component::Position *>(_entities[k][Component::POSITION]); if (sameTile(posPower->getX(), posPower->getY(), pos->getX(), pos->getY(), 650)) { (this->*_bonusPtr[static_cast<Component::Bonus *>(_entities[k][Component::BONUS])->getType()])(&_entities[i]); _entities.erase(_entities.begin() + k); i -= (k < i); break; } } } } else if (_entities[i].getType() == Entity::EXPLOSION) { Component::Range *range = static_cast<Component::Range *>(_entities[i][Component::RANGE]); range->setRange(MAX(range->getRange() - move->getSpeed(), 0)); if (_entities[i].getType() == Entity::EXPLOSION && (j = canMove(pos->getX(), pos->getY(), i, Component::BREAKABLE, 450)) != -1) { if (std::rand() % 10 > 8) { FactoryEntity *fac = FactoryEntity::getInstance(); Entity tmp = fac->create(Entity::POWERUP); Component::Position *oldPos = static_cast<Component::Position *>(_entities[j][Component::POSITION]); Component::Position *newPos = static_cast<Component::Position *>(tmp[Component::POSITION]); std::vector<gdl::Model& (FactoryEntity::*)(void)> const fptr({&FactoryEntity::getBonusFlame, &FactoryEntity::getBonusIce, &FactoryEntity::getBonusPink}); tmp << new Component::Model((FactoryEntity::getInstance()->*fptr[static_cast<Component::Bonus *>(tmp[Component::BONUS])->getType()])(), 0.0002); newPos->setX(oldPos->getX()); newPos->setY(oldPos->getY()); _entities.push_back(tmp); _entities.erase(_entities.begin() + j); } else { _entities.erase(_entities.begin() + j); } _entities.erase(_entities.begin() + i - (j < static_cast<int>(i))); i -= (j < static_cast<int>(i)); --i; } else if (_entities[i].getType() == Entity::EXPLOSION && ((j = canMove(pos->getX(), pos->getY(), i, Component::SOLID, 450)) != -1 || static_cast<Component::Range *>(_entities[i][Component::RANGE])->getRange() == 0)) { _entities.erase(_entities.begin() + i); --i; } } } } return 0; }
bool Handle_2048::checkTile(Tile *t) { if (t->x > 0 && canMove(t->y, t->x - 1, t->value)) return true; if (t->y > 0 && canMove(t->y - 1, t->x, t->value)) return true; if (t->x < 3 && canMove(t->y, t->x + 1, t->value)) return true; return (t->y < 3 && canMove(t->y + 1, t->x, t->value)); }
bool Mine::dead() const { if (state != State::InProgress) return true; if (canMove(1, 0) || canMove(-1, 0) || canMove(0, 1) || canMove(0, -1)) return false; if (problem->getTileCount(Tile::Beard) != 0 && var.curRazors != 0) return false; return true; }
//start move from A (curr pos) to B (to end) then stop or reverse etc. //Pass SM_NONE to x or y to start from the current position, //even before it has finished moving void Sprite::startMoveTo(int xEnd, int yEnd, Uint32 rate, Uint32 delay, float xVel, float yVel, eSprite type /*Sprite::SPR_NONE*/) //repeat, reverse etc { //direction //set by end x or y, or overridden by SM_ direction flags if ( (SPR_LEFT & type) || (xEnd < getXPos()) ) _xDir = -1; else _xDir = 1; //pos=right, neg=left if ( (SPR_UP & type) || (yEnd < getYPos()) ) _yDir = -1; else _yDir = 1; //pos=down, neg=up //end position //if SM_ direction flags used (ie. no end pos), then determine off //screen end positions from sprite size, ie. sprite must be completely //off screen then stop (or reverse if that flag is set _xEnd = xEnd; _yEnd = yEnd; if (SPR_LEFT & type) _xEnd = -(tileW()+1); //calc end x pos (off screen) if (SPR_RIGHT & type) _xEnd = Screen::width() + 1; //calc end x pos (off screen) if (SPR_UP & type) _yEnd = -(tileH()+1); //calc end x pos (off screen) if (SPR_DOWN & type) _yEnd = Screen::height()+1; //calc end x pos (off screen) //velocity _xVel = xVel; _yVel = yVel; //attributes //##TODO## effects flags stuff here // calcWaypoints(_x, _y, xEnd, yEnd); //unpause movement if movement is set up correctly pauseMove( !canMove() ); //set false, if moving set setMoveLoop(true); //repeat any timer/movement //finally start the timer if requested if (rate && canMove()) setMoveRate(rate, delay); }
bool moveRight() { Pos newPos = pos; newPos.x++; if (!canMove(newPos, orient)) return false; pos = newPos; return true; }
bool moveDown() { Pos newPos = pos; newPos.y--; if (!canMove(newPos, orient)) return false; pos = newPos; return true; }
void myForm::mousePressEvent(QMouseEvent *event) { QPoint p = event->pos(); int x = (p.x() + 30) / 60; int y = (p.y() + 30) / 60; QPoint clicked_pos; clicked_pos.setX(x); clicked_pos.setY(y); if (m_selectedid != -1) { if (canMove(m_selectedid, clicked_pos)) { s[m_selectedid]->setGeometry(clicked_pos.x() * 60 - 30, clicked_pos.y() * 60 - 30, 60, 60); s[m_selectedid]->stone_pos = clicked_pos; s[m_selectedid]->update(); } } qDebug() << "you clicked table position(" << clicked_pos << ")" << endl; // qDebug() << "you clicked position(" << event->pos().x() << ", " << event->pos().y() << ")" << endl; // qDebug() << "width: " << geometry().width() << endl; // qDebug() << "height: " << geometry().height() << endl; }
void ButtonControlLayer::onLevelTurn() { for (size_t i = 0; i < 4; i++) { if (_states[i] != NONE) { auto playerCreature = _level->getPlayerCreature(); if (playerCreature != nullptr) { if (playerCreature->canMove(static_cast<Direction>(i))) { playerCreature->queueMove(static_cast<Direction>(i)); } } if (_states[i] == PRESSED) { _states[i] = APPLIED_IN_TURN; } else if (_states[i] == RELEASED_BEFORE_TURN) { _states[i] = NONE; } break; } } }
/*! \qmlmethod ListModel::move(int from, int to, int n) Moves \a n items \a from one position \a to another. The from and to ranges must exist; for example, to move the first 3 items to the end of the list: \code fruitModel.move(0, fruitModel.count - 3, 3) \endcode \sa append() */ void QDeclarativeListModel::move(int from, int to, int n) { if (n==0 || from==to) return; if (!canMove(from, to, n)) { qmlInfo(this) << tr("move: out of range"); return; } int origfrom = from; int origto = to; int orign = n; if (from > to) { // Only move forwards - flip if backwards moving int tfrom = from; int tto = to; from = tto; to = tto+n; n = tfrom-tto; } if (m_flat) m_flat->move(from, to, n); else m_nested->move(from, to, n); if (!inWorkerThread()) emit itemsMoved(origfrom, origto, orign); }
bool moveLeft() { Pos newPos = pos; newPos.x--; if (!canMove(newPos, orient)) return false; pos = newPos; return true; }
bool Scene::setProfile( Profile &p ) { bool ok = true; double duration = profile.getVideoFrameDuration(); profile = p; double margin = profile.getVideoFrameDuration() / 4.0; if ( duration != profile.getVideoFrameDuration() ) { duration = profile.getVideoFrameDuration(); for ( int i = 0; i < tracks.count(); ++i ) { Track *t = tracks[i]; for ( int j = 0; j < t->clipCount(); ++j ) { Clip *c = t->clipAt( j ); c->setFrameDuration( duration ); double newPos = nearestPTS( c->position(), duration ); if ( !c->getTransition() && j > 0 ) { Clip *prev = t->clipAt( j - 1 ); if ( newPos < prev->position() + prev->length() - margin ) newPos = prev->position() + prev->length(); c->setPosition( newPos ); } else if ( canMove( c, c->length(), newPos, i ) ) move( c, i, newPos, i ); else ok = false; } } } return ok; }
void Explore::maxForward(){ ROS_INFO("enter maxForward "); int counter = 0; float d_x = 0, d_y=0, x_map, y_map, x_odom, y_odom; transfromRobotToOdomPosition(d_x, d_y, x_odom, y_odom); while (canMove(x_odom, y_odom)){ d_x += 0.1; d_y = 0; transfromRobotToOdomPosition(d_x, d_y, x_odom, y_odom); /* ++counter; if(counter > 10){ ROS_INFO("leave maxForward, can not move forward"); return; }*/ }; // ROS_INFO("d_x = %f", d_x); float robotAngleInMap = getRobotAngleInMap(); transfromRobotToMapPosition(d_x, d_y, x_map, y_map); // ROS_INFO("robot move to (%f,%f)", x_map, y_map); publishPose(x_map, y_map, robotAngleInMap); // ROS_INFO("wait for result"); // ac_.waitForResult(); ROS_INFO("leave maxForward"); }
bool Character::moveDown(bool isDirFixed){ if (!isDirFixed) { turnDown(); } if (canMove(_destPosition.x, _destPosition.y, CHARACTER_DIRECTION_DOWN)){ _destPosition.y -= 32; return true; } else{ /*switch (_type){ case (int)Type::HAMSTER: return false; break; case (int)Type::MASTER: _destPosition.y -= 32; do{ if (moveDown() == true){ break; } } while (1); break; }*/ return false; } }
void Map::checkBomb() { for (unsigned int i = 0; i < _bomb.size(); i++) { if (_bomb[i]->isExploded() == true) { if (_bomb[i]->isFlamming() == false) { _bomb[i]->getOwner()->setNbBomb((_bomb[i]->getOwner())->getNbBomb() + 1); _bomb[i]->startExplosion(); explodeBomb(i); } else { if (_bomb[i]->isEndFlamming() == true) { clearExplode(i); delete (_bomb[i]); _bomb.erase(_bomb.begin() + i); i = 0; } } } else if (_bomb[i]->isMoving()) { if ((canMove(_bomb[i]->getX(),_bomb[i]->getY(), _bomb[i]->getDirection())) == true) _bomb[i]->startMoving(_bomb[i]->getDirection()); } } }
void Explore::randomForward(){ ROS_INFO("enter randomForward "); int counter = 0; float rand_x, rand_y, x_odom, y_odom, x_map, y_map; do { rand_x = (rand() % 10) / 20.0; rand_y = 0; transfromRobotToOdomPosition(rand_x, rand_y, x_odom, y_odom); ++counter; if(counter > 10){ ROS_INFO("leave randomForward, can not move forward"); return; } } while (!canMove(x_odom, y_odom)); float robotAngleInMap = getRobotAngleInMap(); transfromRobotToMapPosition(rand_x, rand_y, x_map, y_map); // ROS_INFO("robot move to (%f,%f)", x_map, y_map); publishPose(x_map, y_map, robotAngleInMap); // ROS_INFO("wait for result"); // ac_.waitForResult(); ROS_INFO("leave randomForward"); }
// 動かすのに成功したら1、失敗したら0を返す int movePlayer(Sugoroku *s, int player_id, enum Direction d, PositionList *plist, SugorokuStatus *ss) { if(player_id >= s->player_num || player_id < 0) { puts("player番号が頭おかしい"); return 0; } Position pos = s->player[player_id].pos; Position mpos = pos; // 目的の場所 switch(d) { case UP: mpos.y--; if(mpos.y < 0 || !canMove(&s->map, mpos)) return 0; break; case RIGHT: mpos.x++; if(mpos.x >= s->map.width || !canMove(&s->map, mpos)) return 0; break; case DOWN: mpos.y++; if(mpos.y >= s->map.height || !canMove(&s->map, mpos)) return 0; break; case LEFT: mpos.x--; if(mpos.x < 0 || !canMove(&s->map, mpos)) return 0; break; } // 既に行ったことがある場所だったら行かない // 一個前のとこに戻ることは出来る if(isExistPosition(plist, mpos)) { if(isPositionEqual(plist->end->pos, mpos)) { // 進める数を一つ戻す ss->move_num++; s->player[player_id].pos = mpos; popPosition(plist); popPosition(&s->player[player_id].footmark); } else { return 0; } } else { ss->move_num--; s->player[player_id].pos = mpos; pushPosition(plist, pos); pushPosition(&s->player[player_id].footmark, pos); } return 1; }
void CloudAtlasControlWindow::dragEventCallback(double x, double y) { if (canMove()) { addOrigin(x, y); update(); } }
bool World::moveBot(Bot* bot, int x, int y) { if(canMove(bot,x,y)) { bot->moveLocation(y,x); return true; } return false; }
bool win_multi_limited(struct tile ** board_p1, struct tile **board_p2, int score, int score_p2, int size, int elapse) { bool move_p1 = canMove(board_p1, size); bool move_p2 = canMove(board_p2, size); bool filled_p1 = fillUpTile(board_p1, size); bool filled_p2 = fillUpTile(board_p2, size); bool stuck_p1 = move_p1 == false & filled_p1 == true; bool stuck_p2 = move_p2 == false & filled_p2 == true; bool end = false; int time_limit = 300; //less than 5 minutes if (elapse < time_limit) { if (stuck_p1) { mvprintw(20, 2, "PLAYER 2 WIN !!!"); end = true; } if (stuck_p2) { mvprintw(20, 2, "PLAYER 1 WIN !!!"); end = true; } if (stuck_p1 && stuck_p2) { mvprintw(20, 2, "TIED"); end = true; } } // 5 minutes if (elapse == time_limit) { if (score > score_p2) { mvprintw(20, 2, "PLAYER 1 WIN !!!"); } if (score < score_p2) { mvprintw(20, 2, "PLAYER 2 WIN !!!"); } if (score == score_p2) { mvprintw(20, 2, "DRAW !!!"); } end = true; } return end; }
void System::Move::moveEast(unsigned int& i) { Component::Position *pos = static_cast<Component::Position *>(_entities[i][Component::POSITION]); Component::Move *move = static_cast<Component::Move *>(_entities[i][Component::MOVE]); if ((pos->getY() - PIXELS_OFFSET + move->getSpeed()) / PIXELS_BY_CASE == (pos->getY() - PIXELS_OFFSET) / PIXELS_BY_CASE) { pos->setY(pos->getY() + move->getSpeed()); } else if (canMove(pos->getX(), pos->getY() + move->getSpeed(), i, Component::SOLID) == -1) pos->setY(pos->getY() + move->getSpeed()); }
Result RacingKingsBoard::result() { QString str; bool blackFinished = finished(Side::Black); bool whiteFinished = finished(Side::White); // Finishing on eighth rank if (blackFinished && whiteFinished) { str = tr("Drawn race"); return Result(Result::Draw, Side::NoSide, str); } if (blackFinished) { str = tr("Black wins the race"); return Result(Result::Win, Side::Black, str); } Side side = sideToMove(); bool mobile = canMove(); // White finished but Black cannot finish or forfeited the chance if (whiteFinished && ((mobile && !canFinish(Side::Black)) || side == Side::White)) { str = tr("White wins the race"); return Result(Result::Win, Side::White, str); } // Stalemate if (!mobile) { str = tr("Draw by stalemate"); return Result(Result::Draw, Side::NoSide, str); } // 50 move rule if (reversibleMoveCount() >= 100) { str = tr("Draw by fifty moves rule"); return Result(Result::Draw, Side::NoSide, str); } // 3-fold repetition if (repeatCount() >= 2) { str = tr("Draw by 3-fold repetition"); return Result(Result::Draw, Side::NoSide, str); } return Result(); }
void Piece::getAllPosMove() { string p = "A1"; validMove.clear(); for (p[0]='A'; p[0]<='H'; p[0]++) for (p[1]='1'; p[1]<='8'; p[1]++) { if (p == m_position) continue; if (canMove(p) && m_pBoard->squareOwner(m_position,p)!=FRIEND) validMove.push_back(p); } }
void moveForward(ENTITY *entity, GAMESTATE* state, DISPLAY* display) { CELL *destination = NULL; CELL *parent = entity->parent; switch (entity->facing){ case down : destination = parent->below; break; case left : destination = parent->left; break; case up : destination = parent->above; break; case right : destination = parent->right; break; default : entity->facing = up; } if (canMove(destination) == true){ if (destination->type == WATER) decreaseHealth(state, NEGHEALTH); moveEntity(destination, parent); } else if (canMove(destination) == false){ if (destination != NULL){ doActionIfNotEmpty(display, state, destination->entity); } } }
void SceneGame::AfterMove(Node *node, void* id) { node->setZOrder(0); int killid = (int)(intptr_t)id; if (killid != -1) { _c->at(killid)->setVisible(false); } if (_bRedTurn) { for (int i = 16; i < 32; ++i) { if (_c->at(i)->_dead) continue; if (canMove(i, _c->at(Chess::_redJiang)->_row, _c->at(Chess::_redJiang)->_col, Chess::_redJiang)) { cocos2d::log("oh red danger"); break; } } } else { for (int i = 0; i < 16; ++i) { if (_c->at(i)->_dead) continue; if (canMove(i, _c->at(Chess::_blackJiang)->_row, _c->at(Chess::_blackJiang)->_col, Chess::_blackJiang)) { cocos2d::log("oh black danger"); break; } } } }
/*! Moves the player in the specified direction. Returns the number of blocks moved. */ unsigned Rodent::move(direction_t dir) { int xoff = 0; int yoff = 0; unsigned rv = 0; getOffset(dir, xoff, yoff); if (canMove(curXPos, curYPos, dir)) { rv = doMove(curXPos, curYPos, dir); curXPos += xoff; curYPos += yoff; } return rv; }
bool Entity::tryMove(char dir) { if (dir > DIR_MAX) return false; if (!canMove()) return false; Map *m = getMap(); bool r = m->move(this, dir); if (r) this->dir = dir; return r; }