diff --git a/8304/Ivchenko_Anton/lab2/Armor.h b/8304/Ivchenko_Anton/lab2/Armor.h new file mode 100644 index 000000000..d338f5979 --- /dev/null +++ b/8304/Ivchenko_Anton/lab2/Armor.h @@ -0,0 +1,23 @@ +#pragma once + +class Armor { +private: + int armor; +public: + Armor(int a) { + armor = a; + }; + int getArmorValue() { + return armor; + } + void setArmor(int a) { + armor = a; + } + int reduceHealth(int d) { + armor = armor - d; + return armor; + + } + ~Armor() {}; + +}; diff --git a/8304/Ivchenko_Anton/lab2/Damage.h b/8304/Ivchenko_Anton/lab2/Damage.h new file mode 100644 index 000000000..1ff4cfae5 --- /dev/null +++ b/8304/Ivchenko_Anton/lab2/Damage.h @@ -0,0 +1,21 @@ +#pragma once + +class Damage { + +private: + int damage; +public: + Damage(int a) { + damage = a; + }; + int getDamageValue() { + return damage; + } + void setDamage(int a) { + damage = a; + } + void raiseDamage(int value) { + damage = damage + value; + } + ~Damage() {}; +}; diff --git a/8304/Ivchenko_Anton/lab2/Field.cpp b/8304/Ivchenko_Anton/lab2/Field.cpp new file mode 100644 index 000000000..1886d658e --- /dev/null +++ b/8304/Ivchenko_Anton/lab2/Field.cpp @@ -0,0 +1,190 @@ +#include +#include "Field.h" + +Field::Field(int max, int _h, int _w) +{ + + this->h = _h; + this->w = _w; + this->qmax = max; + cur = 0; + + field = new Object * *[h]; + + for (int i = 0; i < h; i++) { + + field[i] = new Object * [w]; + + for (int j = 0; j < w; j++) + + field[i][j] = nullptr; + + }std::cout << "Field created\n"; + +}; +void Field::formLandscape() { + + for (int i = 0; i < h; i++) { + + for (int j = 0; j < w; j++) { + + int a = rand() % 20; + int b = rand() % 1000; + if (a < 10) + field[i][j] = new Plain; + else if (a < 14) + field[i][j] = new Forest; + else if (a < 17) + field[i][j] = new Lake; + else if (a < 20) + field[i][j] = new Mountain; + + if (b < 5) { + Neutral* ntr = new LegendaryItem; + field[i][j]->setNeutral(ntr); + + } + else if (b < 30) { + Neutral* ntr = new ArmorKit; + field[i][j]->setNeutral(ntr); + } + else if (b < 40) { + Neutral* ntr = new WeaponKit; + field[i][j]->setNeutral(ntr); + } + else if (b < 50) { + Neutral* ntr = new SpeedBoost; + field[i][j]->setNeutral(ntr); + } + } + + } + + +}; + +Object* Field::getCoords(int x, int y) { + + return field[x][y]; + +} +Base* Field::SetBase( int x, int y) { + + Base* base = new Base(x,y); + field[x][y]->~Object(); + field[x][y] = base; + + return base; + +}; +void Field::AddObj(Unit* a, int x, int y) { + + + if ((cur < qmax) && (0 < x < h) && (0 < y < h) && field[x][y]->getUnit() == nullptr && field[x][y]->IsAvailable()) { + + field[x][y]->SetUnit(a); + a->setCoordinats(x, y); + cur++; + std::cout << "\nUnit added\n"; + } + else + std::cout << "Incorrect arguments"; +} + +void Field::RemObj(Unit* a, int x, int y) { + + if ((0 < x < h) && (0 < y < h) && (field[x][y]->getUnit() == a)) { + + field[x][y]->RemoveUnit(); + cur--; + std::cout << "\nUnit removed\n"; + } + else + std::cout << "Incorrect arguments"; + +}; + +void Field::Moving(Unit* a, int posx, int posy, int dx, int dy) { + + if ((posx + dx > h || posx + dx < 0) && (posy + dy > w || posy + dy < 0)) { + + + std::cout << "Incorrect arguments"; return; + + } + /*if ((abs(dx) > a->getCharactresistics()->getSpeed())) { + + field[posx][posy]->RemoveUnit(); + int newx = posx + (a->getCharactresistics()->getSpeed() * dx / abs(dx)); + int newy = posx + (a->getCharactresistics()->getSpeed() * dy / abs(dy)); + + field[posx + newx][posy + newy]->SetUnit(a); + + a->setCoordinats(posx + newx, posy + newy); + + std::cout << "\nUnit moved\n"; + } + */ + else { + + RemObj(a, posx, posy); + + AddObj(a, posx + dx, posy + dy); + + std::cout << "\nUnit moved\n"; + + } + + + +}; + +Field* Field::CopyField(Field* a) { + + for (int i = 0; i < h; i++) { + + for (int k = 0; k < w; k++) { + + a->SetUnit(field[i][k], i, k); + + } + }return a; + +}; + + +void Field::SetUnit(Object* a, int b, int c) { + + field[b][c] = a; + +}; + + +void Field::PrintField() { + + for (int i = 0; i < h; i++) { + + std::cout << '\n'; + + for (int k = 0; k < w; k++) { + + if (field[i][k]->getUnit() != nullptr) + + std::cout << field[i][k]->getUnit()->getid() << ' '; + + else if (field[i][k]->getNeutral() != nullptr) + std::cout << field[i][k]->getNeutral()->getType() << ' '; + + else + std::cout << field[i][k]->getObj() << ' '; + } + }; + +}; + +Field::~Field() { + + delete[] field; + std::cout << "\nField deleted\n"; + +}; diff --git a/8304/Ivchenko_Anton/lab2/Field.h b/8304/Ivchenko_Anton/lab2/Field.h new file mode 100644 index 000000000..961014810 --- /dev/null +++ b/8304/Ivchenko_Anton/lab2/Field.h @@ -0,0 +1,31 @@ +#pragma once +#include "Unit.h" +#include "Object.h" + +class Field { + +private: + + int h; + int w; + int cur; + int qmax; + Object*** field; + +public: + + Field(); + Field(int max, int _h, int _w); + Base* SetBase(int x, int y); + void AddObj(Unit* a, int x, int y); + void RemObj(Unit* a, int x, int y); + void Moving(Unit* a, int posx, int posy, int dx, int dy); + Field* CopyField(Field* a); + void SetUnit(Object* a, int b, int c); + void PrintField(); + Object* getCoords(int, int); + void formLandscape(); + void SetNeutralObjs(); + ~Field(); + +}; diff --git a/8304/Ivchenko_Anton/lab2/Flyweight.cpp b/8304/Ivchenko_Anton/lab2/Flyweight.cpp new file mode 100644 index 000000000..f853a6e1f --- /dev/null +++ b/8304/Ivchenko_Anton/lab2/Flyweight.cpp @@ -0,0 +1,16 @@ + +#include "Flyweight.h" + +TypeOfUnit::TypeOfUnit() { + + Atributes* infantry = new Atributes(10, 10, 3); + Atributes* archers = new Atributes(15, 5, 2); + Atributes* cavalry = new Atributes(10, 8, 5); + my_map['i'] = infantry; + my_map['a'] = archers; + my_map['c'] = cavalry; + +} +Atributes* TypeOfUnit::getType(char a) { + return my_map[a]; +} diff --git a/8304/Ivchenko_Anton/lab2/Flyweight.h b/8304/Ivchenko_Anton/lab2/Flyweight.h new file mode 100644 index 000000000..d52ff03c9 --- /dev/null +++ b/8304/Ivchenko_Anton/lab2/Flyweight.h @@ -0,0 +1,42 @@ +#pragma once + +#include "Damage.h" +#include "Armor.h" +#include + + +class Atributes { +private: + Damage* damage; + Armor* armor; + int speed; +public: + Atributes() {}; + Atributes(int a, int b, int c) { + + damage = new Damage(a); + armor = new Armor(b); + speed = c; + + } + Damage* getDamage() { + return damage; + } + Armor* getArmor() { + return armor; + } + int getSpeed() { + return speed; + } + ~Atributes() {}; + +}; +class TypeOfUnit { + +private: + std::map my_map; +public: + TypeOfUnit(); + Atributes* getType(char a); + ~TypeOfUnit() {}; +}; diff --git a/8304/Ivchenko_Anton/lab2/Neutral.h b/8304/Ivchenko_Anton/lab2/Neutral.h new file mode 100644 index 000000000..730838f6a --- /dev/null +++ b/8304/Ivchenko_Anton/lab2/Neutral.h @@ -0,0 +1,76 @@ +#pragma once +#include "Strategy.h" + +class Neutral{ + +private: + char neutral_name; + Context context; +public: + int damage_buff, armor_buff, speed_buff; + Neutral() { + neutral_name = '0'; + damage_buff, armor_buff, speed_buff = 0; + }; + void setType(char a) { + neutral_name = a; + } + char getType() { + return neutral_name; + } + void use(Unit *a) { + if (a->getType() == 'i') context.setStrategy(new WarriorsStrategy, damage_buff, armor_buff, speed_buff, a); + else if (a->getType() == 'a') context.setStrategy(new ArchersStrategy, damage_buff, armor_buff, speed_buff, a); + else if (a->getType() =='c') context.setStrategy(new CavalryStrategy, damage_buff, armor_buff, speed_buff, a); + } + ~Neutral() { + + }; + +}; +class ArmorKit : public Neutral { + +public: + ArmorKit() { + this->setType('A'); + this->armor_buff = 5; + //std::cout << "Найдена улучшенная броня? Использовать?y/n\n"; + + }; + + ~ArmorKit() {}; + +}; + +class WeaponKit : public Neutral { + + +public: + WeaponKit() { + this->setType('W'); + this->damage_buff = 5; + //std::cout << "Найдена улучшенный боеприпасы? Использовать?y/n\n"; + }; + ~WeaponKit() {}; +}; + +class SpeedBoost : public Neutral { +public: + SpeedBoost() { + this->setType('S'); + this->speed_buff = 3; + }; + + ~SpeedBoost() {}; +}; +class LegendaryItem : public Neutral { +public: + LegendaryItem() { + this->setType('L'); + this->speed_buff = 9; + this->armor_buff = 10; + this->damage_buff = 10; + }; + + ~LegendaryItem() {}; +}; diff --git a/8304/Ivchenko_Anton/lab2/Object.h b/8304/Ivchenko_Anton/lab2/Object.h new file mode 100644 index 000000000..984f89f7a --- /dev/null +++ b/8304/Ivchenko_Anton/lab2/Object.h @@ -0,0 +1,221 @@ +#pragma once +#include "Neutral.h" +class Object { + +private: + char obj_name; + Unit* unit; + Neutral* ntr; + bool availability; + +public: + + Object() { obj_name = '0'; unit = nullptr; ntr = nullptr; }; + + void SetUnit(Unit *a) { + unit = a; + }; + void RemoveUnit() { + unit = nullptr; + } + void SetObj(char a) { + obj_name = a; + } + Unit* getUnit() { + return unit; + }; + char getObj() { + return obj_name; + }; + Neutral *getNeutral() { + return ntr; + } + void setNeutral(Neutral *a) { + ntr = a; + } + void useNeutral () { + if (ntr->getType() != '0') { + ntr->use(unit); + } + } + void SetAvailability(bool b) { + this->availability = b; + } + bool IsAvailable() { + return this->availability; + } + ~Object() {}; + +}; + +class Base : public Object { + +private: + + int x, y; + int quantity, q_max, hp; + +public: + + Base(int _x, int _y) :x(_x), y(_y) { + this->SetObj('B'); quantity = 0, q_max = 10, hp = 100; + }; + + Swordman* createSwordman() { + if (quantity < q_max) { + Swordman* swordman = new Swordman; + quantity++; + swordman->setCoordinats(0, 2); + return swordman; + } + else return nullptr; + } + Spearman* createSpearman() { + if (quantity < q_max) { + Spearman* spearman = new Spearman; + quantity++; + spearman->setCoordinats(1, 1); + return spearman; + } + else return nullptr; + } + Bowman* createBowman() { + if (quantity < q_max) { + Bowman* bowman = new Bowman; + quantity++; + bowman->setCoordinats(1, 1); + return bowman; + } + else return nullptr; + } + Slinger* createSlinger() { + if (quantity < q_max) { + Slinger* slinger = new Slinger; + quantity++; + slinger->setCoordinats(1, 1); + return slinger; + } + else return nullptr; + } + LightCavalry* createLC() { + if (quantity < q_max) { + LightCavalry* lc = new LightCavalry; + quantity++; + lc->setCoordinats(1, 1); + return lc; + } + else return nullptr; + } + HeavyCavalry* createHC() { + if (quantity < q_max) { + HeavyCavalry* hc = new HeavyCavalry; + quantity++; + hc->setCoordinats(1, 1); + return hc; + } + else return nullptr; + } + void printBaseCondition() { + std::cout << "\nBase condition:\nHp: " << hp << "\nCurreant unit quantity: " << quantity << "\nMax unit quantity: " << q_max << std::endl; + } + void deleteUnit(Unit* a) { + a->~Unit(); + quantity--; + + }; + + + ~Base() {}; + +}; + + +class Landscape : public Object { + +public: + + Landscape() { + + }; + void SetType(char a) { + this->SetObj(a); + + + } + + void speedChange(int d, Unit* a) { + Atributes* new_c = new Atributes(a->getCharactresistics()->getDamage()->getDamageValue(), a->getCharactresistics()->getArmor()->getArmorValue(), a->getCharactresistics()->getSpeed() + d); + a->changeCharactresistics(new_c); + } + void attackChange(int d, Unit* a) { + Atributes* new_c = new Atributes(a->getCharactresistics()->getDamage()->getDamageValue() + d, a->getCharactresistics()->getArmor()->getArmorValue(), a->getCharactresistics()->getSpeed()); + a->changeCharactresistics(new_c); + } + ~Landscape() { + + }; +}; +class Lake : public Landscape { + +public: + + Lake() { + this->SetType('~'); + this->SetAvailability(0); + //if (getUnit() != nullptr) { + // getUnit()->~Unit(); + //} + } + ~Lake() { + + }; +}; + +class Mountain : public Landscape { + +public: + + Mountain() { + this->SetType('^'); + this->SetAvailability(0); + + } + ~Mountain() { + + }; +}; + +class Plain : public Landscape { + +public: + + Plain() { + this->SetType(' '); + this->SetAvailability(1); + if (getUnit() != nullptr) { + if (getUnit()->getType() == '3') speedChange(2, getUnit()); + } + + } + ~Plain() { + + }; +}; + +class Forest : public Landscape { + +public: + + Forest() { + this->SetType('#'); + this->SetAvailability(1); + if (getUnit() != nullptr) { + if (getUnit()->getType() == '3') speedChange(-1, getUnit()); + if (getUnit()->getid() == '2') attackChange(-1, getUnit()); + } + + } + ~Forest() { + + }; +}; diff --git a/8304/Ivchenko_Anton/lab2/Strategy.h b/8304/Ivchenko_Anton/lab2/Strategy.h new file mode 100644 index 000000000..42167bdd8 --- /dev/null +++ b/8304/Ivchenko_Anton/lab2/Strategy.h @@ -0,0 +1,60 @@ +#pragma once +class Strategy { +public: + int damage_buff, armor_buff, speed_buff; + virtual void execute(Unit* a) = 0; + virtual void operator + (Unit* a) = 0; +}; + + +class WarriorsStrategy: public Strategy{ + + void operator + (Unit* a) { + Atributes* new_c = new Atributes(a->getCharactresistics()->getDamage()->getDamageValue() + (3/5 * damage_buff), a->getCharactresistics()->getArmor()->getArmorValue() + (4/5*armor_buff), a->getCharactresistics()->getSpeed() + (2 / 3 * speed_buff)); + a->changeCharactresistics(new_c); + } + void execute(Unit* a) { + (*this) + a; + } + +}; + +class ArchersStrategy:public Strategy { + + void operator + (Unit* a) { + Atributes* new_c = new Atributes(a->getCharactresistics()->getDamage()->getDamageValue() + (4/5 * damage_buff), a->getCharactresistics()->getArmor()->getArmorValue() + (3/5 * armor_buff), a->getCharactresistics()->getSpeed() + (2/3*speed_buff)); + a->changeCharactresistics(new_c); + } + void execute(Unit* a) { + (*this) + a; + } + +}; + +class CavalryStrategy:public Strategy { + + void operator + (Unit* a) { + Atributes* new_c = new Atributes(a->getCharactresistics()->getDamage()->getDamageValue() + (2/5 * damage_buff), a->getCharactresistics()->getArmor()->getArmorValue() + (3/5 * armor_buff), a->getCharactresistics()->getSpeed() + speed_buff); + a->changeCharactresistics(new_c); + } + void execute(Unit* a) { + (*this) + a; + } +}; +class Context { + +private: + Strategy* strategy; + Unit* unit; +public: + void setStrategy(Strategy* strat, int a, int b, int c, Unit* unit_) { + strategy = strat; + unit = unit_; + strategy->damage_buff = a; + strategy->armor_buff = b; + strategy->speed_buff = c; + }; + void executeStrategy() { + strategy->execute(unit); + }; +}; diff --git a/8304/Ivchenko_Anton/lab2/Unit.cpp b/8304/Ivchenko_Anton/lab2/Unit.cpp new file mode 100644 index 000000000..d0ee5841c --- /dev/null +++ b/8304/Ivchenko_Anton/lab2/Unit.cpp @@ -0,0 +1,120 @@ +#include "Unit.h" + +TypeOfUnit* UnitMap = new TypeOfUnit; + +Unit::Unit() { + id = '0'; characteristics = nullptr; +}; + +void Unit::attack(Unit* a) { + a->get_hit(characteristics->getDamage()->getDamageValue()); +} +void Unit::get_hit(int damage) { + Atributes* new_c = new Atributes (characteristics->getDamage()->getDamageValue(), characteristics->getArmor()->reduceHealth(damage), characteristics->getSpeed()); + this->changeCharactresistics(new_c); + +} +void Unit::check_armor(Unit* a) { + if (a->getCharactresistics()->getArmor() < 0) + a->~Unit(); +} +void Unit::setName(char a) { + this->id = a; +} +void Unit::setType(char a) { + this->type = a; +} +void Unit::setCoordinats(int x_, int y_) { + x = x_; y = y_; +} +char Unit::getid() { + return id; +} +int Unit::getx() { + return x; +} +int Unit::gety() { + return y; +} +char Unit::getType() { + return type; +} +Atributes* Unit::getCharactresistics() { + return characteristics; +} +void Unit::changeCharactresistics(Atributes* a) { + characteristics = a; + +} +Unit::~Unit() {}; + + +Warrior::Warrior() { + this->setType('i'); + this->changeCharactresistics(UnitMap->getType(this->getType())); + }; +Warrior::~Warrior() {}; + + +Swordman::Swordman() { + + this->setName('1'); + } +Swordman::~Swordman() {}; + +Spearman::Spearman() { + + this->setName('2'); + + }; +Spearman::~Spearman() {}; + + + +Archer::Archer() { + this->setType('a'); + this->changeCharactresistics(UnitMap->getType(this->getType())); + + + } +Archer::~Archer() {}; + + +Slinger::Slinger() { + + this->setName('3'); + + }; +Slinger::~Slinger() {}; + + +Bowman::Bowman() { + + this->setName('4'); + + + }; +Bowman::~Bowman() {}; + +Cavalry::Cavalry() { + this->setType('c'); + this->changeCharactresistics(UnitMap->getType(this->getType())); + + }; +Cavalry::~Cavalry() {}; + +LightCavalry::LightCavalry() { + + this->setName('5'); + + }; +LightCavalry::~LightCavalry() {}; + + + +HeavyCavalry::HeavyCavalry() { + + this->setName('6'); + + }; +HeavyCavalry::~HeavyCavalry() {}; diff --git a/8304/Ivchenko_Anton/lab2/Unit.h b/8304/Ivchenko_Anton/lab2/Unit.h new file mode 100644 index 000000000..9bcb1c79d --- /dev/null +++ b/8304/Ivchenko_Anton/lab2/Unit.h @@ -0,0 +1,108 @@ +#pragma once +#include "Flyweight.h" + +class Unit { + +private: + + int x, y; + char id, type; + Atributes *characteristics; + +public: + + Unit(); + void attack(Unit* a); + void get_hit(int damage); + void check_armor(Unit* a); + void setName(char a); + void setType(char a); + void setCoordinats(int x_, int y_); + char getid(); + char getType(); + int getx(); + int gety(); + Atributes* getCharactresistics(); + void changeCharactresistics(Atributes* a); + ~Unit(); + +}; + +class Warrior : public Unit { + +public: + + Warrior(); + ~Warrior(); + +}; + +class Swordman : public Warrior { + +public: + + Swordman(); + ~Swordman(); +}; + +class Spearman : public Warrior { + +public: + + Spearman(); + ~Spearman(); + +}; + +class Archer : public Unit { + +public: + + Archer(); + ~Archer(); +}; + +class Slinger : public Archer { + +public: + + Slinger(); + ~Slinger(); + +}; + +class Bowman : public Archer { + +public: + + Bowman(); + ~Bowman(); +}; + +class Cavalry : public Unit { + +public: + + Cavalry(); + ~Cavalry(); + +}; + +class LightCavalry : public Cavalry { + +public: + + LightCavalry(); + ~LightCavalry(); + + +}; + +class HeavyCavalry : public Cavalry { + +public: + + HeavyCavalry(); + ~HeavyCavalry(); + +}; diff --git a/8304/Ivchenko_Anton/lab2/main.cpp b/8304/Ivchenko_Anton/lab2/main.cpp new file mode 100644 index 000000000..92646944e --- /dev/null +++ b/8304/Ivchenko_Anton/lab2/main.cpp @@ -0,0 +1,127 @@ +#include +#include "Field.h" + +class UnitControl { +private: + Field* field; +public: + UnitControl(Field* f) { + field = f; + } + void UnitFunctional(Unit* a, Base* start_base) { + int choice = 2e7, x, y; + while (choice != 0) { + std::cout << "Unit: Moving(1), attack(2, coords), switch to base(0)\n Your choice:"; + std::cin >> choice; + switch (choice) { + case 1: + std::cin >> x >> y; + field->Moving(a, a->getx(), a->gety(), x, y); + break; + case 2: + std::cin >> x >> y; + if (abs(x - a->getx()) < a->getCharactresistics()->getSpeed() && abs(y - a->gety()) < a->getCharactresistics()->getSpeed()) { + + a->attack(field->getCoords(x, y)->getUnit()); + if (field->getCoords(x, y)->getUnit()->getCharactresistics()->getArmor()->getArmorValue() < 0) { + Unit* b = field->getCoords(x, y)->getUnit(); + field->RemObj(b, x, y); + start_base->deleteUnit(b); + field->Moving(a, a->getx(), a->gety(), x - a->getx(), y - a->gety()); + } + } + else if (x - a->getx() == 0) + field->Moving(a, a->getx(), a->gety(), 0, a->getCharactresistics()->getSpeed() * (y - a->gety()) / abs(y - a->gety())); + else if (y - a->gety() == 0) + field->Moving(a, a->getx(), a->gety(), a->getCharactresistics()->getSpeed() * (x - a->getx()) / abs(x - a->getx()), 0); + else field->Moving(a, a->getx(), a->gety(), a->getCharactresistics()->getSpeed() * (x - a->getx() )/ abs(x - a->getx()), a->getCharactresistics()->getSpeed() * (y - a->gety()) / abs(y - a->gety())); + break; + }field->PrintField(); + } + } +}; +class BaseControl { +private: + Base* start_base; + Field* field; + UnitControl* unit_ctrl; +public: + BaseControl(Field* f) { + field = f; + start_base = field->SetBase(0, 0); + unit_ctrl = new UnitControl(field); + } + ; + void BaseFunctional() { + int choice = 2e7, x, y; + Unit* unit = nullptr; + while (choice != 0) { + std::cout << "\nBase: create swordman(1), spearman(2), slinger(3), bowman(4),light cavalry(5), heavy cavalry(6)\nSwitch to unit(7, write coords)\nCheck base condition(8)\nQuit(0)\nYour choice:"; + std::cin >> choice; + + switch (choice) { + case 1: + { + unit = start_base->createSwordman(); + field->AddObj(unit, unit->getx(), unit->gety()); + break; + } + case 2: + { + unit = start_base->createSpearman(); + field->AddObj(unit, unit->getx(), unit->gety()); + break; + } + case 3: + { + unit = start_base->createSlinger(); + field->AddObj(unit, unit->getx(), unit->gety()); + break; + } + case 4: + { + unit = start_base->createBowman(); + field->AddObj(unit, unit->getx(), unit->gety()); + break; + } + case 5: + { + unit = start_base->createLC(); + field->AddObj(unit, unit->getx(), unit->gety()); + break; + } + case 6: + { + unit = start_base->createHC(); + field->AddObj(unit, unit->getx(), unit->gety()); + break; + } + case 7: { + std::cin >> x >> y; + if (field->getCoords(x, y)->getUnit()->getid() != '0') + unit_ctrl->UnitFunctional(unit, start_base); + else std::cout << "Incorrect coordinates"; + break; + }case 8: { + start_base->printBaseCondition(); + break; + } + + }field->PrintField(); + } + + + } + +}; + +int main() { + + Field *f = new Field(10, 30, 30); + f->formLandscape(); + + BaseControl* base = new BaseControl(f); + base->BaseFunctional(); + + return 0; +} diff --git a/8304/Ivchenko_Anton/lab2/report_lr2.pdf b/8304/Ivchenko_Anton/lab2/report_lr2.pdf new file mode 100644 index 000000000..f1e3bf917 Binary files /dev/null and b/8304/Ivchenko_Anton/lab2/report_lr2.pdf differ diff --git a/8304/Ivchenko_Anton/lab3/Armor.h b/8304/Ivchenko_Anton/lab3/Armor.h new file mode 100644 index 000000000..d338f5979 --- /dev/null +++ b/8304/Ivchenko_Anton/lab3/Armor.h @@ -0,0 +1,23 @@ +#pragma once + +class Armor { +private: + int armor; +public: + Armor(int a) { + armor = a; + }; + int getArmorValue() { + return armor; + } + void setArmor(int a) { + armor = a; + } + int reduceHealth(int d) { + armor = armor - d; + return armor; + + } + ~Armor() {}; + +}; diff --git a/8304/Ivchenko_Anton/lab3/Damage.h b/8304/Ivchenko_Anton/lab3/Damage.h new file mode 100644 index 000000000..1ff4cfae5 --- /dev/null +++ b/8304/Ivchenko_Anton/lab3/Damage.h @@ -0,0 +1,21 @@ +#pragma once + +class Damage { + +private: + int damage; +public: + Damage(int a) { + damage = a; + }; + int getDamageValue() { + return damage; + } + void setDamage(int a) { + damage = a; + } + void raiseDamage(int value) { + damage = damage + value; + } + ~Damage() {}; +}; diff --git a/8304/Ivchenko_Anton/lab3/Field.cpp b/8304/Ivchenko_Anton/lab3/Field.cpp new file mode 100644 index 000000000..1886d658e --- /dev/null +++ b/8304/Ivchenko_Anton/lab3/Field.cpp @@ -0,0 +1,190 @@ +#include +#include "Field.h" + +Field::Field(int max, int _h, int _w) +{ + + this->h = _h; + this->w = _w; + this->qmax = max; + cur = 0; + + field = new Object * *[h]; + + for (int i = 0; i < h; i++) { + + field[i] = new Object * [w]; + + for (int j = 0; j < w; j++) + + field[i][j] = nullptr; + + }std::cout << "Field created\n"; + +}; +void Field::formLandscape() { + + for (int i = 0; i < h; i++) { + + for (int j = 0; j < w; j++) { + + int a = rand() % 20; + int b = rand() % 1000; + if (a < 10) + field[i][j] = new Plain; + else if (a < 14) + field[i][j] = new Forest; + else if (a < 17) + field[i][j] = new Lake; + else if (a < 20) + field[i][j] = new Mountain; + + if (b < 5) { + Neutral* ntr = new LegendaryItem; + field[i][j]->setNeutral(ntr); + + } + else if (b < 30) { + Neutral* ntr = new ArmorKit; + field[i][j]->setNeutral(ntr); + } + else if (b < 40) { + Neutral* ntr = new WeaponKit; + field[i][j]->setNeutral(ntr); + } + else if (b < 50) { + Neutral* ntr = new SpeedBoost; + field[i][j]->setNeutral(ntr); + } + } + + } + + +}; + +Object* Field::getCoords(int x, int y) { + + return field[x][y]; + +} +Base* Field::SetBase( int x, int y) { + + Base* base = new Base(x,y); + field[x][y]->~Object(); + field[x][y] = base; + + return base; + +}; +void Field::AddObj(Unit* a, int x, int y) { + + + if ((cur < qmax) && (0 < x < h) && (0 < y < h) && field[x][y]->getUnit() == nullptr && field[x][y]->IsAvailable()) { + + field[x][y]->SetUnit(a); + a->setCoordinats(x, y); + cur++; + std::cout << "\nUnit added\n"; + } + else + std::cout << "Incorrect arguments"; +} + +void Field::RemObj(Unit* a, int x, int y) { + + if ((0 < x < h) && (0 < y < h) && (field[x][y]->getUnit() == a)) { + + field[x][y]->RemoveUnit(); + cur--; + std::cout << "\nUnit removed\n"; + } + else + std::cout << "Incorrect arguments"; + +}; + +void Field::Moving(Unit* a, int posx, int posy, int dx, int dy) { + + if ((posx + dx > h || posx + dx < 0) && (posy + dy > w || posy + dy < 0)) { + + + std::cout << "Incorrect arguments"; return; + + } + /*if ((abs(dx) > a->getCharactresistics()->getSpeed())) { + + field[posx][posy]->RemoveUnit(); + int newx = posx + (a->getCharactresistics()->getSpeed() * dx / abs(dx)); + int newy = posx + (a->getCharactresistics()->getSpeed() * dy / abs(dy)); + + field[posx + newx][posy + newy]->SetUnit(a); + + a->setCoordinats(posx + newx, posy + newy); + + std::cout << "\nUnit moved\n"; + } + */ + else { + + RemObj(a, posx, posy); + + AddObj(a, posx + dx, posy + dy); + + std::cout << "\nUnit moved\n"; + + } + + + +}; + +Field* Field::CopyField(Field* a) { + + for (int i = 0; i < h; i++) { + + for (int k = 0; k < w; k++) { + + a->SetUnit(field[i][k], i, k); + + } + }return a; + +}; + + +void Field::SetUnit(Object* a, int b, int c) { + + field[b][c] = a; + +}; + + +void Field::PrintField() { + + for (int i = 0; i < h; i++) { + + std::cout << '\n'; + + for (int k = 0; k < w; k++) { + + if (field[i][k]->getUnit() != nullptr) + + std::cout << field[i][k]->getUnit()->getid() << ' '; + + else if (field[i][k]->getNeutral() != nullptr) + std::cout << field[i][k]->getNeutral()->getType() << ' '; + + else + std::cout << field[i][k]->getObj() << ' '; + } + }; + +}; + +Field::~Field() { + + delete[] field; + std::cout << "\nField deleted\n"; + +}; diff --git a/8304/Ivchenko_Anton/lab3/Field.h b/8304/Ivchenko_Anton/lab3/Field.h new file mode 100644 index 000000000..961014810 --- /dev/null +++ b/8304/Ivchenko_Anton/lab3/Field.h @@ -0,0 +1,31 @@ +#pragma once +#include "Unit.h" +#include "Object.h" + +class Field { + +private: + + int h; + int w; + int cur; + int qmax; + Object*** field; + +public: + + Field(); + Field(int max, int _h, int _w); + Base* SetBase(int x, int y); + void AddObj(Unit* a, int x, int y); + void RemObj(Unit* a, int x, int y); + void Moving(Unit* a, int posx, int posy, int dx, int dy); + Field* CopyField(Field* a); + void SetUnit(Object* a, int b, int c); + void PrintField(); + Object* getCoords(int, int); + void formLandscape(); + void SetNeutralObjs(); + ~Field(); + +}; diff --git a/8304/Ivchenko_Anton/lab3/Flyweight.cpp b/8304/Ivchenko_Anton/lab3/Flyweight.cpp new file mode 100644 index 000000000..f853a6e1f --- /dev/null +++ b/8304/Ivchenko_Anton/lab3/Flyweight.cpp @@ -0,0 +1,16 @@ + +#include "Flyweight.h" + +TypeOfUnit::TypeOfUnit() { + + Atributes* infantry = new Atributes(10, 10, 3); + Atributes* archers = new Atributes(15, 5, 2); + Atributes* cavalry = new Atributes(10, 8, 5); + my_map['i'] = infantry; + my_map['a'] = archers; + my_map['c'] = cavalry; + +} +Atributes* TypeOfUnit::getType(char a) { + return my_map[a]; +} diff --git a/8304/Ivchenko_Anton/lab3/Flyweight.h b/8304/Ivchenko_Anton/lab3/Flyweight.h new file mode 100644 index 000000000..d52ff03c9 --- /dev/null +++ b/8304/Ivchenko_Anton/lab3/Flyweight.h @@ -0,0 +1,42 @@ +#pragma once + +#include "Damage.h" +#include "Armor.h" +#include + + +class Atributes { +private: + Damage* damage; + Armor* armor; + int speed; +public: + Atributes() {}; + Atributes(int a, int b, int c) { + + damage = new Damage(a); + armor = new Armor(b); + speed = c; + + } + Damage* getDamage() { + return damage; + } + Armor* getArmor() { + return armor; + } + int getSpeed() { + return speed; + } + ~Atributes() {}; + +}; +class TypeOfUnit { + +private: + std::map my_map; +public: + TypeOfUnit(); + Atributes* getType(char a); + ~TypeOfUnit() {}; +}; diff --git a/8304/Ivchenko_Anton/lab3/Neutral.h b/8304/Ivchenko_Anton/lab3/Neutral.h new file mode 100644 index 000000000..730838f6a --- /dev/null +++ b/8304/Ivchenko_Anton/lab3/Neutral.h @@ -0,0 +1,76 @@ +#pragma once +#include "Strategy.h" + +class Neutral{ + +private: + char neutral_name; + Context context; +public: + int damage_buff, armor_buff, speed_buff; + Neutral() { + neutral_name = '0'; + damage_buff, armor_buff, speed_buff = 0; + }; + void setType(char a) { + neutral_name = a; + } + char getType() { + return neutral_name; + } + void use(Unit *a) { + if (a->getType() == 'i') context.setStrategy(new WarriorsStrategy, damage_buff, armor_buff, speed_buff, a); + else if (a->getType() == 'a') context.setStrategy(new ArchersStrategy, damage_buff, armor_buff, speed_buff, a); + else if (a->getType() =='c') context.setStrategy(new CavalryStrategy, damage_buff, armor_buff, speed_buff, a); + } + ~Neutral() { + + }; + +}; +class ArmorKit : public Neutral { + +public: + ArmorKit() { + this->setType('A'); + this->armor_buff = 5; + //std::cout << "Найдена улучшенная броня? Использовать?y/n\n"; + + }; + + ~ArmorKit() {}; + +}; + +class WeaponKit : public Neutral { + + +public: + WeaponKit() { + this->setType('W'); + this->damage_buff = 5; + //std::cout << "Найдена улучшенный боеприпасы? Использовать?y/n\n"; + }; + ~WeaponKit() {}; +}; + +class SpeedBoost : public Neutral { +public: + SpeedBoost() { + this->setType('S'); + this->speed_buff = 3; + }; + + ~SpeedBoost() {}; +}; +class LegendaryItem : public Neutral { +public: + LegendaryItem() { + this->setType('L'); + this->speed_buff = 9; + this->armor_buff = 10; + this->damage_buff = 10; + }; + + ~LegendaryItem() {}; +}; diff --git a/8304/Ivchenko_Anton/lab3/Object.h b/8304/Ivchenko_Anton/lab3/Object.h new file mode 100644 index 000000000..984f89f7a --- /dev/null +++ b/8304/Ivchenko_Anton/lab3/Object.h @@ -0,0 +1,221 @@ +#pragma once +#include "Neutral.h" +class Object { + +private: + char obj_name; + Unit* unit; + Neutral* ntr; + bool availability; + +public: + + Object() { obj_name = '0'; unit = nullptr; ntr = nullptr; }; + + void SetUnit(Unit *a) { + unit = a; + }; + void RemoveUnit() { + unit = nullptr; + } + void SetObj(char a) { + obj_name = a; + } + Unit* getUnit() { + return unit; + }; + char getObj() { + return obj_name; + }; + Neutral *getNeutral() { + return ntr; + } + void setNeutral(Neutral *a) { + ntr = a; + } + void useNeutral () { + if (ntr->getType() != '0') { + ntr->use(unit); + } + } + void SetAvailability(bool b) { + this->availability = b; + } + bool IsAvailable() { + return this->availability; + } + ~Object() {}; + +}; + +class Base : public Object { + +private: + + int x, y; + int quantity, q_max, hp; + +public: + + Base(int _x, int _y) :x(_x), y(_y) { + this->SetObj('B'); quantity = 0, q_max = 10, hp = 100; + }; + + Swordman* createSwordman() { + if (quantity < q_max) { + Swordman* swordman = new Swordman; + quantity++; + swordman->setCoordinats(0, 2); + return swordman; + } + else return nullptr; + } + Spearman* createSpearman() { + if (quantity < q_max) { + Spearman* spearman = new Spearman; + quantity++; + spearman->setCoordinats(1, 1); + return spearman; + } + else return nullptr; + } + Bowman* createBowman() { + if (quantity < q_max) { + Bowman* bowman = new Bowman; + quantity++; + bowman->setCoordinats(1, 1); + return bowman; + } + else return nullptr; + } + Slinger* createSlinger() { + if (quantity < q_max) { + Slinger* slinger = new Slinger; + quantity++; + slinger->setCoordinats(1, 1); + return slinger; + } + else return nullptr; + } + LightCavalry* createLC() { + if (quantity < q_max) { + LightCavalry* lc = new LightCavalry; + quantity++; + lc->setCoordinats(1, 1); + return lc; + } + else return nullptr; + } + HeavyCavalry* createHC() { + if (quantity < q_max) { + HeavyCavalry* hc = new HeavyCavalry; + quantity++; + hc->setCoordinats(1, 1); + return hc; + } + else return nullptr; + } + void printBaseCondition() { + std::cout << "\nBase condition:\nHp: " << hp << "\nCurreant unit quantity: " << quantity << "\nMax unit quantity: " << q_max << std::endl; + } + void deleteUnit(Unit* a) { + a->~Unit(); + quantity--; + + }; + + + ~Base() {}; + +}; + + +class Landscape : public Object { + +public: + + Landscape() { + + }; + void SetType(char a) { + this->SetObj(a); + + + } + + void speedChange(int d, Unit* a) { + Atributes* new_c = new Atributes(a->getCharactresistics()->getDamage()->getDamageValue(), a->getCharactresistics()->getArmor()->getArmorValue(), a->getCharactresistics()->getSpeed() + d); + a->changeCharactresistics(new_c); + } + void attackChange(int d, Unit* a) { + Atributes* new_c = new Atributes(a->getCharactresistics()->getDamage()->getDamageValue() + d, a->getCharactresistics()->getArmor()->getArmorValue(), a->getCharactresistics()->getSpeed()); + a->changeCharactresistics(new_c); + } + ~Landscape() { + + }; +}; +class Lake : public Landscape { + +public: + + Lake() { + this->SetType('~'); + this->SetAvailability(0); + //if (getUnit() != nullptr) { + // getUnit()->~Unit(); + //} + } + ~Lake() { + + }; +}; + +class Mountain : public Landscape { + +public: + + Mountain() { + this->SetType('^'); + this->SetAvailability(0); + + } + ~Mountain() { + + }; +}; + +class Plain : public Landscape { + +public: + + Plain() { + this->SetType(' '); + this->SetAvailability(1); + if (getUnit() != nullptr) { + if (getUnit()->getType() == '3') speedChange(2, getUnit()); + } + + } + ~Plain() { + + }; +}; + +class Forest : public Landscape { + +public: + + Forest() { + this->SetType('#'); + this->SetAvailability(1); + if (getUnit() != nullptr) { + if (getUnit()->getType() == '3') speedChange(-1, getUnit()); + if (getUnit()->getid() == '2') attackChange(-1, getUnit()); + } + + } + ~Forest() { + + }; +}; diff --git a/8304/Ivchenko_Anton/lab3/Strategy.h b/8304/Ivchenko_Anton/lab3/Strategy.h new file mode 100644 index 000000000..42167bdd8 --- /dev/null +++ b/8304/Ivchenko_Anton/lab3/Strategy.h @@ -0,0 +1,60 @@ +#pragma once +class Strategy { +public: + int damage_buff, armor_buff, speed_buff; + virtual void execute(Unit* a) = 0; + virtual void operator + (Unit* a) = 0; +}; + + +class WarriorsStrategy: public Strategy{ + + void operator + (Unit* a) { + Atributes* new_c = new Atributes(a->getCharactresistics()->getDamage()->getDamageValue() + (3/5 * damage_buff), a->getCharactresistics()->getArmor()->getArmorValue() + (4/5*armor_buff), a->getCharactresistics()->getSpeed() + (2 / 3 * speed_buff)); + a->changeCharactresistics(new_c); + } + void execute(Unit* a) { + (*this) + a; + } + +}; + +class ArchersStrategy:public Strategy { + + void operator + (Unit* a) { + Atributes* new_c = new Atributes(a->getCharactresistics()->getDamage()->getDamageValue() + (4/5 * damage_buff), a->getCharactresistics()->getArmor()->getArmorValue() + (3/5 * armor_buff), a->getCharactresistics()->getSpeed() + (2/3*speed_buff)); + a->changeCharactresistics(new_c); + } + void execute(Unit* a) { + (*this) + a; + } + +}; + +class CavalryStrategy:public Strategy { + + void operator + (Unit* a) { + Atributes* new_c = new Atributes(a->getCharactresistics()->getDamage()->getDamageValue() + (2/5 * damage_buff), a->getCharactresistics()->getArmor()->getArmorValue() + (3/5 * armor_buff), a->getCharactresistics()->getSpeed() + speed_buff); + a->changeCharactresistics(new_c); + } + void execute(Unit* a) { + (*this) + a; + } +}; +class Context { + +private: + Strategy* strategy; + Unit* unit; +public: + void setStrategy(Strategy* strat, int a, int b, int c, Unit* unit_) { + strategy = strat; + unit = unit_; + strategy->damage_buff = a; + strategy->armor_buff = b; + strategy->speed_buff = c; + }; + void executeStrategy() { + strategy->execute(unit); + }; +}; diff --git a/8304/Ivchenko_Anton/lab3/Unit.cpp b/8304/Ivchenko_Anton/lab3/Unit.cpp new file mode 100644 index 000000000..d0ee5841c --- /dev/null +++ b/8304/Ivchenko_Anton/lab3/Unit.cpp @@ -0,0 +1,120 @@ +#include "Unit.h" + +TypeOfUnit* UnitMap = new TypeOfUnit; + +Unit::Unit() { + id = '0'; characteristics = nullptr; +}; + +void Unit::attack(Unit* a) { + a->get_hit(characteristics->getDamage()->getDamageValue()); +} +void Unit::get_hit(int damage) { + Atributes* new_c = new Atributes (characteristics->getDamage()->getDamageValue(), characteristics->getArmor()->reduceHealth(damage), characteristics->getSpeed()); + this->changeCharactresistics(new_c); + +} +void Unit::check_armor(Unit* a) { + if (a->getCharactresistics()->getArmor() < 0) + a->~Unit(); +} +void Unit::setName(char a) { + this->id = a; +} +void Unit::setType(char a) { + this->type = a; +} +void Unit::setCoordinats(int x_, int y_) { + x = x_; y = y_; +} +char Unit::getid() { + return id; +} +int Unit::getx() { + return x; +} +int Unit::gety() { + return y; +} +char Unit::getType() { + return type; +} +Atributes* Unit::getCharactresistics() { + return characteristics; +} +void Unit::changeCharactresistics(Atributes* a) { + characteristics = a; + +} +Unit::~Unit() {}; + + +Warrior::Warrior() { + this->setType('i'); + this->changeCharactresistics(UnitMap->getType(this->getType())); + }; +Warrior::~Warrior() {}; + + +Swordman::Swordman() { + + this->setName('1'); + } +Swordman::~Swordman() {}; + +Spearman::Spearman() { + + this->setName('2'); + + }; +Spearman::~Spearman() {}; + + + +Archer::Archer() { + this->setType('a'); + this->changeCharactresistics(UnitMap->getType(this->getType())); + + + } +Archer::~Archer() {}; + + +Slinger::Slinger() { + + this->setName('3'); + + }; +Slinger::~Slinger() {}; + + +Bowman::Bowman() { + + this->setName('4'); + + + }; +Bowman::~Bowman() {}; + +Cavalry::Cavalry() { + this->setType('c'); + this->changeCharactresistics(UnitMap->getType(this->getType())); + + }; +Cavalry::~Cavalry() {}; + +LightCavalry::LightCavalry() { + + this->setName('5'); + + }; +LightCavalry::~LightCavalry() {}; + + + +HeavyCavalry::HeavyCavalry() { + + this->setName('6'); + + }; +HeavyCavalry::~HeavyCavalry() {}; diff --git a/8304/Ivchenko_Anton/lab3/Unit.h b/8304/Ivchenko_Anton/lab3/Unit.h new file mode 100644 index 000000000..9bcb1c79d --- /dev/null +++ b/8304/Ivchenko_Anton/lab3/Unit.h @@ -0,0 +1,108 @@ +#pragma once +#include "Flyweight.h" + +class Unit { + +private: + + int x, y; + char id, type; + Atributes *characteristics; + +public: + + Unit(); + void attack(Unit* a); + void get_hit(int damage); + void check_armor(Unit* a); + void setName(char a); + void setType(char a); + void setCoordinats(int x_, int y_); + char getid(); + char getType(); + int getx(); + int gety(); + Atributes* getCharactresistics(); + void changeCharactresistics(Atributes* a); + ~Unit(); + +}; + +class Warrior : public Unit { + +public: + + Warrior(); + ~Warrior(); + +}; + +class Swordman : public Warrior { + +public: + + Swordman(); + ~Swordman(); +}; + +class Spearman : public Warrior { + +public: + + Spearman(); + ~Spearman(); + +}; + +class Archer : public Unit { + +public: + + Archer(); + ~Archer(); +}; + +class Slinger : public Archer { + +public: + + Slinger(); + ~Slinger(); + +}; + +class Bowman : public Archer { + +public: + + Bowman(); + ~Bowman(); +}; + +class Cavalry : public Unit { + +public: + + Cavalry(); + ~Cavalry(); + +}; + +class LightCavalry : public Cavalry { + +public: + + LightCavalry(); + ~LightCavalry(); + + +}; + +class HeavyCavalry : public Cavalry { + +public: + + HeavyCavalry(); + ~HeavyCavalry(); + +}; diff --git a/8304/Ivchenko_Anton/lab3/main.cpp b/8304/Ivchenko_Anton/lab3/main.cpp new file mode 100644 index 000000000..92646944e --- /dev/null +++ b/8304/Ivchenko_Anton/lab3/main.cpp @@ -0,0 +1,127 @@ +#include +#include "Field.h" + +class UnitControl { +private: + Field* field; +public: + UnitControl(Field* f) { + field = f; + } + void UnitFunctional(Unit* a, Base* start_base) { + int choice = 2e7, x, y; + while (choice != 0) { + std::cout << "Unit: Moving(1), attack(2, coords), switch to base(0)\n Your choice:"; + std::cin >> choice; + switch (choice) { + case 1: + std::cin >> x >> y; + field->Moving(a, a->getx(), a->gety(), x, y); + break; + case 2: + std::cin >> x >> y; + if (abs(x - a->getx()) < a->getCharactresistics()->getSpeed() && abs(y - a->gety()) < a->getCharactresistics()->getSpeed()) { + + a->attack(field->getCoords(x, y)->getUnit()); + if (field->getCoords(x, y)->getUnit()->getCharactresistics()->getArmor()->getArmorValue() < 0) { + Unit* b = field->getCoords(x, y)->getUnit(); + field->RemObj(b, x, y); + start_base->deleteUnit(b); + field->Moving(a, a->getx(), a->gety(), x - a->getx(), y - a->gety()); + } + } + else if (x - a->getx() == 0) + field->Moving(a, a->getx(), a->gety(), 0, a->getCharactresistics()->getSpeed() * (y - a->gety()) / abs(y - a->gety())); + else if (y - a->gety() == 0) + field->Moving(a, a->getx(), a->gety(), a->getCharactresistics()->getSpeed() * (x - a->getx()) / abs(x - a->getx()), 0); + else field->Moving(a, a->getx(), a->gety(), a->getCharactresistics()->getSpeed() * (x - a->getx() )/ abs(x - a->getx()), a->getCharactresistics()->getSpeed() * (y - a->gety()) / abs(y - a->gety())); + break; + }field->PrintField(); + } + } +}; +class BaseControl { +private: + Base* start_base; + Field* field; + UnitControl* unit_ctrl; +public: + BaseControl(Field* f) { + field = f; + start_base = field->SetBase(0, 0); + unit_ctrl = new UnitControl(field); + } + ; + void BaseFunctional() { + int choice = 2e7, x, y; + Unit* unit = nullptr; + while (choice != 0) { + std::cout << "\nBase: create swordman(1), spearman(2), slinger(3), bowman(4),light cavalry(5), heavy cavalry(6)\nSwitch to unit(7, write coords)\nCheck base condition(8)\nQuit(0)\nYour choice:"; + std::cin >> choice; + + switch (choice) { + case 1: + { + unit = start_base->createSwordman(); + field->AddObj(unit, unit->getx(), unit->gety()); + break; + } + case 2: + { + unit = start_base->createSpearman(); + field->AddObj(unit, unit->getx(), unit->gety()); + break; + } + case 3: + { + unit = start_base->createSlinger(); + field->AddObj(unit, unit->getx(), unit->gety()); + break; + } + case 4: + { + unit = start_base->createBowman(); + field->AddObj(unit, unit->getx(), unit->gety()); + break; + } + case 5: + { + unit = start_base->createLC(); + field->AddObj(unit, unit->getx(), unit->gety()); + break; + } + case 6: + { + unit = start_base->createHC(); + field->AddObj(unit, unit->getx(), unit->gety()); + break; + } + case 7: { + std::cin >> x >> y; + if (field->getCoords(x, y)->getUnit()->getid() != '0') + unit_ctrl->UnitFunctional(unit, start_base); + else std::cout << "Incorrect coordinates"; + break; + }case 8: { + start_base->printBaseCondition(); + break; + } + + }field->PrintField(); + } + + + } + +}; + +int main() { + + Field *f = new Field(10, 30, 30); + f->formLandscape(); + + BaseControl* base = new BaseControl(f); + base->BaseFunctional(); + + return 0; +} diff --git a/8304/Ivchenko_Anton/lab3/report_lr3.pdf b/8304/Ivchenko_Anton/lab3/report_lr3.pdf new file mode 100644 index 000000000..cd2868a82 Binary files /dev/null and b/8304/Ivchenko_Anton/lab3/report_lr3.pdf differ