Загрузка данных


#include <iostream>

class Body {
protected:
    int weight_;
    int x_, y_, z_;
    float jump_ability_;

private:
    int id_;
    static int amount_;

public:
    Body(int weight, int x, int y, int z, float jump_ability)
        : weight_(weight), x_(x), y_(y), z_(z), jump_ability_(jump_ability)
    {
        amount_++;
        id_ = amount_;
    }

    virtual int dropIt(int force) = 0;
};

int Body::amount_ = 0;

class Dice : public Body {
private:
    int num_;

public:
    Dice(int weight, int x, int y, int z, float jump_ability)
        : Body(weight, x, y, z, jump_ability)
    {
        num_ = 1;
    }

    int dropIt(int force) override
    {
        x_ += force;
        y_ = 0;
        z_ += force;

        num_ = force % 6 + 1;

        return num_;
    }
};

class Ball : public Body {
private:
    int jump_height_;

public:
    Ball(int weight, int x, int y, int z, float jump_ability)
        : Body(weight, x, y, z, jump_ability)
    {
        jump_height_ = 0;
    }

    int dropIt(int force) override
    {
        jump_height_ = static_cast<int>(force * jump_ability_);

        y_ = 0;

        return jump_height_;
    }
};

int main()
{
    Dice dice(1, 0, 10, 0, 0.5f);
    Ball ball(1, 0, 20, 0, 0.8f);

    std::cout << "Dice: " << dice.dropIt(5) << std::endl;
    std::cout << "Ball: " << ball.dropIt(5) << std::endl;

    return 0;
}