Star StarShip::createStar() { QPointF dir = chooseRandomDirection(); QPoint pos = chooseRandomPosition(); int random = (rand() % 2); int size = 24; // BIG if (random == 0) { size = 8; // SMALL } else if (random == 1) { size = 16; // MEDIUM } Star newStar = Star(pos); newStar.setDirection(dir); newStar.setSize(size); return newStar; }
//TODO: дублирует метод из predator, можно попытаться вынести общее в animal void Prey::createPrey() { chooseRandomDirection(); switch (direction) { case Direction::UP: { new Prey(this->place.getV() - 1, this->place.getH(), this->field, this->units_struct); break; } case Direction::RIGHT: { new Prey(this->place.getV(), this->place.getH() + 1, this->field, this->units_struct); break; } case Direction::DOWN: { new Prey(this->place.getV() + 1, this->place.getH(), this->field, this->units_struct); break; } case Direction::LEFT: { new Prey(this->place.getV(), this->place.getH() - 1, this->field, this->units_struct); } default: {} } this->energy = 0; }
void Prey::directionFinding() noexcept { chooseRandomDirection(); }