Skip to content

[8303] Rudko lab3-5 #843

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

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
30 changes: 30 additions & 0 deletions Rudko/Lab1.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += \
base.cpp \
facade.cpp \
gfield.cpp \
log.cpp \
main.cpp \
memento.cpp \
unit.cpp

HEADERS += \
base.h \
deathcard.h \
facade.h \
forest.h \
gfield.h \
land.h \
landscape.h \
log.h \
memento.h \
negativecard.h \
neutralobkect.h \
positivecard.h \
swamp.h \
transformationcard.h \
unit.h
335 changes: 335 additions & 0 deletions Rudko/Lab1.pro.user

Large diffs are not rendered by default.

137 changes: 137 additions & 0 deletions Rudko/base.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#include "base.h"
#include <string.h>

Base::Base(int x, int y, GField* field){
this->field = field;
if(field->map1[x][y]->type == "landscape" && !flag_base){
Unit* BASE = new Unit;
BASE->x = x;
BASE->y = y;
base_x = x;
base_y = y;
BASE->health = 1000;
BASE->type = "base";
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]->type == "landscape"){
counter++;
if(counter > 7)
std::cout << "На поле максимальное количество юнитов" << std::endl;
else
field->addUnit(unit, x, y);
}
}

void Base::Condition(){
std::cout << "Coordinats = " << base_x << ' ' << base_y << std::endl;
std::cout << "Helth = " << base_helth << std::endl;
std::cout << "People on the field = " << counter << std::endl;
}

void Base::Control(int x, int y, std::string answer){
//std::cout << x << ' ' << y << std::endl;
if(x >= field->getLength() || y >= field->getLength() || x < 0 || y < 0){
std::cout << "Ввседите координаты удовлетворяющие полю" << std::endl;
}
else {
if(answer != "L" && answer != "R" && answer != "U" && answer != "D")
std::cout << "Введите существующие команды" << std::endl;
else {
if(answer == "L"){
if(field->map1[x][y-1]->type == "landscape"){
if(field->getLand()->isMoved(field->map1[x][y]))
if(field->getLand()->isDamage(field->map1[x][y])){
field->map1[x][y]->health -= 3;
std::cout << "! Воин получил урон в размере 3 едениц !" << std::endl;
field->moveUnite(field->map1[x][y], x, y-1);
return;
}else {
field->moveUnite(field->map1[x][y], x, y-1);
return;
}
else{
std::cout << "Воин не может передвигаться по даннаму типу ландшафта" << std::endl;
return;
}
}
}
if(answer == "R"){
if(field->map1[x][y+1]->type == "landscape"){
if(field->getLand()->isMoved(field->map1[x][y]))
if(field->getLand()->isDamage(field->map1[x][y])){
field->map1[x][y]->health -= 3;
std::cout << "! Воин получил урон в размере 3 едениц !" << std::endl;
field->moveUnite(field->map1[x][y], x, y+1);
return;
}else {
field->moveUnite(field->map1[x][y], x, y+1);
return;
}
else{
std::cout << "Воин не может передвигаться по даннаму типу ландшафта" << std::endl;
return;
}
}
}
if(answer == "U"){
if(field->map1[x-1][y]->type == "landscape"){
if(field->getLand()->isMoved(field->map1[x][y]))
if(field->getLand()->isDamage(field->map1[x][y])){
field->map1[x][y]->health -= 3;
std::cout << "! Воин получил урон в размере 3 едениц !" << std::endl;
field->moveUnite(field->map1[x][y], x-1, y);
return;
}else {
field->moveUnite(field->map1[x][y], x-1, y);
return;
}
else{
std::cout << "Воин не может передвигаться по даннаму типу ландшафта" << std::endl;
return;
}
}
}
if(answer == "D"){
if(field->map1[x+1][y]->type == "landscape"){
if(field->getLand()->isMoved(field->map1[x][y])){
if(field->getLand()->isDamage(field->map1[x][y])){
field->map1[x][y]->health -= 3;
std::cout << "! Воин получил урон в размере 3 едениц !" << std::endl;
field->moveUnite(field->map1[x][y], x+1, y);
return;
}else {
//std::cout << field->map1[x][y]->x << ' ' << field->map1[x][y]->y << std::endl;
//std::cout << x << ' ' << y << std::endl;
field->moveUnite(field->map1[x][y], x+1, y);
return;
}
}
else{
std::cout << "Воин не может передвигаться по даннаму типу ландшафта" << std::endl;
return;
}
}
}
std::cout << "Клетка игрового поля занята" << std::endl;
return;
}
}

}

int Base::getCount(){
return counter;
}
25 changes: 25 additions & 0 deletions Rudko/base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef BASE_H
#define BASE_H

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

class Base
{
private:
GField* field;
int base_helth;
int base_x, base_y;
bool flag_base = 0;

public:
int counter = 0;
Base(int, int, GField*);
void CreatureUnit(int, int, std::string);
int getCount();
void Condition();
void Control(int, int, std::string);
};

#endif // BASE_H
25 changes: 25 additions & 0 deletions Rudko/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
80 changes: 80 additions & 0 deletions Rudko/facade.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "facade.h"

void Facade::NewGame(){
l = new log;
l1 = new log(1);
field = new GField(10, 10);
field->addLabdscape();
base = new Base(1, 1, this->field);
base->CreatureUnit(0, 2, "scorpio");
l1->logt("base", 3, 0, 2, "scorpio");
base->CreatureUnit(0, 3, "mammoth");
l1->logt("base", 3, 0, 3, "mammoth");
base->CreatureUnit(0, 4, "frog");
l1->logt("base", 3, 0, 4, "frog");
base->CreatureUnit(0, 5, "kangaroo");
l1->logt("base", 3, 0, 5, "kangaroo");
base->CreatureUnit(0, 6, "swallow");
l1->logt("base", 3, 0, 6, "swallow");
base->CreatureUnit(0, 7, "hawk");
l1->logt("base", 3, 0, 7, "hawk");
}

void Facade::Play(){
std::cout << "Now playning" << std::endl;
std::string answer;
std::string name;
int x,y;
while(answer != "exit"){
std::cout << "> ";
std::cin >> answer;
if(answer != "exit")
if(answer != "save")
if(answer != "display")
if(answer != "base")
std::cin >> x >> y;
if(answer != "exit"){
if(answer == "base"){
l->logf(answer, 1, 0, 0, "chek");
l->logf(answer, 3, 0, 0, "base");
base->Condition();
}
else {
if(answer == "add"){
l->logf(answer, 1, 0, 0, "add");
std::cin >> name;
l->logf(answer, 3, 0, 0, name);
l->logf(answer, 2, x, y, name);
base->CreatureUnit(x, y, name);
field->printField();
}
else {
if(answer == "save"){
l->logf(answer, 1, 0, 0, "save");
std::string p = "Save.txt";
s = new Memento(p);
s->record(field);
s->~Memento();
}
else {
if(answer == "display"){
l->logf(answer, 1, 0, 0, "display");
s = new Memento;
s->display();
s->~Memento();
}
else {
std::string n = field->map1[x][y]->name;
l->logf(answer, 2, x, y, n);
base->Control(x, y, answer);
field->printField();
}
}
}
}
}
}
l->logf(answer, 1, 0, 0, "exit");
l->~log();
std::cout << "Всего хорошего!" << std::endl;
}
26 changes: 26 additions & 0 deletions Rudko/facade.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef FACADE_H
#define FACADE_H

#include "unit.h"
#include "gfield.h"
#include "base.h"
#include "memento.h"
#include "log.h"

#include <string>

class Facade
{
private:
GField* field;
Base* base;
Memento* s;
log* l;
log* l1;

public:
void NewGame();
void Play();
};

#endif // FACADE_H
34 changes: 34 additions & 0 deletions Rudko/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 Unit
{
public:
Forest(){
this->type = "landscape";
this->name = "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
Loading