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

[8304] Masalykin_Daniil #850

Open
wants to merge 3 commits 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
83 changes: 83 additions & 0 deletions 8304/Masalykin_Daniil/BattleForHonour/Armor/Armor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#ifndef BATTLEFORHONOUR_ARMOR_H
#define BATTLEFORHONOUR_ARMOR_H

#include <ostream>
#include "ArmorType.h"


class Armor {

protected:

ArmorType type;
int absorbation{};

public:

Armor(){}

[[nodiscard]] int controlAbsorb() const {
return this->absorbation;
}
ArmorType getArmorType(){
return type;
}

friend std::ostream &operator<<(std::ostream &stream, const Armor &armor){
stream << "Armor = " << "Damage Absorb: " << armor.absorbation << " ;";
return stream;
}

bool operator==(Armor &other){
return this->type == other.type && this->absorbation == other.absorbation;
}

Armor& operator=(const Armor& tmp){
if (this == &tmp)
return *this;
this->type = tmp.type;
this->absorbation = tmp.absorbation;
return *this;
}
};


class LeatherArmor: public Armor {

public:
LeatherArmor(){
type = ArmorType::LIGHT;
absorbation = 2;
}
};

class PlateMail: public Armor{

public:
PlateMail(){
type = ArmorType::MEDIUM;
absorbation = 5;
}

};

class Robe: public Armor{

public:
Robe(){
type = ArmorType::MAGIC;
absorbation = 1;
}

};

class VladimirOffering: public Armor{

public:
VladimirOffering(){
type = ArmorType::HEAVY;
absorbation = 10;
}

};
#endif //BATTLEFORHONOUR_ARMOR_H
38 changes: 38 additions & 0 deletions 8304/Masalykin_Daniil/BattleForHonour/Armor/ArmorFlyWeight.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef BATTLEFORHONOUR_ARMORFLYWEIGHT_H
#define BATTLEFORHONOUR_ARMORFLYWEIGHT_H


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

class ArmorFlyweight {

private:

static ArmorFlyweight *self;
std::vector<Armor*> armorArr;

public:
template <typename Type>
static Type* getFlyweight(){

if (!self)
self = new ArmorFlyweight();

Type typeArmor;
for (auto *armor: self->armorArr){
if (typeArmor == *armor){
return static_cast<Type*>(armor);
}
}

Type *armorPtr = new Type();
self->armorArr.push_back(armorPtr);
return armorPtr;
}
};

ArmorFlyweight *ArmorFlyweight::self = nullptr;


#endif //BATTLEFORHONOUR_ARMORFLYWEIGHT_H
11 changes: 11 additions & 0 deletions 8304/Masalykin_Daniil/BattleForHonour/Armor/ArmorType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef BATTLEFORHONOUR_ARMORTYPE_H
#define BATTLEFORHONOUR_ARMORTYPE_H

enum class ArmorType{
LIGHT,
MEDIUM,
HEAVY,
MAGIC
};

#endif //BATTLEFORHONOUR_ARMORTYPE_H
86 changes: 86 additions & 0 deletions 8304/Masalykin_Daniil/BattleForHonour/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
cmake_minimum_required(VERSION 3.15)
project(BattleForHonour)

set(CMAKE_CXX_STANDARD 20)

add_executable(BattleForHonour
main.cpp
GameField/GameField.cpp
GameField/GameField.h
Objects/Unit.cpp
Objects/Unit.h
Weapon/Weapon.h
Armor/Armor.h
GameField/Point.h
GameField/GameFieldIterator.h
Objects/Units/Infantry/Infantry.h
Weapon/WeaponType.h
Armor/ArmorType.h
Objects/Units/Druid/Druid.h
Objects/Units/Archer/Archer.h
Objects/Units/Infantry/SwordMan.h
Objects/Units/Archer/CrossBowMan.h
Objects/Units/Archer/LongBowMan.h
Objects/Units/Infantry/SpearMan.h
Objects/Units/Druid/Priestess.h
Objects/Units/Druid/Hermit.h
GameField/FieldCell.cpp
GameField/FieldCell.h
Terrains/Terrain.h
Objects/Base.cpp
Objects/Base.h
Objects/Neutrals/NeutralObject.h
Objects/GameObject.cpp
Objects/GameObject.h
Objects/Neutrals/Tent.h
Objects/Neutrals/Hospital.h
Objects/Neutrals/Well.h
Terrains/TerrainProxy.cpp
Terrains/TerrainProxy.h
Objects/Neutrals/Archery.h
Objects/Neutrals/NeutralObjectStrategy.h
Objects/Neutrals/NeutralObjectStrategy.h
Objects/Neutrals/ArcherStrategy.h
Objects/Neutrals/InfantryStrategy.h
Objects/Neutrals/DruidStrategy.h
Armor/ArmorFlyweight.h
Weapon/WeaponFlyweight.h
Observers/Observers.h
User/Commands/Command.h
User/Commands/CreateBaseCommand.h
User/Commands/CreateUnitCommand.h
User/Commands/MoveUnitCommand.h
User/Commands/ShowBaseCommand.h
User/Commands/ShowUnitCommand.h
User/Commands/ShowCommand.h
User/Commands/CreateCommand.h
User/Commands/MoveCommand.h
User/Commands/SkipCommand.h
Game/GameFacade.h
Game/GameState.h
User/Commands/AttackCommand.h
User/Commands/AttackUnitCommand.h
Logs/LogProxy.h
Logs/Logger.h
Logs/FileLogger.h
Logs/CmdLogger.h
Logs/NoLogger.h
Logs/LogString.h
Logs/Log.h
User/Commands/ExitCommand.h
Logs/LogEnd.h
User/Commands/SaveCommand.h
User/Commands/LoadCommand.h
User/Commands/CommandSnapshot.h
User/CommandInterpreter.h
User/LoadCI.h
GameSettings/SmallGame.h
GameSettings/MidGame.h
GameSettings/GameRule.h
User/Commands/NewCommand.h
User/Commands/NewGameCommand.h
GameSettings/PlayerState.h
GameSettings/BigGame.h
GameSettings/HillKing.h
Exceptions/StackExceptions.h
Objects/UnitType.h User/Commands/SkipCommand.h Logs/Log.cpp Objects/ObjectType.h GameSettings/HillKing.h)
40 changes: 40 additions & 0 deletions 8304/Masalykin_Daniil/BattleForHonour/Exceptions/StackExceptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef BATTLEFORHONOUR_STACKEXCEPTIONS_H
#define BATTLEFORHONOUR_STACKEXCEPTIONS_H


#include <exception>


class DoubleBasePlacingExc: std::exception {

public:

int playerIndex;
explicit DoubleBasePlacingExc(int playerIndex): playerIndex(playerIndex){}

};

class OutOfRangeExc: std::exception {

public:
int x;
int y;
OutOfRangeExc(int x, int y): x(x), y(y){}
};

class DoublePlacingExc: std::exception {

};

class ImpossibleMoveExc: std::exception {

};

class InvalidFileLoadExc: std::exception {

};




#endif //BATTLEFORHONOUR_STACKEXCEPTIONS_H
68 changes: 68 additions & 0 deletions 8304/Masalykin_Daniil/BattleForHonour/Game/GameFacade.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#ifndef BATTLEFORHONOUR_GAMEFACADE_H
#define BATTLEFORHONOUR_GAMEFACADE_H


#include <sstream>
#include "GameState.h"
#include "../User/CommandInterpreter.h"


template<typename Rule, int playersCount>
class GameFacade: public GameState {

private:

CommandInterpreter actCommand;
Rule rule;
GameFacade(int fieldWidth, int fieldHeight):
GameState(playersCount, fieldWidth, fieldWidth, new Rule){}

public:

static GameFacade& single(){
Rule rule;
static GameFacade subSystem(rule.fieldWidth, rule.fieldHeight);
return subSystem;
}

friend std::ostream &operator<<(std::ostream &stream, const GameFacade &game){
stream << "Current user: " << game.currentUser << std::endl;
stream << game.gameField << std::endl;
return stream;
}

bool isOver(){
return rule.isOver(*this);
}

void nextTurn(){

std::string commandString;
std::getline(std::cin, commandString);

std::cout << "---------------------------------------------" << std::endl;

std::unique_ptr<Command> command = actCommand.handle(commandString);
try {
command->execute(*this);
} catch(DoubleBasePlacingExc &exception) {
std::cout << "User " << exception.playerIndex << " trying to place second base." << std::endl;
} catch (DoublePlacingExc &exception){
std::cout << "This cell is full by another object." << std::endl;
} catch (OutOfRangeExc &exception){
std::cout << "Out of range. Cell point " << exception.x << " " << exception.y << " is not exist." << std::endl;
} catch (ImpossibleMoveExc &exception){
std::cout << "Can't move to this cell. They busy by other object." << std::endl;
} catch (InvalidFileLoadExc &exception){
std::cout << "Wrong file." << std::endl;
} catch (...){
std::cout << "Unknown error." << std::endl;
}
gameActions.push_back(command->getSnapshot());
nextUser();
}

};


#endif //BATTLEFORHONOUR_GAMEFACADE_H
Loading