Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- using namespace std;
- // координаты объекта в космосе
- class SpacePoint
- {
- public:
- int X, Y;
- int distance(SpacePoint point) {
- return sqrt(pow(X - point.X, 2) + pow(Y - point.Y, 2));
- }
- void read() {
- cin >> X >> Y;
- }
- void print() {
- cout << "Cordinates: x=" << X << " y=" << Y << endl;
- }
- };
- // Денежный счет
- class CreditAccount {
- public:
- // Галактические кредиты
- int credits = 0;
- void buy(int t_credits)
- {
- credits -= t_credits;
- //credits = credits > 0 ? credits : 0;
- }
- void putCredits(int credits) {
- credits += credits;
- }
- void putProtorianBools(int count) {
- credits += count * 3;
- }
- void putOrionStars(int count) {
- credits += count * 2 / 5;
- }
- void printSatus() {
- cout << "Account: " << credits << " credits" << endl;
- }
- };
- class SpaceShip {
- public:
- int fuelLeft; //Остаток топлива
- int fuelMax; // Вместимость топливного бака (максимум топлива)
- string name; // Название корабля
- SpacePoint pos; //Координаты корабля
- CreditAccount account; // Денежный счет
- void printStatus() {
- cout << "STATUS: " << name << endl;
- pos.print();
- cout << "Fuel: " << fuelLeft << " from " << fuelMax << endl;
- account.printSatus();
- }
- void flight(SpacePoint pt) {
- fuelLeft -= pos.distance(pt);
- if (fuelLeft < 0)
- fuelLeft = 0;
- pos = pt;
- }
- void prepare() {
- cin >> name >> fuelLeft >> fuelMax;
- pos.read();
- cin >> account.credits;
- }
- };
- int main() {
- SpaceShip ship;
- ship.prepare();
- int comCount;
- cin >> comCount;
- for (int i = 0; i < comCount; i++)
- {
- string com;
- cin >> com;
- if (com == "flight") {
- SpacePoint pt;
- pt.read();
- ship.flight(pt);
- }
- else if (com == "buy")
- {
- int cost;
- std::cin >> cost;
- ship.account.buy(cost);
- }
- else if (com == "cache") {
- int count;
- string name;
- cin >> count >> name;
- if (name == "credits")
- ship.account.putCredits(count);
- if (name == "bools")
- ship.account.putProtorianBools(count);
- if (name == "stars")
- ship.account.putOrionStars(count);
- }
- else if (com == "status")
- {
- ship.printStatus();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement