Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8303] Rudko Lab2 #820

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added 8303/Rudko_Daniil_lb2/Report_OOP_2.pdf
Binary file not shown.
33 changes: 33 additions & 0 deletions 8303/Rudko_Daniil_lb2/base.cpp
Original file line number Diff line number Diff line change
@@ -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<std::vector<Unit*>> 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;
}
22 changes: 22 additions & 0 deletions 8303/Rudko_Daniil_lb2/base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef BASE_H
#define BASE_H

#include "unit.h"
#include "gfield.h"
#include <string>

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
25 changes: 25 additions & 0 deletions 8303/Rudko_Daniil_lb2/deathcard.h
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions 8303/Rudko_Daniil_lb2/forest.h
Original file line number Diff line number Diff line change
@@ -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
92 changes: 92 additions & 0 deletions 8303/Rudko_Daniil_lb2/gfield.cpp
Original file line number Diff line number Diff line change
@@ -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<std::vector<Unit*>> GField::getMap(){
return map1;
}
void GField::setMap(std::vector<std::vector<Unit *>> map){
map1 = map;
}
int GField::getMaxUnit(){
return maxnumberUnit;
}
int GField::getNumUnit(){
return numberUnit;
}
void GField::setNumUnit(int num){
numberUnit = num;
}


33 changes: 33 additions & 0 deletions 8303/Rudko_Daniil_lb2/gfield.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef GFIELD_H
#define GFIELD_H

#include "unit.h"
#include <vector>

class GField{
private:
int length, width;
int numberUnit;
const int maxnumberUnit = 5;
//Unit*** map;


public:

std::vector<std::vector<Unit*>> 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<std::vector<Unit*>> getMap();
void setMap(std::vector<std::vector<Unit*>>);
};

#endif // GFIELD_H
34 changes: 34 additions & 0 deletions 8303/Rudko_Daniil_lb2/land.h
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions 8303/Rudko_Daniil_lb2/landscape.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "landscape.h"

Landscape::Landscape()
{

}
14 changes: 14 additions & 0 deletions 8303/Rudko_Daniil_lb2/landscape.h
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions 8303/Rudko_Daniil_lb2/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <iostream>
#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;
}

24 changes: 24 additions & 0 deletions 8303/Rudko_Daniil_lb2/negativecard.h
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions 8303/Rudko_Daniil_lb2/neutralobkect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef NEUTRALOBKECT_H
#define NEUTRALOBKECT_H

#include "unit.h"

class Neutral{
public:
virtual std::string name() = 0;
};

#endif // NEUTRALOBKECT_H
Loading