Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Strategy.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <string>
- #include <vector>
- #include <iostream>
- #include <map>
- using namespace std;
- class Unit {
- protected:
- string name;
- int attack;
- int health;
- int defense;
- int initiative;
- const string attack_type;
- public:
- void info() {
- cout << name << '\n';
- };
- };
- class Warrior : public Unit {
- protected:
- const string attack_type = "Closest target";
- };
- class Mage : public Unit {
- protected:
- const string attack_type = "All targets";
- string element;
- };
- class Ranger : public Unit {
- private:
- const string attack_type = "Any target";
- };
- class Knight : public Warrior {
- private:
- public:
- const static int ID = 0;
- const static int cost = 0;
- Knight() {
- name = "Knight";
- attack = 0;
- defense = 0;
- health = 0;
- initiative = 0;
- };
- ~Knight() {};
- };
- class Archer : public Ranger {
- private:
- public:
- const static int ID = 1;
- const static int cost = 0;
- Archer() {
- name = "Archer";
- attack = 0;
- defense = 0;
- health = 0;
- initiative = 0;
- };
- ~Archer() {};
- };
- class Wizard : public Mage {
- private:
- public:
- const static int ID = 2;
- const static int cost = 0;
- Wizard() {
- name = "Wizard";
- attack = 0;
- defense = 0;
- health = 0;
- initiative = 0;
- element = "Air";
- };
- ~Wizard() {};
- };
- /*class Hero {
- };
- class Special : public Unit {
- };*/
- class Army {
- public:
- vector<Warrior*> Warriors;
- vector<Mage*> Mages;
- vector<Ranger*> Rangers;
- void info() {
- cout << "Warriors:\n";
- for (auto i : Warriors) {
- i->info();
- }
- cout << "Mages:\n";
- for (auto i : Mages) {
- i->info();
- }
- cout << "Rangers:\n";
- for (auto i : Rangers) {
- i->info();
- }
- }
- ~Army() {
- for (auto i : Warriors) {
- delete i;
- }
- for (auto i : Mages) {
- delete i;
- }
- for (auto i : Rangers) {
- delete i;
- }
- }
- };
- class ArmyFactory {
- protected:
- map<string, vector<pair<string, int>>> FractionOverview;
- public:
- virtual Warrior* createWarrior(int ID) = 0;
- virtual Mage* createMage(int ID) = 0;
- virtual Ranger* createRanger(int ID) = 0;
- ~ArmyFactory() {};
- };
- class HumanArmyFactory : public ArmyFactory {
- public:
- HumanArmyFactory() {
- FractionOverview["Warriors"] = { make_pair("Knight", Knight::cost) };
- FractionOverview["Mages"] = { make_pair("Wizard", Wizard::cost) };
- FractionOverview["Rangers"] = { make_pair("Archer", Archer::cost) };
- }
- Warrior* createWarrior(int ID) {
- switch (ID) {
- case Knight::ID:
- return new Knight;
- }
- }
- Mage* createMage(int ID) {
- switch (ID) {
- case Wizard::ID:
- return new Wizard;
- }
- }
- Ranger* createRanger(int ID) {
- switch (ID) {
- case Archer::ID:
- return new Archer;
- }
- }
- };
- class UndeadArmyFactory : public ArmyFactory {
- public:
- };
- class Menu {
- public:
- Army* CreateArmy(int &balance, ArmyFactory* factory) {
- while (true) {
- cout << "Your balance: " << balance << "\n";
- for (auto i : factory->FractionOverview)
- }
- }
- };
- class Player {
- private:
- int fraction_ID;
- Army* Player_Army;
- int balance;
- ArmyFactory* factory;
- public:
- Player(int balance): fraction_ID(0), Player_Army(nullptr), balance(balance) {}
- int ShowFraction() {
- return fraction_ID;
- }
- void SetFraction() {
- cout << "Choose your fraction:\n1. Humans\n2. Undead";
- cin >> fraction_ID;
- switch (fraction_ID) {
- case 1:
- factory = new HumanArmyFactory();
- case 2:
- factory = new HumanArmyFactory();
- }
- }
- void Initialize() {
- SetFraction();
- Menu PlMenu;
- Player_Army = PlMenu.CreateArmy(balance, factory);
- }
- };
- int main()
- {
- int balance;
- cout << "Enter the starting treasury >> ";
- cin >> balance;
- Player Player_1(balance);
- Player_1.Initialize();
- Player Player_2(balance);
- Player_2.Initialize();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement