void GameControl::rotateShipTo(ShipHull* ship, size_t orientation_index) { while (orientation_index >= ShipHull::sOrientations.size()) orientation_index -= ShipHull::sOrientations.size(); ship->setOrientationIndex(orientation_index); // Color the ship checkShip(ship); }
bool Ship::tryAddCell(list <shared_ptr<GameBoardCell>> cells) { _bufCells.splice(_bufCells.end(), cells); //совмещаем листы if (_bufCells.size() >= 0 && _bufCells.size() <= (unsigned int)getSize()) { //сумма ячеек не должна превышать размер карабля if (_bufCells.size() == 1) return 1; //если однопалубник, всё проще if (resetDir() == UNK) return 0; //просчитываем новое направление карабля sortCell(); return checkShip(); } else return 0; }
void RandomSetShips::setShip(Ship::TubesShip nTubes, Board& board) { Ship ship(nTubes); if (checkShip(ship, board)) insertShip(ship, board); else setShip(nTubes, board); }
// Move Ship void GameControl::moveShipTo(ShipHull* ship, std::vector<size_t> coords) { // Normalize coords std::vector<size_t> dimensions = ship->getGrid()->getDimensions(); for (size_t i = 0; i < 3; ++i) { while (coords[i] >= dimensions[i]) coords[i] -= dimensions[i]; } // Set coords ship->getNode()->setPosition(ship->getGrid()->coords2position(coords)); // Color the ship checkShip(ship); }
bool checkShip(Brick* brick, int tick, Ship* ship) { brick->tick = tick; assert(brick->ship == ship); if (brick->ship != ship) return false; for (int i = 0; i < brick->numConnections; ++i) { if (brick->connections[i].other->tick != tick) if (!checkShip(brick->connections[i].other, tick, ship)) return false; } return true; }
bool Ship::checkFull() { if (_bufCells.size() == getSize() && checkShip()) { return 1; } else return 0; }