コード例 #1
0
ファイル: starship.cpp プロジェクト: WuzUrDaddy/MineStorm
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;
}
コード例 #2
0
ファイル: prey.cpp プロジェクト: Zhuikov/predator-prey
//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;
}
コード例 #3
0
ファイル: prey.cpp プロジェクト: Zhuikov/predator-prey
void Prey::directionFinding() noexcept
{
    chooseRandomDirection();
}