diff --git a/8303/Rudko_Daniil_lb2/Report_OOP_2.pdf b/8303/Rudko_Daniil_lb2/Report_OOP_2.pdf new file mode 100644 index 000000000..40490e71e Binary files /dev/null and b/8303/Rudko_Daniil_lb2/Report_OOP_2.pdf differ diff --git a/8303/Rudko_Daniil_lb2/base.cpp b/8303/Rudko_Daniil_lb2/base.cpp new file mode 100644 index 000000000..525cf9154 --- /dev/null +++ b/8303/Rudko_Daniil_lb2/base.cpp @@ -0,0 +1,33 @@ +#include "base.h" + +Base::Base(int x, int y, GField* field){ + this->field = field; + if(field->map1[x][y] == nullptr && !flag_base){ + Unit* BASE = new Unit; + BASE->x = x; + BASE->y = y; + BASE->health = 1000; + BASE->name = "BASE"; + field->map1[x][y] = BASE; + flag_base = 1; + } +} + +void Base::CreatureUnit(int x, int y, std::string Name){ + Unit* unit; + //std::vector> map = field->getMap(); + if(Name == "scorpio") { unit = new Scorpio(); }//num++; } + if(Name == "mammoth") { unit = new Mammoth(); }//num++; } + if(Name == "frog") { unit = new Frog(); }//num++; } + if(Name == "kangaroo"){ unit = new Kangaroo(); }//num++; } + if(Name == "swallow") { unit = new Swallow(); }//num++; } + if(Name == "hawk") { unit = new Hawk(); }//num++; } + if(field->map1[x][y] == nullptr){ + counter++; + field->addUnit(unit, x, y); + } +} + +int Base::getCount(){ + return counter; +} diff --git a/8303/Rudko_Daniil_lb2/base.h b/8303/Rudko_Daniil_lb2/base.h new file mode 100644 index 000000000..0cbe66998 --- /dev/null +++ b/8303/Rudko_Daniil_lb2/base.h @@ -0,0 +1,22 @@ +#ifndef BASE_H +#define BASE_H + +#include "unit.h" +#include "gfield.h" +#include + +class Base +{ +private: + GField* field; + int base_helth; + int counter = 0; + bool flag_base = 0; + +public: + Base(int, int, GField*); + void CreatureUnit(int, int, std::string); + int getCount(); +}; + +#endif // BASE_H diff --git a/8303/Rudko_Daniil_lb2/deathcard.h b/8303/Rudko_Daniil_lb2/deathcard.h new file mode 100644 index 000000000..d2978cce1 --- /dev/null +++ b/8303/Rudko_Daniil_lb2/deathcard.h @@ -0,0 +1,25 @@ +#ifndef DEATHCARD_H +#define DEATHCARD_H + +#include "neutralobkect.h" +#include "gfield.h" + +class DeathCard : public Neutral +{ +private: + std::string name_death; + GField* field; +public: + DeathCard(GField* field){} + std::string name() override{ + name_death = "death_card"; + + } + void operator /(Unit* unit){ + this->field = field; + field->deleteUnite(unit); + } + +}; + +#endif // DEATHCARD_H diff --git a/8303/Rudko_Daniil_lb2/forest.h b/8303/Rudko_Daniil_lb2/forest.h new file mode 100644 index 000000000..28830224c --- /dev/null +++ b/8303/Rudko_Daniil_lb2/forest.h @@ -0,0 +1,34 @@ +#ifndef FOREST_H +#define FOREST_H + +#include "landscape.h" + +class Forest: public Landscape +{ +public: + Forest(){}; + + std::string namelandscape() override{ + return "forest"; + } + + bool isMoved(Unit* unit) override{ + if(unit->type == "MeleeWarrior") + return true; + if(unit->type == "MediumWarrior") + return true; + if(unit->type == "DistanceWarrior") + return true; + } + + bool isDamage(Unit* unit) override{ + if(unit->type == "MeleeWarrior") + return true; + if(unit->type == "MediumWarrior") + return true; + if(unit->type == "DistanceWarrior") + return false; + } +}; + +#endif // FOREST_H diff --git a/8303/Rudko_Daniil_lb2/gfield.cpp b/8303/Rudko_Daniil_lb2/gfield.cpp new file mode 100644 index 000000000..be4ed158d --- /dev/null +++ b/8303/Rudko_Daniil_lb2/gfield.cpp @@ -0,0 +1,92 @@ +#include "gfield.h" + +using namespace std; + +GField::GField(int x, int y) { + x = max(x,y); + this->length = x; + this->width = x; + this->numberUnit = 0; + + //map = new Unit** [this->length]; + map1.resize(this->width); + for (int i = 0; i < this->width; i++) + { + //map[i] = new Unit* [x]; + map1[i].resize(this->length); + for (int j = 0; j < this->length; j++){ + //map[i][j] = nullptr; + map1[i][j] = nullptr; + } + } + + +} + +GField::GField(const GField &gfield) {} + + + +void GField::addUnit(Unit* unite, int x, int y) { + if (x < this->length && y < this->width && this->numberUnit < this->maxnumberUnit) { + //map[unite->x][unite->y] = unite; + map1[x][y] = unite; + this->numberUnit++; + } + else + if(this->numberUnit >= this->maxnumberUnit) + std::cout << "На поле максимальное количество юнитов" << std::endl; + } + +void GField::moveUnite(Unit* unite, int newx, int newy) { + if (map1[newx][newy] == nullptr) { + map1[unite->x][unite->y] = nullptr; + unite->move(newx, newy); + unite->x = newx; + unite->y = newy; + map1[unite->x][unite->y] = unite; + } + else { + std::cout << "Клетка игрового поля занята" << std::endl; + } + } + +void GField::deleteUnite(Unit* unite) { + int x = unite->x; + int y = unite->y; + delete map1[unite->x][unite->y]; + map1[x][y] = nullptr; + + this->numberUnit--; + } + +void GField::printField() { + for (int i = 0; i < this->length; i++) { + for (int j = 0; j < this->width; j++) + if (map1[i][j] != nullptr) { + cout << map1[i][j]->name << " "; + } + else { + cout << "X "; + } + cout << endl; + } +} + +std::vector> GField::getMap(){ + return map1; +} +void GField::setMap(std::vector> map){ + map1 = map; +} +int GField::getMaxUnit(){ + return maxnumberUnit; +} +int GField::getNumUnit(){ + return numberUnit; +} +void GField::setNumUnit(int num){ + numberUnit = num; +} + + diff --git a/8303/Rudko_Daniil_lb2/gfield.h b/8303/Rudko_Daniil_lb2/gfield.h new file mode 100644 index 000000000..9f723cd70 --- /dev/null +++ b/8303/Rudko_Daniil_lb2/gfield.h @@ -0,0 +1,33 @@ +#ifndef GFIELD_H +#define GFIELD_H + +#include "unit.h" +#include + +class GField{ +private: + int length, width; + int numberUnit; + const int maxnumberUnit = 5; + //Unit*** map; + + +public: + + std::vector> map1; + + GField(const GField &gfield); + + GField(int , int ); + void addUnit(Unit*, int, int); + void moveUnite(Unit* , int , int); + void deleteUnite(Unit*); + void printField(); + int getMaxUnit(); + int getNumUnit(); + void setNumUnit(int); + std::vector> getMap(); + void setMap(std::vector>); +}; + +#endif // GFIELD_H diff --git a/8303/Rudko_Daniil_lb2/land.h b/8303/Rudko_Daniil_lb2/land.h new file mode 100644 index 000000000..e08057d53 --- /dev/null +++ b/8303/Rudko_Daniil_lb2/land.h @@ -0,0 +1,34 @@ +#ifndef LAND_H +#define LAND_H + +#include "landscape.h" + +class Land: public Landscape +{ +public: + Land(){}; + + std::string namelandscape() override{ + return "land"; + } + + bool isMoved(Unit* unit) override{ + if(unit->type == "MeleeWarrior") + return true; + if(unit->type == "MediumWarrior") + return true; + if(unit->type == "DistanceWarrior") + return true; + } + + bool isDamage(Unit* unit) override{ + if(unit->type == "MeleeWarrior") + return false; + if(unit->type == "MediumWarrior") + return false; + if(unit->type == "DistanceWarrior") + return false; + } +}; + +#endif // LAND_H diff --git a/8303/Rudko_Daniil_lb2/landscape.cpp b/8303/Rudko_Daniil_lb2/landscape.cpp new file mode 100644 index 000000000..62b18b3d9 --- /dev/null +++ b/8303/Rudko_Daniil_lb2/landscape.cpp @@ -0,0 +1,6 @@ +#include "landscape.h" + +Landscape::Landscape() +{ + +} diff --git a/8303/Rudko_Daniil_lb2/landscape.h b/8303/Rudko_Daniil_lb2/landscape.h new file mode 100644 index 000000000..62bb0919d --- /dev/null +++ b/8303/Rudko_Daniil_lb2/landscape.h @@ -0,0 +1,14 @@ +#ifndef LANDSCAPE_H +#define LANDSCAPE_H + +#include "unit.h" + +class Landscape +{ +public: + virtual bool isMoved(Unit* ) = 0; + virtual bool isDamage(Unit* ) = 0; + virtual std::string namelandscape() = 0; +}; + +#endif // LANDSCAPE_H diff --git a/8303/Rudko_Daniil_lb2/main.cpp b/8303/Rudko_Daniil_lb2/main.cpp new file mode 100644 index 000000000..5fc5527ab --- /dev/null +++ b/8303/Rudko_Daniil_lb2/main.cpp @@ -0,0 +1,38 @@ +#include +#include "unit.h" +#include "gfield.h" +#include "base.h" + +using namespace std; + +int main(){ + cout << "Введите размеры поля" << endl; + int a, b, c, d; + cin >> a >> b; + GField* field = new GField(a, b); + field->printField(); + cout << "Введите координаты базы" << endl; + cin >> a >> b; + Base* base = new Base(a-1, b-1, field); + field->printField(); + cout << "Начальное число юнитов на поле" << endl; + cin >> a; + cout << "Имена юнитов:\n" + "\t\t scorpio\n" + "\t\t mammoth\n" + "\t\t frog\n" + "\t\t kangaroo\n" + "\t\t swallow\n" + "\t\t hawk" << endl; + for(int i = 0; i < a; i++){ + int x,y; + string name; + cout << "Введите имя юнита и его координаты" << endl; + cin >> name >> x >> y; + base->CreatureUnit(x-1, y-1, name); + } + field->printField(); + + return 0; +} + diff --git a/8303/Rudko_Daniil_lb2/negativecard.h b/8303/Rudko_Daniil_lb2/negativecard.h new file mode 100644 index 000000000..1b44f7a46 --- /dev/null +++ b/8303/Rudko_Daniil_lb2/negativecard.h @@ -0,0 +1,24 @@ +#ifndef NEGATIVECARD_H +#define NEGATIVECARD_H + +#include "neutralobkect.h" + +class NegativeCard : public Neutral +{ +private: + std::string name_minus; +public: + NegativeCard(){} + std::string name() override{ + name_minus = "negative_card"; + + } + void operator -(Unit* unit){ + unit->health -= 10; + unit->armor -= 10; + unit->attack -=10; + } + +}; + +#endif // NEGATIVECARD_H diff --git a/8303/Rudko_Daniil_lb2/neutralobkect.h b/8303/Rudko_Daniil_lb2/neutralobkect.h new file mode 100644 index 000000000..6e5e147b1 --- /dev/null +++ b/8303/Rudko_Daniil_lb2/neutralobkect.h @@ -0,0 +1,11 @@ +#ifndef NEUTRALOBKECT_H +#define NEUTRALOBKECT_H + +#include "unit.h" + +class Neutral{ +public: + virtual std::string name() = 0; +}; + +#endif // NEUTRALOBKECT_H diff --git a/8303/Rudko_Daniil_lb2/positivecard.h b/8303/Rudko_Daniil_lb2/positivecard.h new file mode 100644 index 000000000..ac0c77845 --- /dev/null +++ b/8303/Rudko_Daniil_lb2/positivecard.h @@ -0,0 +1,24 @@ +#ifndef HELTHCARD_H +#define HELTHCARD_H + +#include "neutralobkect.h" + +class PositiveCard : public Neutral +{ +private: + std::string name_plus; +public: + PositiveCard(){} + std::string name() override{ + name_plus = "positive_card"; + + } + void operator +(Unit* unit){ + unit->health += 10; + unit->armor += 10; + unit->attack +=10; + } + +}; + +#endif // HELTHCARD_H diff --git a/8303/Rudko_Daniil_lb2/swamp.h b/8303/Rudko_Daniil_lb2/swamp.h new file mode 100644 index 000000000..6d111cca4 --- /dev/null +++ b/8303/Rudko_Daniil_lb2/swamp.h @@ -0,0 +1,34 @@ +#ifndef SWAMP_H +#define SWAMP_H + +#include "landscape.h" + +class Swamp: public Landscape +{ +public: + Swamp(){}; + + std::string namelandscape() override{ + return "swamp"; + } + + bool isMoved(Unit* unit) override{ + if(unit->type == "MeleeWarrior") + return false; + if(unit->type == "MediumWarrior") + return false; + if(unit->type == "DistanceWarrior") + return true; + } + + bool isDamage(Unit* unit) override{ + if(unit->type == "MeleeWarrior") + return true; + if(unit->type == "MediumWarrior") + return true; + if(unit->type == "DistanceWarrior") + return false; + } +}; + +#endif // SWAMP_H diff --git a/8303/Rudko_Daniil_lb2/transformationcard.h b/8303/Rudko_Daniil_lb2/transformationcard.h new file mode 100644 index 000000000..1146ffa06 --- /dev/null +++ b/8303/Rudko_Daniil_lb2/transformationcard.h @@ -0,0 +1,24 @@ +#ifndef TRANSFORMATIONCARD_H +#define TRANSFORMATIONCARD_H + +#include "neutralobkect.h" + +class TransformationCard : public Neutral +{ +private: + std::string name_transform; +public: + TransformationCard() {} + std::string name() override{ + name_transform = "transformation_card"; + + } + + void operator*(Unit* unit){ + unit->attack += 20; + unit->armor -= 10; + } + +}; + +#endif // TRANSFORMATIONCARD_H diff --git a/8303/Rudko_Daniil_lb2/unit.cpp b/8303/Rudko_Daniil_lb2/unit.cpp new file mode 100644 index 000000000..0f4f71988 --- /dev/null +++ b/8303/Rudko_Daniil_lb2/unit.cpp @@ -0,0 +1,66 @@ +#include "unit.h" + +void Unit::move(int x, int y) { + this->x = x - 1; + this->y = y - 1; +} + +Scorpio::Scorpio() { + //this->x = x; + //this->y = y; + this->type = "MeleeWarrior"; + this->name = "scorpio"; + this->health = 100; + this->armor = 50; + this->attack = 30; +} + +Mammoth::Mammoth() { + //this->x = x; + //this->y = y; + this->type = "MeleeWarrior"; + this->name = "mammoth"; + this->health = 200; + this->armor = 70; + this->attack = 50; +} + +Frog::Frog() { + //this->x = x; + //this->y = y; + this->type = "MediumWarrior"; + this->name = "frog"; + this->health = 100; + this->armor = 50; + this->attack = 10; +} + +Kangaroo::Kangaroo() { + //this->x = x; + //this->y = y; + this->type = "MediumWarrior"; + this->name = "kangaroo"; + this->health = 100; + this->armor = 5; + this->attack = 67; +} + +Swallow::Swallow() { + //this->x = x; + //this->y = y; + this->type = "DistanceWarrior"; + this->name = "swallow"; + this->health = 100; + this->armor = 50; + this->attack = 30; +} + +Hawk::Hawk() { + //this->x = x; + //this->y = y; + this->type = "DistanceWarrior"; + this->name = "hawk"; + this->health = 100; + this->armor = 50; + this->attack = 30; +} diff --git a/8303/Rudko_Daniil_lb2/unit.h b/8303/Rudko_Daniil_lb2/unit.h new file mode 100644 index 000000000..3fe1b30ee --- /dev/null +++ b/8303/Rudko_Daniil_lb2/unit.h @@ -0,0 +1,73 @@ +#ifndef UNIT_H +#define UNIT_H + +#include +#include + +class Unit { +public: + int x, y; + int health; + int armor; + int attack; + std::string type; + std::string name; + void move(int, int); +}; + +class MeleeWarrior + :public Unit { +protected: + int melee_r; +}; + +class MediumWarrior + :public Unit { +protected: + int medium_r; +}; + +class DistanceWarrior + :public Unit { +protected: + int distance_r; +}; + +class Scorpio + :public MeleeWarrior { //класс воинов "скорпион", ближний бой +public: + Scorpio(); +}; + +class Mammoth + :public MeleeWarrior { //класс воинов "мамонт", ближний бой +public: + Mammoth(); +}; + +class Frog + :public MediumWarrior { //класс воинов "лягушка", бой на средней дистанции +public: + Frog(); +}; + +class Kangaroo + :public MediumWarrior { //класс воинов "кенгуру", бой на средней дистанции +public: + Kangaroo(); +}; + +class Swallow + :public DistanceWarrior { //класс воинов "ласточка", дальний бой +public: + Swallow(); +}; + +class Hawk + :public DistanceWarrior { //класс воинов "ястреб", дальний бой +public: + Hawk(); +}; + + +#endif // UNIT_H