From 0b31bf6d31881908e0fcf3e4783bc37c8ad99ff1 Mon Sep 17 00:00:00 2001 From: stephaniewhoo Date: Wed, 10 Jan 2018 21:23:08 -0500 Subject: [PATCH] Add files via upload --- GiantStre.cc | 22 +++ GiantStre.h | 13 ++ MagicFati.cc | 16 ++ MagicFati.h | 13 ++ Makefile | 14 ++ Silence.cc | 15 ++ Silence.h | 13 ++ airelem.cc | 14 ++ airelem.h | 21 +++ apprentice.cc | 23 +++ apprentice.h | 18 ++ ascii_graphics.cc | 465 ++++++++++++++++++++++++++++++++++++++++++++++ ascii_graphics.h | 41 ++++ auraofpower.cc | 25 +++ auraofpower.h | 13 ++ banish.cc | 17 ++ banish.h | 14 ++ blizzard.cc | 28 +++ blizzard.h | 14 ++ board.cc | 74 ++++++++ board.h | 32 ++++ bonegolem.cc | 19 ++ bonegolem.h | 17 ++ card.cc | 33 ++++ card.h | 56 ++++++ darkritual.cc | 20 ++ darkritual.h | 12 ++ deck.cc | 117 ++++++++++++ deck.h | 22 +++ disenchant.cc | 15 ++ disenchant.h | 14 ++ earthelem.cc | 14 ++ earthelem.h | 17 ++ enchantment.cc | 55 ++++++ enchantment.h | 43 +++++ enrage.cc | 22 +++ enrage.h | 12 ++ fireelem.cc | 18 ++ fireelem.h | 17 ++ haste.cc | 18 ++ haste.h | 12 ++ main.cc | 249 +++++++++++++++++++++++++ massum.cc | 27 +++ massum.h | 17 ++ minion.cc | 103 ++++++++++ minion.h | 46 +++++ novice.cc | 22 +++ novice.h | 17 ++ player.cc | 244 ++++++++++++++++++++++++ player.h | 70 +++++++ potionsell.cc | 21 +++ potionsell.h | 17 ++ raisedead.cc | 15 ++ raisedead.h | 14 ++ recharge.cc | 18 ++ recharge.h | 14 ++ ritual.cc | 33 ++++ ritual.h | 39 ++++ spell.cc | 30 +++ spell.h | 40 ++++ standstill.cc | 21 +++ standstill.h | 12 ++ textdisplay.cc | 267 ++++++++++++++++++++++++++ textdisplay.h | 16 ++ unsummon.cc | 21 +++ unsummon.h | 14 ++ 66 files changed, 2845 insertions(+) create mode 100644 GiantStre.cc create mode 100644 GiantStre.h create mode 100644 MagicFati.cc create mode 100644 MagicFati.h create mode 100644 Makefile create mode 100644 Silence.cc create mode 100644 Silence.h create mode 100644 airelem.cc create mode 100644 airelem.h create mode 100644 apprentice.cc create mode 100644 apprentice.h create mode 100644 ascii_graphics.cc create mode 100644 ascii_graphics.h create mode 100644 auraofpower.cc create mode 100644 auraofpower.h create mode 100644 banish.cc create mode 100644 banish.h create mode 100644 blizzard.cc create mode 100644 blizzard.h create mode 100644 board.cc create mode 100644 board.h create mode 100644 bonegolem.cc create mode 100644 bonegolem.h create mode 100644 card.cc create mode 100644 card.h create mode 100644 darkritual.cc create mode 100644 darkritual.h create mode 100644 deck.cc create mode 100644 deck.h create mode 100644 disenchant.cc create mode 100644 disenchant.h create mode 100644 earthelem.cc create mode 100644 earthelem.h create mode 100644 enchantment.cc create mode 100644 enchantment.h create mode 100644 enrage.cc create mode 100644 enrage.h create mode 100644 fireelem.cc create mode 100644 fireelem.h create mode 100644 haste.cc create mode 100644 haste.h create mode 100644 main.cc create mode 100644 massum.cc create mode 100644 massum.h create mode 100644 minion.cc create mode 100644 minion.h create mode 100644 novice.cc create mode 100644 novice.h create mode 100644 player.cc create mode 100644 player.h create mode 100644 potionsell.cc create mode 100644 potionsell.h create mode 100644 raisedead.cc create mode 100644 raisedead.h create mode 100644 recharge.cc create mode 100644 recharge.h create mode 100644 ritual.cc create mode 100644 ritual.h create mode 100644 spell.cc create mode 100644 spell.h create mode 100644 standstill.cc create mode 100644 standstill.h create mode 100644 textdisplay.cc create mode 100644 textdisplay.h create mode 100644 unsummon.cc create mode 100644 unsummon.h diff --git a/GiantStre.cc b/GiantStre.cc new file mode 100644 index 0000000..1557298 --- /dev/null +++ b/GiantStre.cc @@ -0,0 +1,22 @@ +#include "GiantStre.h" +#include +using namespace std; + +GiantStre::GiantStre(Player *owner): Enchantment{ "Giant Strength", "Enchantment", "", 1, owner, 2, 2 } {} + +GiantStre::~GiantStre(){} + +void GiantStre::activate(shared_ptr c) { + cout<< "activating Giant Strength" << endl; + int points = c->getAttack() + 2; + c->setAttack(points); + points = c->getDefence() + 2; + c->setDefence(points); +} +void GiantStre::deactivate(shared_ptr c) { + cout << "deactivate Giant strength" << endl; + int points = c->getAttack() - 2; + c->setAttack(points); + points = c->getDefence() - 2; + c->setDefence(points); +} diff --git a/GiantStre.h b/GiantStre.h new file mode 100644 index 0000000..92217e0 --- /dev/null +++ b/GiantStre.h @@ -0,0 +1,13 @@ +#ifndef MAGFAT_H +#define MAGFAT_H +#include "enchantment.h" + +class GiantStre :public Enchantment { +public: + GiantStre(Player *owner); + ~GiantStre(); + void activate(std::shared_ptr c) override; + void deactivate(std::shared_ptr c) override; +}; +#endif // !MAGFAT_H + diff --git a/MagicFati.cc b/MagicFati.cc new file mode 100644 index 0000000..494041e --- /dev/null +++ b/MagicFati.cc @@ -0,0 +1,16 @@ +#include "MagicFati.h" +using namespace std; + +MagicFati::MagicFati(Player *owner): Enchantment{ "Magic Fatigue", "Enchantment", "Enchanted minion's activated ability costs 2 more", 0, owner, 0, 0 } {} + +MagicFati::~MagicFati(){} + +void MagicFati::activate(shared_ptr c){ + int cost = c->getAbCost() + 2; + c->setAbCost(cost); +} + +void MagicFati::deactivate(shared_ptr c) { + int cost = c->getAbCost() - 2; + c->setAbCost(cost); +} diff --git a/MagicFati.h b/MagicFati.h new file mode 100644 index 0000000..6ccfc44 --- /dev/null +++ b/MagicFati.h @@ -0,0 +1,13 @@ +#ifndef MAGICFATI_H +#define MAGICFATI_H +#include "enchantment.h" + +class MagicFati :public Enchantment { +public: + MagicFati(Player *owner); + ~MagicFati(); + void activate(std::shared_ptr c) override; + void deactivate(std::shared_ptr c) override; +}; +#endif // !MAGICFATI_H + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a98666a --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +CXX = g++-5 +CXXFLAGS = -std=c++14 -Werror=vla +EXEC = sorcery +OBJECTS = ascii_graphics.o board.o card.o deck.o main.o minion.o player.o ritual.o spell.o enchantment.o textdisplay.o airelem.o apprentice.o auraofpower.o banish.o blizzard.o bonegolem.o darkritual.o disenchant.o earthelem.o enrage.o fireelem.o GiantStre.o haste.o MagicFati.o massum.o novice.o potionsell.o raisedead.o recharge.o Silence.o standstill.o unsummon.o +DEPENDS = ${OBJECTS.o: .d} + +${EXEC}: ${OBJECTS} + ${CXX} ${CXXFLAGS} ${OBJECTS} -o ${EXEC} +-include ${DEPENDS} + +.PHONY: clean + +clean: + rm ${OBJECTS} ${EXEC} ${DEPENDS} diff --git a/Silence.cc b/Silence.cc new file mode 100644 index 0000000..0363506 --- /dev/null +++ b/Silence.cc @@ -0,0 +1,15 @@ +#include "Silence.h" +#include +using namespace std; + +Silence::Silence(Player *owner): Enchantment{ "Silence", "Enchantment", "Enchanted minion cannot use abilities", 1, owner, 0, 0 } {} + +Silence::~Silence() {} + +void Silence::activate(shared_ptr c) { + cout<<"using silence"<silence(); +} + +void Silence::deactivate(shared_ptr c) { +} diff --git a/Silence.h b/Silence.h new file mode 100644 index 0000000..dd3440a --- /dev/null +++ b/Silence.h @@ -0,0 +1,13 @@ +#ifndef SILENCE_H +#define SILENCE_H +#include "enchantment.h" + +class Silence :public Enchantment { +public: + Silence(Player *owner); + ~Silence(); + void activate(std::shared_ptr c) override; + void deactivate(std::shared_ptr c) override; +}; +#endif // !SILENCE_H + diff --git a/airelem.cc b/airelem.cc new file mode 100644 index 0000000..8e49d1f --- /dev/null +++ b/airelem.cc @@ -0,0 +1,14 @@ +#include "airelem.h" +#include +using namespace std; + +AirElem:: AirElem(Player *owner): + Minion{"Air Elemental","Minion","",0,owner,1,1,0}{} + +AirElem::~AirElem(){} + +void AirElem::activate(){} + +void AirElem::activate(shared_ptr target){} + +void AirElem::notify(const string event){} diff --git a/airelem.h b/airelem.h new file mode 100644 index 0000000..78619c5 --- /dev/null +++ b/airelem.h @@ -0,0 +1,21 @@ +#ifndef AIRELEM_H +#define AIRELEM_H +#include "player.h" +#include "card.h" +#include "minion.h" +#include + +class AirElem : public Minion { + public: + AirElem(Player *owner); + ~AirElem(); + void activate() override; + void activate(std::shared_ptr) override; + void notify(const std::string event) override; +}; + + + + +#endif + diff --git a/apprentice.cc b/apprentice.cc new file mode 100644 index 0000000..40003f1 --- /dev/null +++ b/apprentice.cc @@ -0,0 +1,23 @@ +#include "apprentice.h" +#include "airelem.h" +#include +using namespace std; + +AppSum:: AppSum(Player *owner): + Minion{"Apprentice Summoner","Minion","Summon a 1/1 air elemental",1,owner,1,1,1}{} + +AppSum::~AppSum(){} + +void AppSum::activate(){ + if (actionpts <= 0) return; + --actionpts; + if (owner->getMagic() >= abCost && !isSilence && owner->getMinion().size()<5){ + owner->getMinion().push_back(make_shared(owner)); + owner->subMagic(abCost); + } +} + +void AppSum::activate(shared_ptr target){} + +void AppSum::notify(const string event){} + diff --git a/apprentice.h b/apprentice.h new file mode 100644 index 0000000..1e87a47 --- /dev/null +++ b/apprentice.h @@ -0,0 +1,18 @@ +#ifndef APPRENTICE_H +#define APPRENTICE_H +#include "player.h" +#include "card.h" +#include "minion.h" + +class AppSum : public Minion { + public: + AppSum(Player *owner); + ~AppSum(); + void activate() override; + void activate(std::shared_ptr) override; + void notify(const std::string event) override; +}; + + +#endif + diff --git a/ascii_graphics.cc b/ascii_graphics.cc new file mode 100644 index 0000000..5098a01 --- /dev/null +++ b/ascii_graphics.cc @@ -0,0 +1,465 @@ +#include "ascii_graphics.h" +#include + +static void prepare_for_replace(card_template_t &); +static void replace_text_left(card_template_t &,char,std::string); +static void replace_text_right(card_template_t &,char,std::string); +static card_template_t display_minion_general(card_template_t,std::string,int,int,int, + std::string,int); + +static card_template_t display_enchantment_general(card_template_t,std::string,int,std::string, + std::string,std::string); +card_template_t display_minion_no_ability(std::string name,int cost,int attack,int defence) { + return display_minion_general(CARD_TEMPLATE_MINION_NO_ABILITY,name,cost,attack,defence,"",0); +} + +card_template_t display_minion_triggered_ability(std::string name,int cost,int attack, + int defence,std::string trigger_desc) { + return display_minion_general(CARD_TEMPLATE_MINION_NO_ABILITY,name,cost,attack, + defence,trigger_desc,0); +} + +card_template_t display_minion_activated_ability(std::string name,int cost,int attack, int defence, + int ability_cost,std::string ability_desc) { + return display_minion_general(CARD_TEMPLATE_MINION_WITH_ABILITY,name,cost,attack,defence, + ability_desc,ability_cost); +} + +card_template_t display_ritual(std::string name,int cost,int ritual_cost,std::string ritual_desc, + int ritual_charges) { + std::ostringstream oss; + card_template_t out(CARD_TEMPLATE_RITUAL); + prepare_for_replace(out); + replace_text_left(out,'N',name); + oss << cost; + replace_text_right(out,'C',oss.str()); + replace_text_right(out,'T',"Ritual"); + oss.str(""); + oss << ritual_cost; + replace_text_left(out,'K',oss.str()); + replace_text_left(out,'E',ritual_desc); + oss.str(""); + oss << ritual_charges; + replace_text_right(out,'D',oss.str()); + return out; +} + +card_template_t display_spell(std::string name,int cost,std::string desc) { + std::ostringstream oss; + card_template_t out(CARD_TEMPLATE_SPELL); + prepare_for_replace(out); + replace_text_left(out,'N',name); + oss << cost; + replace_text_right(out,'C',oss.str()); + replace_text_right(out,'T',"Spell"); + replace_text_left(out,'E',desc); + return out; +} + +card_template_t display_enchantment(std::string name,int cost,std::string desc) { + return display_enchantment_general(CARD_TEMPLATE_ENCHANTMENT,name,cost,desc,"",""); +} + +card_template_t display_enchantment_attack_defence(std::string name,int cost,std::string desc, + std::string attack,std::string defence) { + return display_enchantment_general(CARD_TEMPLATE_ENCHANTMENT_WITH_ATTACK_DEFENCE, + name,cost,desc,attack,defence); +} + +card_template_t display_player_card(int player_num,std::string name,int life,int mana) { + std::ostringstream oss; + card_template_t out = player_num == 1 ? PLAYER_1_TEMPLATE : PLAYER_2_TEMPLATE; + prepare_for_replace(out); + std::string centred_name = name; + if (centred_name.size() < 13) { + int extend = 13 - centred_name.size(); + oss.str(""); + for (int i=0;i CENTRE_GRAPHIC = +#if SIMPLE_GRAPHICS == 0 + {"╠═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╣", + "║ ║", + "║ ███████╗ ██████╗ ██████╗ ██████╗███████╗██████╗ ██╗ ██╗ ║", + "║ ██╔════╝██╔═══██╗██╔══██╗██╔════╝██╔════╝██╔══██╗╚██╗ ██╔╝ ║", + "║ ███████╗██║ ██║██████╔╝██║ █████╗ ██████╔╝ ╚████╔╝ ║", + "║ ╚════██║██║ ██║██╔══██╗██║ ██╔══╝ ██╔══██╗ ╚██╔╝ ║", + "║ ███████║╚██████╔╝██║ ██║╚██████╗███████╗██║ ██║ ██║ ║", + "║ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝╚═╝ ╚═╝ ╚═╝ ║", + "║ ║", + "╠═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╣"}; +#else + {"|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|", + "| _____ |", + "| / ____| |", + "| | (___ ___ _ __ ___ ___ _ __ _ _ |", + "| \\___ \\ / _ \\| '__/ __/ _ \\ '__| | | | |", + "| ____) | (_) | | | (_| __/ | | |_| | |", + "| |_____/ \\___/|_| \\___\\___|_| \\__, | |", + "| __/ | |", + "| |___/ |", + "|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|"}; +#endif + + +const std::string EXTERNAL_BORDER_CHAR_UP_DOWN = +#if SIMPLE_GRAPHICS == 0 + "║"; +#else + "|"; +#endif + +const std::string EXTERNAL_BORDER_CHAR_LEFT_RIGHT = +#if SIMPLE_GRAPHICS == 0 + "═"; +#else + "-"; +#endif + +const std::string EXTERNAL_BORDER_CHAR_TOP_LEFT = +#if SIMPLE_GRAPHICS == 0 + "╔"; +#else + "-"; +#endif + +const std::string EXTERNAL_BORDER_CHAR_TOP_RIGHT = +#if SIMPLE_GRAPHICS == 0 + "╗"; +#else + "-"; +#endif + +const std::string EXTERNAL_BORDER_CHAR_BOTTOM_LEFT = +#if SIMPLE_GRAPHICS == 0 + "╚"; +#else + "-"; +#endif + +const std::string EXTERNAL_BORDER_CHAR_BOTTOM_RIGHT = +#if SIMPLE_GRAPHICS == 0 + "╝"; +#else + "-"; +#endif + +//Delimiter used to separate replaceable blocks +//(Displayed by ~ in the actual strings) +//Should never appear in replaced text +static const char DELIMITER = '\v'; + +static void replace_text_left(card_template_t &text,char flag,std::string new_text) { + std::string::iterator sit = new_text.begin(); + bool start_replace = false; + bool end_replace = false; + for (card_template_t::iterator vit = text.begin(); vit != text.end(); ++vit) { + for (std::string::iterator lit = vit->begin(); lit != vit->end(); ++lit) { + if (*lit == DELIMITER && *(lit+1) == flag) { + start_replace = true; + } else if (*lit == DELIMITER) { + end_replace = true; + } + if (start_replace && (*lit == flag || *lit == DELIMITER)) { + if (sit != new_text.end()) { + *lit = *sit; + ++sit; + } else { + *lit = ' '; + } + } + if (end_replace) { + end_replace = false; + start_replace = false; + } + } + } +} + +static void replace_text_right(card_template_t &text,char flag,std::string new_text) { + std::string::reverse_iterator sit = new_text.rbegin(); + bool start_replace = false; + bool end_replace = false; + for (card_template_t::reverse_iterator vit = text.rbegin(); vit != text.rend(); ++vit) { + for (std::string::reverse_iterator lit = vit->rbegin(); lit != vit->rend(); ++lit) { + if (*lit == DELIMITER && *(lit+1) == flag) { + start_replace = true; + } else if (*lit == DELIMITER) { + end_replace = true; + } + if (start_replace && (*lit == flag || *lit == DELIMITER)) { + if (sit != new_text.rend()) { + *lit = *sit; + ++sit; + } else { + *lit = ' '; + } + } + if (end_replace) { + end_replace = false; + start_replace = false; + } + } + } +} + +static void prepare_for_replace(card_template_t &text) { + for (card_template_t::iterator it=text.begin();it != text.end();++it) { + for (std::string::iterator sit = it->begin();sit != it->end();++sit) { + if (*sit == '~') *sit = DELIMITER; + } + } +} diff --git a/ascii_graphics.h b/ascii_graphics.h new file mode 100644 index 0000000..b44cf7f --- /dev/null +++ b/ascii_graphics.h @@ -0,0 +1,41 @@ +#include +#include + +//If SIMPLE_GRAPHICS = 1, use | and - instead of unicode and simplify graphics +#define SIMPLE_GRAPHICS 1 + +typedef std::vector card_template_t; + +card_template_t display_minion_no_ability(std::string name,int cost,int attack,int defence); +card_template_t display_minion_triggered_ability(std::string name,int cost,int attack,int defence, + std::string trigger_desc); +card_template_t display_minion_activated_ability(std::string name,int cost,int attack,int defence, + int ability_cost, std::string ability_desc); +card_template_t display_ritual(std::string name,int cost,int ritual_cost,std::string ritual_desc, + int ritual_charges); +card_template_t display_spell(std::string name,int cost,std::string desc); +card_template_t display_enchantment_attack_defence(std::string name,int cost,std::string desc, + std::string attack,std::string defence); +card_template_t display_enchantment(std::string name,int cost,std::string desc); +card_template_t display_player_card(int player_num,std::string name,int life,int mana); + +extern const card_template_t CARD_TEMPLATE_MINION_NO_ABILITY; +extern const card_template_t CARD_TEMPLATE_MINION_WITH_ABILITY; +extern const card_template_t CARD_TEMPLATE_BORDER; +extern const card_template_t CARD_TEMPLATE_EMPTY; +extern const card_template_t CARD_TEMPLATE_RITUAL; +extern const card_template_t CARD_TEMPLATE_SPELL; +extern const card_template_t CARD_TEMPLATE_ENCHANTMENT_WITH_ATTACK_DEFENCE; +extern const card_template_t CARD_TEMPLATE_ENCHANTMENT; + +extern const card_template_t PLAYER_1_TEMPLATE; +extern const card_template_t PLAYER_2_TEMPLATE; + +extern const std::vector CENTRE_GRAPHIC; + +extern const std::string EXTERNAL_BORDER_CHAR_UP_DOWN; +extern const std::string EXTERNAL_BORDER_CHAR_LEFT_RIGHT; +extern const std::string EXTERNAL_BORDER_CHAR_TOP_LEFT; +extern const std::string EXTERNAL_BORDER_CHAR_TOP_RIGHT; +extern const std::string EXTERNAL_BORDER_CHAR_BOTTOM_LEFT; +extern const std::string EXTERNAL_BORDER_CHAR_BOTTOM_RIGHT; diff --git a/auraofpower.cc b/auraofpower.cc new file mode 100644 index 0000000..f2110c7 --- /dev/null +++ b/auraofpower.cc @@ -0,0 +1,25 @@ +#include +#include "auraofpower.h" +using namespace std; + +AuraOfPower::AuraOfPower(Player *owner): +Ritual{"Aura Of Power","Ritual","Whenever a minion enters play under your control, it gains +1/+1",1,owner,4,1}{ +} + +AuraOfPower::~AuraOfPower(){} + +void AuraOfPower::notify(const string event){ + if (actCost <= charge){ + if (event == "enter" && owner->getBoard()->getActive() == owner){ + charge -= actCost; + int originAttack = owner->getMinion().back()->getAttack(); + int originDefense = owner->getMinion().back()->getDefence(); + owner->getMinion().back()->setAttack(originAttack+1); + owner->getMinion().back()->setDefence(originDefense+1); + } + } + if (charge==0) { + owner->setRitual(nullptr); + } +} + diff --git a/auraofpower.h b/auraofpower.h new file mode 100644 index 0000000..9a6625e --- /dev/null +++ b/auraofpower.h @@ -0,0 +1,13 @@ +#ifndef AURA_OF_POWER_H +#define AURA_OF_POWER_H +#include "ritual.h" +#include "player.h" + +class AuraOfPower :public Ritual { + public: + AuraOfPower(Player *owner); + ~AuraOfPower(); + void notify(const std::string event) override; +}; + +#endif diff --git a/banish.cc b/banish.cc new file mode 100644 index 0000000..3011f38 --- /dev/null +++ b/banish.cc @@ -0,0 +1,17 @@ +#include "banish.h" +#include "player.h" +#include "spell.h" +#include + +using namespace std; + +Banish::Banish(Player *owner): Spell("Banish","Spell","Destroy target minion or ritual",2,owner){} + +Banish::~Banish(){} + +void Banish::activate(shared_ptr target){ + target->getOwner()->goToGrave(target); + } + +void Banish::activate() {} + diff --git a/banish.h b/banish.h new file mode 100644 index 0000000..19d09c8 --- /dev/null +++ b/banish.h @@ -0,0 +1,14 @@ +#ifndef __BANISH__ +#define __BANISH__ +#include "spell.h" +#include "card.h" + +class Banish: public Spell{ +public: + Banish(Player *owner); + ~Banish(); + void activate(std::shared_ptr target) override; + void activate() override; +}; + +#endif diff --git a/blizzard.cc b/blizzard.cc new file mode 100644 index 0000000..ce8e899 --- /dev/null +++ b/blizzard.cc @@ -0,0 +1,28 @@ +#include "blizzard.h" +#include "player.h" +#include "spell.h" +#include +using namespace std; + +Blizzard::Blizzard(Player *owner): Spell("Blizzard","Spell","Deal 2 damages to all minions",3,owner){} + +Blizzard::~Blizzard(){} + + +void Blizzard::activate(shared_ptr target){} + +void Blizzard::activate() { + if (owner->getMinion().size() >0){ + // cout << " bigger than 0 " << endl; + for (int i = 0; i< owner->getMinion().size(); ++i) { + // cout << "go in active loop" << endl; + owner->getMinion().at(i)->beAttacked(2); + + } } + if (owner->getBoard()->getInactive()->getMinion().size() >0){ + for (int i=0; igetBoard()->getInactive()->getMinion().size(); ++i) { +// cout << "inactive loop" << endl; + owner->getBoard()->getInactive()->getMinion().at(i)->beAttacked(2); + } } + // cout << "done for blizzard" << endl; +} diff --git a/blizzard.h b/blizzard.h new file mode 100644 index 0000000..25f01e8 --- /dev/null +++ b/blizzard.h @@ -0,0 +1,14 @@ +#ifndef BLIZZARD_H +#define BLIZZARD_H +#include "spell.h" +#include "card.h" + +class Blizzard: public Spell{ +public: + Blizzard(Player *owner); + ~Blizzard(); + void activate(std::shared_ptr) override; + void activate() override; +}; + +#endif diff --git a/board.cc b/board.cc new file mode 100644 index 0000000..8a14c0b --- /dev/null +++ b/board.cc @@ -0,0 +1,74 @@ +#include "board.h" +#include "card.h" +#include "ritual.h" +#include "minion.h" +#include "player.h" +#include +#include +using namespace std; + + +Board:: Board(): state{"None"},active{nullptr},inactive{nullptr}{} + +Board:: ~Board() { + +} + + void Board::notifyObservers(const string event){ + if (active->minionSize() > 0) { + for (auto n: active->getMinion()) { + n->notify(event); + } +} + if (inactive->minionSize() >0) { + for (auto n: inactive->getMinion()) { + n->notify(event); + } +} + if (active->getRitual()) { + active->getRitual()->notify(event);} + if (inactive->getRitual()){ + inactive->getRitual()->notify(event); + } +} + +string Board::getState() { + return state; +} + + +void Board::changeState(const string event) { + //state = event; + notifyObservers(event); +} + +Player *Board::getActive() { + return active; +} + +Player *Board::getInactive() { + return inactive; +} + +void Board::setActPlayer(Player *p) { + active = p; +} + +void Board::setInActPlayer(Player *p) { + inactive = p; +} + +void Board::setActRitual(shared_ptr r) { + active->setRitual(r); +} + +void Board::setInRitual(shared_ptr r) { + inactive->setRitual(r); +} + +void Board::swapTurn() { + swap(active,inactive); +} + + + diff --git a/board.h b/board.h new file mode 100644 index 0000000..775f3b0 --- /dev/null +++ b/board.h @@ -0,0 +1,32 @@ +#ifndef BOARD_H +#define BOARD_H +#include +#include +#include + +class Player; +class Card; +class Ritual; + +class Board { // if a pattern needed + std::string state; // start end turn + minion leave and enter + Player *active; + Player *inactive; + public: + Board(); + ~Board(); + Player *getActive(); + Player *getInactive(); + std::string getState(); + void setActPlayer(Player *p); + void setInActPlayer(Player *p); + void setActRitual(std::shared_ptr r); + void setInRitual(std::shared_ptr r); + + //void display(); // not done + void changeState(const std::string event); // settled string + void notifyObservers(const std::string event); + void swapTurn(); +}; + +#endif diff --git a/bonegolem.cc b/bonegolem.cc new file mode 100644 index 0000000..0cdf56e --- /dev/null +++ b/bonegolem.cc @@ -0,0 +1,19 @@ +#include "bonegolem.h" + +using namespace std; + +BoneGol:: BoneGol(Player *owner): + Minion{"Bone Golem","Minion","Gain +1/+1 whenever a minion leaves play",2,owner,1,3,0}{} + +BoneGol::~BoneGol(){} + +void BoneGol::activate(){} + +void BoneGol::activate(shared_ptr target){} + +void BoneGol::notify(const string event){ + if (event=="leave" && !isSilence) { + setDefence(getDefence()+1); + setAttack(getAttack()+1); + } +} diff --git a/bonegolem.h b/bonegolem.h new file mode 100644 index 0000000..130bd01 --- /dev/null +++ b/bonegolem.h @@ -0,0 +1,17 @@ +#ifndef BONEGOL_H +#define BONEGOL_H +#include "player.h" +#include "card.h" +#include "minion.h" + +class BoneGol : public Minion { + public: + BoneGol(Player *owner); + ~BoneGol(); + void activate() override; + void activate(std::shared_ptr) override; + void notify(const std::string event) override; +}; + + +#endif diff --git a/card.cc b/card.cc new file mode 100644 index 0000000..ead6326 --- /dev/null +++ b/card.cc @@ -0,0 +1,33 @@ +#include "card.h" +#include "player.h" +using namespace std; + +Card:: Card(string name, string type, string des,int cost,Player* p): name{name},type{type},des{des},cost{cost},owner{p}{} + +Card::~Card(){} + +string Card::getName()const{ + return name; +} + +string Card::getType()const{ + return type; +} + +string Card::getDes() const { + return des; +} + +int Card::getCost()const{ + return cost; +} + + +Player *Card::getOwner()const{ + return owner; +} + +void Card::setCost(int i){ + cost = i; +} + diff --git a/card.h b/card.h new file mode 100644 index 0000000..69397df --- /dev/null +++ b/card.h @@ -0,0 +1,56 @@ +#ifndef _CARD_H_ +#define _CARD_H_ +#include +#include +#include + +class Player; + +class Card { +protected: + std::string name; + std::string type; // Minion Spell Ritual Enchantment + std::string des; + int cost; + Player* owner; +public: + Card(std::string name, std::string type, std::string des,int cost, Player* owner); + std::string getName()const; + std::string getType()const; + std::string getDes() const; + int getCost()const; + void setCost(int i); + Player* getOwner()const; + + virtual ~Card(); + virtual void incActPts() = 0; + virtual int getAttack()const = 0; //m + virtual void setAttack(int i) = 0; //m + virtual int getDefence()const = 0; //m + virtual void setDefence(int i) = 0; //m + virtual std::vector> getEnchants() = 0;//m + virtual int getAbCost() = 0; //m + virtual int getRitualCharge()const = 0; //ritual pts + virtual void setRitualCharge(int i) = 0; //r + virtual int getRitualCost() = 0; //r + virtual void setActPts(int i)=0; + virtual int getActPts() const=0; + virtual int getMaxActPts() const = 0; + + virtual void notify(const std::string event)=0; // m+r + virtual void activate(std::shared_ptr target) =0; // spell m + virtual void activate()=0; // spell m + + virtual void inspect() = 0; // + virtual void popEnchant() = 0; //m + virtual void addEnchant(std::shared_ptr c) = 0; //m + virtual void attack(std::shared_ptr c) = 0; //m + virtual void attack(Player *p) = 0;//m + virtual void beAttacked(int i) = 0;//m + virtual void setAbCost(int i) = 0; + virtual void silence() = 0; + + +}; + +#endif diff --git a/darkritual.cc b/darkritual.cc new file mode 100644 index 0000000..f706b6d --- /dev/null +++ b/darkritual.cc @@ -0,0 +1,20 @@ +#include "darkritual.h" +#include +using namespace std; +DarkRitual::DarkRitual(Player *owner): +Ritual{"Dark Ritual","Ritual","At the start of your turn, gain 1 magic",0,owner,5,1}{ +} + +DarkRitual::~DarkRitual() {} + +void DarkRitual::notify(const string event){ + if (charge >= actCost) { + if (event == "start" && owner == owner->getBoard()->getActive()){ + owner->addMagic(1); + charge -= actCost; + } + } + if (charge==0) { + owner->setRitual(nullptr); + } +} diff --git a/darkritual.h b/darkritual.h new file mode 100644 index 0000000..246f637 --- /dev/null +++ b/darkritual.h @@ -0,0 +1,12 @@ +#ifndef DARK_RITUAL_H +#define DARK_RITUAL_H +#include "ritual.h" + +class DarkRitual :public Ritual { + public: + DarkRitual(Player *owner); + ~DarkRitual(); + void notify(const std::string event) override; +}; + +#endif diff --git a/deck.cc b/deck.cc new file mode 100644 index 0000000..0584b23 --- /dev/null +++ b/deck.cc @@ -0,0 +1,117 @@ +#include "deck.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "airelem.h" +#include "earthelem.h" +#include "fireelem.h" +#include "potionsell.h" +#include "apprentice.h" +#include "novice.h" +#include "massum.h" +#include "bonegolem.h" +#include "banish.h" +#include "unsummon.h" +#include "recharge.h" +#include "disenchant.h" +#include "raisedead.h" +#include "blizzard.h" +#include "GiantStre.h" +#include "enrage.h" +#include "haste.h" +#include "MagicFati.h" +#include "Silence.h" +#include "darkritual.h" +#include "auraofpower.h" +#include "standstill.h" +#include "spell.h" +#include "ritual.h" +#include "auraofpower.h" + + +using namespace std; +class Card; + + Deck:: Deck (const string filename,Player *owner): owner{owner}{ + ifstream f{filename}; + string card; + while (getline(f,card)) { + addCard(card); + } + } + + Deck:: ~Deck(){ + + } + + int Deck::decksize() { + return content.size(); + } + + shared_ptr Deck:: popDeck() { + shared_ptr temp = content.back(); + content.pop_back(); + return temp; + } + + void Deck:: shuffle(){ + srand(time(NULL)); // + for(unsigned int i = 0; i < content.size(); ++i){ + unsigned int r = rand() % content.size(); + swap(content[i],content[r]); + } + } + + void Deck:: addCard(const string s) { + if(s == "Air Elemental"){ + content.emplace_back(make_shared(owner)); // new AirElem + }else if(s == "Earth Elemental"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Bone Golem"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Fire Elemental"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Potion Seller"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Novice Pyromancer"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Apprentice Summoner"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Master Summoner"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Banish"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Unsummon"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Recharge"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Disenchant"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Raise Dead"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Blizzard"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Giant Strength"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Enrage"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Haste"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Magic Fatigue"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Silence"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Dark Ritual"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Aura of Power"){ + content.emplace_back(make_shared(owner)); + }else if(s == "Standstill"){ + content.emplace_back(make_shared(owner)); + } +} + diff --git a/deck.h b/deck.h new file mode 100644 index 0000000..79db263 --- /dev/null +++ b/deck.h @@ -0,0 +1,22 @@ +#ifndef DECK_H +#define DECK_H +#include +#include +#include "player.h" + +class Card; +class Player; + +class Deck{ + std::vector> content; + Player *owner; + public: + Deck(const std::string filename,Player *owner); + ~Deck(); + std::shared_ptr popDeck(); + void shuffle(); + void addCard(const std::string card); + int decksize(); +}; + +#endif diff --git a/disenchant.cc b/disenchant.cc new file mode 100644 index 0000000..55d3e4c --- /dev/null +++ b/disenchant.cc @@ -0,0 +1,15 @@ +#include "disenchant.h" +#include + +using namespace std; + +Disenchant::Disenchant(Player *owner):Spell{"Disenchant","Spell","Destroy the top enchantment on target minion",1,owner}{} +Disenchant::~Disenchant(){} +void Disenchant::activate(shared_ptr target){ + if (target->getEnchants().size() > 0){ + cout << "disenchant after if statement" << endl; + target->popEnchant(); + cout << "disenchant after pop" << endl; + } +} +void Disenchant::activate(){} diff --git a/disenchant.h b/disenchant.h new file mode 100644 index 0000000..894e2e7 --- /dev/null +++ b/disenchant.h @@ -0,0 +1,14 @@ +#ifndef DISENCHANT_H +#define DISENCHANT_H +#include "spell.h" +#include "card.h" + +class Disenchant: public Spell{ +public: + Disenchant(Player *owner); + ~Disenchant(); + void activate(std::shared_ptr) override; + void activate() override; +}; + +#endif diff --git a/earthelem.cc b/earthelem.cc new file mode 100644 index 0000000..7de9d5e --- /dev/null +++ b/earthelem.cc @@ -0,0 +1,14 @@ +#include "earthelem.h" + +using namespace std; + +EarthElem:: EarthElem(Player *owner): + Minion{"Earth Elemental","Minion","",3,owner,4,4,0}{} + +EarthElem::~EarthElem(){} + +void EarthElem::activate(){} + +void EarthElem::activate(shared_ptr target){} + +void EarthElem::notify(const string event){} diff --git a/earthelem.h b/earthelem.h new file mode 100644 index 0000000..e9b715a --- /dev/null +++ b/earthelem.h @@ -0,0 +1,17 @@ +#ifndef EARTHELEM_H +#define EARTHELEM_H +#include "player.h" +#include "card.h" +#include "minion.h" + +class EarthElem : public Minion { + public: + EarthElem(Player *owner); + ~EarthElem(); + void activate() override; + void activate(std::shared_ptr) override; + void notify(const std::string event) override; +}; + + +#endif diff --git a/enchantment.cc b/enchantment.cc new file mode 100644 index 0000000..e6d45af --- /dev/null +++ b/enchantment.cc @@ -0,0 +1,55 @@ +#include "enchantment.h" + +using namespace std; + +Enchantment::Enchantment(string name,string type, string des, int cost, Player *owner, int atk, int def): Card{name,type,des,cost,owner}, atk{atk}, def{def} {} + +Enchantment::~Enchantment() {} + +int Enchantment::getAttack()const { + return atk; +} + +void Enchantment::incActPts() {} + +void Enchantment::setAttack(int i) {} + +void Enchantment::attack(shared_ptr c) {} + +void Enchantment::attack(Player *p) {}; + +void Enchantment::beAttacked(int i) {}; + +int Enchantment::getDefence()const { + return def; +} + +void Enchantment::inspect() { +//need to do +} + +void Enchantment::notify(const string event) {} + +int Enchantment::getRitualCharge()const { return 0; } + +void Enchantment::setRitualCharge(int i) {} + +void Enchantment::popEnchant() {} + +void Enchantment::setDefence(int i) {} + +void Enchantment::addEnchant(shared_ptr c) {} + +int Enchantment::getRitualCost() { return 0; } + +vector> Enchantment::getEnchants() {} + +int Enchantment::getAbCost() { return 0; } + +void Enchantment::activate() {} + + void Enchantment::setActPts(int i){} + int Enchantment::getActPts() const{return 0;} + int Enchantment::getMaxActPts()const {return 0;} + void Enchantment::setAbCost(int i) {} + void Enchantment::silence() {} diff --git a/enchantment.h b/enchantment.h new file mode 100644 index 0000000..853b0cd --- /dev/null +++ b/enchantment.h @@ -0,0 +1,43 @@ +#ifndef ENCHANTMENT_H +#define ENCHANTMENT_H +#include +#include +#include +#include "minion.h" +#include "card.h" + +class Player; + +class Enchantment : public Card { + int atk, def; +public: + Enchantment(std::string name, std::string type, std::string des, int cost, Player *owner, int atk, int def); + ~Enchantment(); + void notify(const std::string event) override; + int getAttack()const override; + void setAttack(int i) override; + void attack(std::shared_ptr c) override; + void attack(Player *p) override; + void beAttacked(int i) override; + int getDefence()const override; + void inspect() override; + int getRitualCharge()const override; + void setRitualCharge(int i) override; + void popEnchant() override; + void setDefence(int i) override; + void addEnchant(std::shared_ptr c) override; + int getRitualCost() override; + std::vector> getEnchants() override; + int getAbCost() override; + void activate(std::shared_ptr target) = 0; //about ability + void activate() override; + virtual void deactivate(std::shared_ptr target) = 0; + void setActPts(int i); + int getActPts() const; + int getMaxActPts()const override; + void setAbCost(int i) override; + void incActPts() override; + void silence() override; +}; + +#endif // !ENCHANTMENT_H diff --git a/enrage.cc b/enrage.cc new file mode 100644 index 0000000..9416de0 --- /dev/null +++ b/enrage.cc @@ -0,0 +1,22 @@ +#include "enrage.h" +#include +using namespace std; + +Enrage::Enrage(Player *owner): Enchantment { "Enrage", "Enchantment", "", 2, owner, 2, 2 } {} + +Enrage::~Enrage() {} + +void Enrage::activate(shared_ptr c) { + cout << "Using Enrage" << endl; + int atk = c->getAttack(); + int def = c->getDefence(); + c->setAttack(atk * 2); + c->setDefence(def * 2); +} + +void Enrage::deactivate(shared_ptr c) { + int atk = c->getAttack(); + int def = c->getDefence(); + c->setAttack(atk / 2); + c->setDefence(def / 2); +} diff --git a/enrage.h b/enrage.h new file mode 100644 index 0000000..e6eeccc --- /dev/null +++ b/enrage.h @@ -0,0 +1,12 @@ +#ifndef ENRAGE_H +#define ENRAGE_H +#include "enchantment.h" + +class Enrage : public Enchantment { +public: + Enrage(Player *owner); + ~Enrage(); + void activate(std::shared_ptr c) override; + void deactivate(std::shared_ptr c) override; +}; +#endif diff --git a/fireelem.cc b/fireelem.cc new file mode 100644 index 0000000..f869294 --- /dev/null +++ b/fireelem.cc @@ -0,0 +1,18 @@ +#include "fireelem.h" +#include +using namespace std; + +FireElem:: FireElem(Player *owner): + Minion{"Fire Elemental","Minion","Whenever an opponent's minion enters play, deal 1 damage to it",2,owner,2,2,0}{} + +FireElem::~FireElem(){} + +void FireElem::activate(){} + +void FireElem::activate(shared_ptr target){} + +void FireElem::notify(const string event){ + if (event=="enter"&& !isSilence && owner != owner->getBoard()->getActive()) { + owner->getBoard()->getActive()->getMinion().back()->beAttacked(1); + } +} diff --git a/fireelem.h b/fireelem.h new file mode 100644 index 0000000..fdc2cfc --- /dev/null +++ b/fireelem.h @@ -0,0 +1,17 @@ +#ifndef FIREELEM_H +#define FIREELEM_H +#include "player.h" +#include "card.h" +#include "minion.h" + +class FireElem : public Minion { + public: + FireElem(Player *owner); + ~FireElem(); + void activate() override; + void activate(std::shared_ptr) override; + void notify(const std::string event) override; +}; + + +#endif diff --git a/haste.cc b/haste.cc new file mode 100644 index 0000000..ac8ceb2 --- /dev/null +++ b/haste.cc @@ -0,0 +1,18 @@ +#include "haste.h" +#include + +using namespace std; + +Haste::Haste(Player *owner): Enchantment{ "Haste", "Enchantment", "Enchanted minion gains +1 action each turn", 1, owner, 0, 0 } {} + +Haste::~Haste(){} + +void Haste::activate(shared_ptr c) { + int points = c->getMaxActPts() + 1; + c->setActPts(points); +} + +void Haste::deactivate(shared_ptr c) { + int points = c->getMaxActPts() - 1; + c->setActPts(points); +} diff --git a/haste.h b/haste.h new file mode 100644 index 0000000..64d28b7 --- /dev/null +++ b/haste.h @@ -0,0 +1,12 @@ +#ifndef HASTE_H +#define HASTE_H +#include "enchantment.h" + +class Haste :public Enchantment { +public: + Haste(Player *owner); + ~Haste(); + void activate(std::shared_ptr c) override; + void deactivate(std::shared_ptr c) override; +}; +#endif // !HASTE_H diff --git a/main.cc b/main.cc new file mode 100644 index 0000000..972e338 --- /dev/null +++ b/main.cc @@ -0,0 +1,249 @@ +#include +#include +#include +#include +#include +#include "player.h" +#include "textdisplay.h" +#include "board.h" +#include "card.h" +#include +using namespace std; + +int main(int argc, char* argv[]) { + Player p1; + Player p2; + Board b; + string mode; //What mode? + string display; //what display? + TextDisplay t; + ifstream f; + const string helpmsg = "Commands: help -- Display this message.\n"" " + "end -- End the current player's turn.\n"" ""quit -- End the game.\n"" " + "attack minion other-minion -- Orders minion to attack other-minion.\n"" " + "attack minion -- Orders minion to attack the opponent.\n"" " + "play card [target-player target-card] -- Play card, optionally targeting target-card owned by target-player.\n" + " " + "use minion [target-player target-card] -- Use minion's special ability, optionally targeting target-card owned by target-player.\n" + " " + "inspect minion -- View a minion's card and all enchantments on that minion.\n"" " + "hand -- Describe all cards in your hand.\n"" " + "board -- Describe all cards on the board."; + bool init = false; + b.setActPlayer(&p1); + b.setInActPlayer(&p2); + Player *activePlayer = b.getActive(); + Player *inactivePlayer = b.getInactive(); + p1.setdeck("default.deck"); + p2.setdeck("default.deck"); + p1.setBoard(&b); + p2.setBoard(&b); + p2.setMaxMagic(2); + for (int i = 1; i < argc; ++i) { + string temp = argv[i]; + if (temp == "-deck1") { + ++i; + string temp2 = argv[i]; + p1.setdeck(temp2); + } + else if (temp == "-deck2") { + ++i; + string temp3 = argv[i]; + p2.setdeck(temp3); + } + else if (temp == "-init") { + ++i; + string temp2 = argv[i]; + f.open(temp2); + //read command from file + init = true; + } + else if (temp == "-testing") { + mode = "t"; + } + else if (temp == "-graphics") { + display = "g"; + } + } + + if (mode != "t") { //shuffle + p1.shuffleDeck(); + p2.shuffleDeck(); + p2.shuffleDeck(); + } + + + for (int i = 0; i < 5; ++i) { + p1.draw(); + } + + for (int i = 0; i < 5; ++i) {//should be 5 + p2.draw(); + } + + + string name1; + string name2; //Player names + if (init) { + + getline(f,name1); + p1.setName(name1); + getline(f,name2); + p2.setName(name2); + } + else { + cout << "Player1 please enter your name:" << endl; + getline(cin,name1); + p1.setName(name1); + cout << "Player2 please enter your name:" << endl; + getline(cin,name2); + p2.setName(name2); + } + + + + //game loop + string cmd; + string line; //the whole line + while (true) { + if (init) { + getline(f,line); + if (!f.good()) { + init = false; + } + } + if (!init) { + getline(cin,line); + if (!cin.good()) { + break; + } + } + stringstream ss{ line }; + ss >> cmd; + + if (cmd == "help") { + cout << helpmsg << endl; + } + else if (cmd == "end") { + activePlayer->endTurn(); + inactivePlayer->startTurn(); + b.swapTurn(); + swap(activePlayer,inactivePlayer); + } + else if (cmd == "draw" && mode == "t") { + activePlayer->draw(); + } + else if (cmd == "discard" && mode == "t") { + int index; + ss >> index; + --index; + if (index < activePlayer->getHand().size()){ + activePlayer->discard(index); + } else { + cout << "Invalid hand card index! " << endl; + } + } + else if (cmd == "attack") { + int i; //active player index + ss >> i; + --i; + int j; //inactive player index + if (!(ss >> j)) { + if (activePlayer->getMinion().size() > i){ + activePlayer->getMinion()[i]->attack(inactivePlayer);} + else { + cout << "Invalid index! Please try again!" << endl; + } //Player::attack face + } else { + --j; + activePlayer->attack(i, j); + } + } + else if (cmd == "play") { + int i; //active player index + ss >> i; + int p; //which player + --i; + if (!(ss >> p)) { + activePlayer->play(i); //just play it + } + else { + int j; //inactive player index + ss >> j; + --j; + if (p==1) { + if(j < p1.getMinion().size()) { + activePlayer->play(i,p1.getMinion().at(j)); + } + else { + cout << "Invalid hand card index" << endl; + } + } + else { + if (p2.getMinion().size() > j){ + activePlayer->play(i,p2.getMinion().at(j)); + } else { + cout << "Invalid hand card index" << endl; + } + } + } + } + else if (cmd == "use") { + int i; //active player index + ss >> i; + int p; + --i; + if (!(ss >> p)) { + activePlayer->useActive(i); //use activated ability on no target + } + else { + int j; + ss >> j; + --j; + if (p==1){ + if (juseActive(i,p1.getMinion().at(j)); + } else { + cout << "Invalid hand card index!" << endl; + } + } + else { + if (juseActive(i,p2.getMinion().at(j));} + else { + cout << "Invalid hand card index!" << endl; + } + } + } + } + else if (cmd == "inspect") { + int i; + ss >> i; + --i; + if (igetMinion().size()) { + shared_ptr temp = activePlayer->getMinion().at(i); + t.inspectMinion(temp); + } else { + cout << "Invalid hand card index!" << endl; + } + } + else if (cmd == "hand") { + t.displayHand(activePlayer); + } + else if (cmd == "board") { + t.displayBoard(&b); + } + else { + cout << "invalid command" << endl; + } + + if (p1.isDead()) { + cout << "Game Over! Player 2 wins!!" << endl; + break; + } + if (p2.isDead()) { + cout << "Game Over! Player 1 wins!!" << endl; + break; + } + } +} diff --git a/massum.cc b/massum.cc new file mode 100644 index 0000000..5496f5f --- /dev/null +++ b/massum.cc @@ -0,0 +1,27 @@ +#include "massum.h" +#include "airelem.h" + +using namespace std; + +MasSum:: MasSum(Player *owner): + Minion{"Master Summoner","Minion","Summon up to three 1/1 air elementals",3,owner,2,3,2}{} + +MasSum::~MasSum(){} + +void MasSum::activate(){ + if (actionpts > 0 && !isSilence) { + int i = 0; + if (owner->getMagic() >= abCost && owner->getMinion().size() < 5) { + while (owner->getMinion().size() < 5 && i < 3) { + owner->getMinion().push_back(make_shared(owner)); + owner->subMagic(abCost); + ++i; + } + } + --actionpts; + } +} + +void MasSum::activate(shared_ptr target){} + +void MasSum::notify(const string event){} diff --git a/massum.h b/massum.h new file mode 100644 index 0000000..7ce4a22 --- /dev/null +++ b/massum.h @@ -0,0 +1,17 @@ +#ifndef MASSSUM_H +#define MASSUM_H +#include "player.h" +#include "card.h" +#include "minion.h" + +class MasSum : public Minion { + public: + MasSum(Player *owner); + ~MasSum(); + void activate() override; + void activate(std::shared_ptr) override; + void notify(const std::string event) override; +}; + + +#endif diff --git a/minion.cc b/minion.cc new file mode 100644 index 0000000..e631aef --- /dev/null +++ b/minion.cc @@ -0,0 +1,103 @@ +#include "minion.h" +#include +#include "player.h" +#include + + +using namespace std; + +Minion::Minion(string name, string type, string des, int cost, Player* owner, int Attack, int defense, int abCost): Card{name,type,des,cost,owner},Attack{Attack}, defense{defense}, originalAtk{Attack}, originalDef{defense}, abCost{abCost} {} + +Minion::~Minion() {} + +int Minion::getAttack() const { return Attack; } + +void Minion::setAttack(int i) { Attack = i; } + +void Minion::attack(shared_ptr c) { + if (actionpts > 0) { + c->beAttacked(Attack); + this->beAttacked(c->getAttack()); + --actionpts; + } else { + cout << "Not enought Action Pts" << endl; + } +} + +void Minion::attack(Player *p) { + if (actionpts > 0) { + p->beAttacked(Attack); + --actionpts; + } else { + cout << "Not enought Action Pts" << endl; + + } +} + +void Minion::beAttacked(int i) { + defense -= i; + if (defense <= 0) { + owner->goToGrave(shared_from_this()); + } +} + + +int Minion::getDefence() const { return defense; } + +void Minion::inspect() {} + +int Minion::getRitualCharge()const {} + +void Minion::setRitualCharge(int i) {} + +void Minion::popEnchant() { + int size = buffs.size() - 1; + auto m = dynamic_pointer_cast(buffs[size]); + m -> deactivate(shared_from_this()); + buffs.pop_back(); +} + +void Minion::setDefence(int i) { defense = i; } + +void Minion::addEnchant(shared_ptr target) { + buffs.emplace_back(target); + auto m = dynamic_pointer_cast(target); + m->activate(shared_from_this()); +} + + +int Minion::getRitualCost() +{ + return 0; +} + +vector> Minion::getEnchants() { return buffs; } + +int Minion::getAbCost() { return abCost; } + +void Minion::setActPts(int i) +{ + maxactpts = i; +} + +void Minion::incActPts() { + ++actionpts; +} + +int Minion::getActPts() const { + return actionpts; +} + +int Minion::getMaxActPts() const { + return maxactpts; +} + +void Minion::silence() +{ + isSilence = true; +} + +void Minion::setAbCost(int i) +{ + abCost = i; +} diff --git a/minion.h b/minion.h new file mode 100644 index 0000000..9da2198 --- /dev/null +++ b/minion.h @@ -0,0 +1,46 @@ +#ifndef MINION_H +#define MINION_H +#include +#include +#include +#include "card.h" +#include "enchantment.h" + +class Minion : public Card, public std::enable_shared_from_this { + int Attack, defense, originalAtk, originalDef; + std::vector> buffs; +protected: + int actionpts = 1; + int maxactpts = 1; + int abCost; + bool isSilence = false; +public: + Minion(std::string name, std::string type, std::string des,int cost, Player *owner, int Attack, int defense, int abCost); + ~Minion(); + void incActPts() override; + int getAttack()const override; + void setAttack(int i) override; + void attack(std::shared_ptr c) override; + void attack(Player *p) override; + void beAttacked(int i) override; + int getDefence()const override; + void inspect() override; + int getRitualCharge()const override; + void setRitualCharge(int i) override; + void popEnchant() override; + void setDefence(int i) override; + void addEnchant(std::shared_ptr c) override; + int getRitualCost() override; + std::vector> getEnchants() override; + int getAbCost() override; + virtual void activate(std::shared_ptr target)=0; //about ability + virtual void activate()=0; + virtual void notify(const std::string event)=0; + void setActPts(int i) override; + int getActPts() const override; + int getMaxActPts()const override; + void silence() override; + void setAbCost(int i) override; + +}; +#endif // !MINION_H diff --git a/novice.cc b/novice.cc new file mode 100644 index 0000000..b4297f2 --- /dev/null +++ b/novice.cc @@ -0,0 +1,22 @@ +#include "novice.h" + +using namespace std; + + +NovicePyro:: NovicePyro(Player *owner): + Minion{"Novice Pyromancer","Minion","Deal 1 damage to target minion",1,owner,0,1,1}{} + +NovicePyro::~NovicePyro(){} + +void NovicePyro::activate(){} + +void NovicePyro::activate(shared_ptr target){ + if (actionpts <= 0) return; + if (!isSilence){ + --actionpts; + target->beAttacked(1); + owner->subMagic(1); +} +} + +void NovicePyro::notify(const string event){} diff --git a/novice.h b/novice.h new file mode 100644 index 0000000..88f30d6 --- /dev/null +++ b/novice.h @@ -0,0 +1,17 @@ +#ifndef NOVICE_H +#define NOVICE_H +#include "player.h" +#include "card.h" +#include "minion.h" + +class NovicePyro : public Minion { + public: + NovicePyro(Player *owner); + ~NovicePyro(); + void activate() override; + void activate(std::shared_ptr) override; + void notify(const std::string event) override; +}; + + +#endif diff --git a/player.cc b/player.cc new file mode 100644 index 0000000..b73e784 --- /dev/null +++ b/player.cc @@ -0,0 +1,244 @@ +#include "player.h" +#include +#include +#include +#include +#include +#include +#include "card.h" +#include "minion.h" +#include "enchantment.h" +#include "ritual.h" +#include "spell.h" +#include "ascii_graphics.h" + +using namespace std; + +Player:: Player() : deck{nullptr},board{nullptr} +{ +} + +void Player:: setMaxMagic(int i) { + maxMagic = i; +} + +void Player:: setName(string name) { + this->name = name; +} + +string Player:: getName() +{return name;} + +Player:: ~Player(){ +} + +void Player::addHealth(int i) { + health += i; +} + +void Player::addMaxMagic(int i) { + maxMagic += i; +} + +void Player::addMagic(int i) { + magic += i; +} + +void Player::subMagic(int i) { + magic -=i; +} // if already 0? + +Board * Player::getBoard(){ + return board; +} + +void Player::setBoard(Board *b) { + board = b; +} + +void Player::draw(){ // to see if hand is full + if (!isHandFull()){ + if (deck->decksize() == 0) { + cout << "Your deck has no cards left" << endl; + } else { + hand.emplace_back(deck->popDeck()); //draw a card from deck(top) to hand + } + } else { + cout << "your hand is too full" << endl; + } +} + +void Player::play(int i) { + if (i < hand.size()){ + int charge = hand.at(i)->getCost(); + if (magic >= charge) { // check if enough magic + magic -= charge; + string type = hand.at(i)->getType(); + if (type == "Minion") { + minion.emplace_back(hand.at(i)); + board->changeState("enter"); + } else if (type == "Ritual") { + r = hand.at(i); + } else{ // spell with no target + hand.at(i)->activate(); + } + hand.erase(hand.begin()+i); + } + else { + cout << "Sorry! You do not have enough magic value!" << endl; + } + } else { + cout << "Invalid hand card index!" << endl; + } +} + +void Player::play(int i, shared_ptr target) { // in board, transform t to a card ptr + if (igetCost(); + if (magic >= charge) { + magic -= charge; + string type=hand.at(i)->getType(); + cout << type << endl; + if (type == "Enchantment") { + target->addEnchant(hand[i]); //minion->add(Enchant); + } else { + hand.at(i)->activate(target); // spell with a target + } + hand.erase(hand.begin()+i); + } else { + cout << "Sorry! You do not have enough Magic Value! " << endl; + } + } else { + cout << "Invalid hand card index" << endl; + } +} + +vector> &Player::getGraveyard(){ + return graveyard; +} + + +vector> &Player::getMinion(){ + return minion; +} + +bool Player:: isHandFull() { + int num = hand.size(); + return (num==5); +} + +void Player:: discard(int i){ // memory leak? + hand.erase(hand.begin()+i); +} + +void Player:: setdeck(const std::string filename){//setdeck input:deck.default + deck = make_shared(filename,this); //OK +} + +void Player:: beAttacked(int i){ + health -=i; // if dead +} + +void Player:: attack(int i, Player *p) { + minion.at(i)->attack(p); +} + +void Player:: attack (int i, int j) { + if (i < minion.size() && getBoard()->getInactive()->getMinion().size() > j ){ + minion.at(i)->attack(this->getBoard()->getInactive()->getMinion().at(j)); + } + else {cout << "Invalid index! Please try again!" << endl;} +} + +void Player:: shuffleDeck(){ + deck->shuffle(); //OK +} + +std::vector> &Player:: getHand(){ + return hand; +} + +void Player::endTurn() { + board->changeState("end"); +} + +void Player::startTurn() { //draw OK + ++maxMagic; + magic = maxMagic; + draw(); + board->changeState("start"); + for (auto n: minion) { + int newmax = n->getMaxActPts(); + n->setActPts(newmax); + while (n->getActPts() < newmax) { + n->incActPts(); + } + } +} + + +bool Player::isDead() { + return (health<=0); +} + +void Player::goToGrave(std::shared_ptr card) { + // shared_ptr card= static_cast>(c); + int enchantSize = card->getEnchants().size(); + if(enchantSize > 0){ + for(int i = 0; i < enchantSize; ++i){ + card->popEnchant(); + } + } + for(int i = 0; i < minion.size(); ++i){ + if(minion[i] == card){ + minion.erase(minion.begin()+i); + break; + } + } + graveyard.emplace_back(card); + board->changeState("leave"); +} + +int Player::getMagic() {return magic;} + +void Player::returnCard(std::shared_ptr card){ + if (hand.size()<5) { + int i =0; + for (auto n:minion) { + if (n==card) { + minion.erase(minion.begin()+i); + break; + } + ++i; + } + hand.emplace_back(card); + board->changeState("leave"); + } else { + goToGrave(card); + } +} + +std::shared_ptr Player::getRitual() {return r;} + +void Player::setRitual(std::shared_ptr r) {r=r;} + +void Player::useActive(int i){ + if (i < minion.size()) { + minion.at(i)->activate();} + else { cout << "Invalid index! " << endl; + } +} + +void Player::useActive(int i, shared_ptr target){ + if (i < minion.size()){ + minion.at(i)->activate(target);} + else { cout << "Invalid index!" << endl; + } +} + +int Player::getHealth() {return health;} + + +int Player:: minionSize() { + return minion.size(); +} diff --git a/player.h b/player.h new file mode 100644 index 0000000..2f9fa70 --- /dev/null +++ b/player.h @@ -0,0 +1,70 @@ +#ifndef PLAYER_H +#define PLAYER_H +#include +#include +#include +#include "deck.h" +#include "board.h" + + +class Card; +class Ritual; +class Minion; +class Enchantment; +class Deck; + + +class Player final { + std::string name; + std::vector> hand; + std::shared_ptr deck; + int health=20; + int magic=3; + int maxMagic=3; + Board *board; // has a board ptr + std::vector> graveyard; //on board + std::vector> minion; //on board + std::shared_ptr r; //ritual + public: + Player(); + ~Player(); + void addHealth(int i); + void addMagic(int i); + void subMagic(int i); + void addMaxMagic(int i); + int getMagic(); + int getHealth(); + void setBoard(Board *b); + std::vector> &getHand(); + void setName(std::string name); + std::string getName(); + Board *getBoard(); + std::shared_ptr getRitual(); + std::vector> &getGraveyard(); + std::vector> &getMinion(); + void setdeck(const std::string filename); //setdeck input:deck.default + void setRitual(std::shared_ptr r); + int minionSize(); + void setMaxMagic(int i); + // end of setter and getter + + void shuffleDeck(); //ok + void play(int i); + void play(int i, std::shared_ptr target); // with target + void draw(); //done + void discard(int i); + void beAttacked(int i); + bool isHandFull(); + void attack(int i, Player *p); + void attack(int i, int j); + void endTurn(); + void startTurn(); + bool isDead(); + void goToGrave(std::shared_ptr card); + void returnCard(std::shared_ptr card); + void useActive(int i); + void useActive(int i, std::shared_ptr target); + void inspect(int i); +}; + +#endif diff --git a/potionsell.cc b/potionsell.cc new file mode 100644 index 0000000..2ab57a2 --- /dev/null +++ b/potionsell.cc @@ -0,0 +1,21 @@ +#include "potionsell.h" + +using namespace std; + +PotionSell:: PotionSell(Player *owner): + Minion{"Potion Seller","Minion","At the end of your turn, all your minions gain +0/+1",2,owner,1,3,0}{} + +PotionSell::~PotionSell(){} + +void PotionSell::activate(){} + +void PotionSell::activate(shared_ptr target){} + +void PotionSell::notify(const string event){ + if (event == "end" && !isSilence && owner== owner->getBoard()->getActive()) { + for (auto n:owner->getMinion()){ + int cur = n->getDefence(); + n->setDefence(cur+1); + } + } +} diff --git a/potionsell.h b/potionsell.h new file mode 100644 index 0000000..557e12f --- /dev/null +++ b/potionsell.h @@ -0,0 +1,17 @@ +#ifndef POTIONSELL_H +#define POTIONSELL_H +#include "player.h" +#include "card.h" +#include "minion.h" + +class PotionSell : public Minion { + public: + PotionSell(Player *owner); + ~PotionSell(); + void activate() override; + void activate(std::shared_ptr) override; + void notify(const std::string event) override; +}; + + +#endif diff --git a/raisedead.cc b/raisedead.cc new file mode 100644 index 0000000..ee04536 --- /dev/null +++ b/raisedead.cc @@ -0,0 +1,15 @@ +#include "raisedead.h" + +using namespace std; + +Raisedead::Raisedead(Player *owner):Spell{"Raisedead","Spell","Resurrect the top minion in your graveyarda nd set its defence to 1",1,owner}{} +Raisedead::~Raisedead(){} +void Raisedead::activate(shared_ptr target){} +void Raisedead::activate(){ + if (owner->getGraveyard().size() > 0) { + owner->getMinion().emplace_back(owner->getGraveyard().back()); + owner->getGraveyard().pop_back(); + owner->getMinion().back()->setDefence(1); + owner->getBoard()->changeState("enter"); + } +} diff --git a/raisedead.h b/raisedead.h new file mode 100644 index 0000000..2839844 --- /dev/null +++ b/raisedead.h @@ -0,0 +1,14 @@ +#ifndef RAISEDEAD_H +#define RAISEDEAD_H +#include "spell.h" +#include "card.h" + +class Raisedead: public Spell{ +public: + Raisedead(Player *owner); + ~Raisedead(); + void activate(std::shared_ptr) override; + void activate() override; +}; + +#endif diff --git a/recharge.cc b/recharge.cc new file mode 100644 index 0000000..2a11c03 --- /dev/null +++ b/recharge.cc @@ -0,0 +1,18 @@ +#include "recharge.h" +#include "card.h" +#include "player.h" + +using namespace std; + +Recharge::Recharge(Player *owner):Spell{"Recharge","Spell","Your ritual gains 3 charges",1,owner}{} + +Recharge::~Recharge(){} + +void Recharge::activate(shared_ptr c){} + +void Recharge::activate() { + if (owner->getRitual()){ + int cur=owner->getRitual()->getRitualCharge(); + owner->getRitual()->setRitualCharge(cur+3); + } +} diff --git a/recharge.h b/recharge.h new file mode 100644 index 0000000..d3ad8ce --- /dev/null +++ b/recharge.h @@ -0,0 +1,14 @@ +#ifndef RECHARGE_H +#define RECHARGE_H +#include "spell.h" +#include "card.h" + +class Recharge: public Spell{ +public: + Recharge(Player *owner); + ~Recharge(); + void activate(std::shared_ptr) override; + void activate() override; +}; + +#endif diff --git a/ritual.cc b/ritual.cc new file mode 100644 index 0000000..82fe40e --- /dev/null +++ b/ritual.cc @@ -0,0 +1,33 @@ +#include "ritual.h" +#include +#include "player.h" +#include "card.h" +Ritual:: Ritual(std::string name, std::string type, std::string des, int cost, Player *owner,int charge, int actCost): +Card{name,type,des,cost,owner},charge{charge},actCost{actCost}{} + +Ritual:: ~Ritual(){} +int Ritual::getMaxActPts() const {return 0;} +int Ritual::getAttack()const {return 0;} +void Ritual::setAttack(int i){} +int Ritual::getDefence()const {return 0;} +void Ritual::setDefence(int i){} +void Ritual::popEnchant(){} +void Ritual::addEnchant(std::shared_ptr c){} +std::vector> Ritual::getEnchants(){} +int Ritual:: getAbCost(){return 0;} +void Ritual::attack(std::shared_ptr c){} +void Ritual::attack(Player *p){} +void Ritual::beAttacked(int i){} +void Ritual:: activate(std::shared_ptr target) {} +void Ritual:: activate() {} +void Ritual:: inspect(){} +int Ritual::getRitualCharge()const { + return charge; +} +void Ritual::setRitualCharge(int i) {charge =i;} +int Ritual::getRitualCost(){return actCost;} +void Ritual:: setActPts(int i){} +void Ritual:: setAbCost(int i){} +void Ritual::silence(){} +int Ritual:: getActPts() const {return 0;} +void Ritual::incActPts() {} diff --git a/ritual.h b/ritual.h new file mode 100644 index 0000000..4b3e14a --- /dev/null +++ b/ritual.h @@ -0,0 +1,39 @@ +#ifndef RITUAL_H +#define RITUAL_H +#include +#include "player.h" +#include "card.h" +class Ritual : public Card { + protected: + int charge; // life + int actCost; + public: + Ritual(std::string name, std::string type, std::string des, int cost, Player *owner,int charges, int actCost); + virtual~Ritual(); + int getAttack()const override; + void setAttack(int i)override; + int getDefence()const override; + void setDefence(int i)override; + int getAbCost() override; + std::vector> getEnchants() override; + void inspect() override; + void popEnchant()override; + void addEnchant(std::shared_ptr c)override; + void attack(std::shared_ptr c)override; + void attack(Player *p)override; + void beAttacked(int i)override; + void activate(std::shared_ptr target);// spell or active ability + void activate();// ab + void setAbCost(int i) override; + void setActPts(int i) override; + int getActPts() const override; + void silence() override; + int getMaxActPts() const override; + int getRitualCost()override; + int getRitualCharge()const override; + void setRitualCharge(int i)override; + virtual void notify(const std::string event)=0; + void incActPts() override; +}; + +#endif diff --git a/spell.cc b/spell.cc new file mode 100644 index 0000000..54659ae --- /dev/null +++ b/spell.cc @@ -0,0 +1,30 @@ +#include "spell.h" + +Spell:: ~Spell(){} + +Spell:: Spell(std::string name, std::string type, std:: string des, int cost, Player *owner): Card{name,type,des,cost,owner}{} + + +void Spell:: setAttack(int i){} +int Spell:: getAttack()const {return 0;} +void Spell:: attack(std::shared_ptr c){} +void Spell::attack(Player *p){} +void Spell::beAttacked(int i){} + +void Spell:: incActPts() {} +int Spell::getDefence()const {return 0;} +void Spell::setDefence(int i){} +int Spell::getRitualCharge()const {return 0;} +void Spell::setRitualCharge(int i){} +void Spell::popEnchant(){} +void Spell::addEnchant(std::shared_ptr c){} +int Spell::getRitualCost(){return 0;} +std::vector> Spell::getEnchants(){} +int Spell::getAbCost(){return 0;} +void Spell:: notify(const std::string event) {} +void Spell:: inspect() {} +void Spell:: setAbCost(int i) {} +void Spell:: setActPts(int i){} +void Spell:: silence(){} +int Spell:: getActPts() const{return 0;} +int Spell:: getMaxActPts() const {return 0;} diff --git a/spell.h b/spell.h new file mode 100644 index 0000000..2b9990e --- /dev/null +++ b/spell.h @@ -0,0 +1,40 @@ +#ifndef SPELL_H +#define SPELL_H +#include "card.h" +#include "player.h" + +class Player; + + +class Spell: public Card { + public: + Spell(std::string name, std::string type, std::string des, int cost, Player *owner); + void incActPts() override; + int getAttack()const override;// + void setAttack(int i)override;// + int getDefence()const override; // + void setDefence(int i)override; + std::vector> getEnchants() override; + int getRitualCharge()const override; + void setRitualCharge(int i)override; + int getAbCost() override; + int getRitualCost()override; + void inspect() override; + void setAbCost(int i) override; + void attack(std::shared_ptr c)override;// + void attack(Player *p)override;// + void beAttacked(int i)override;// + void popEnchant()override; + void addEnchant(std::shared_ptr c)override; + void notify(const std::string event) override; + void silence() override; + virtual ~Spell(); + void setActPts(int i); + int getActPts() const; + int getMaxActPts()const override; + virtual void activate(std::shared_ptr)=0; + virtual void activate()=0; +}; + + +#endif diff --git a/standstill.cc b/standstill.cc new file mode 100644 index 0000000..763080e --- /dev/null +++ b/standstill.cc @@ -0,0 +1,21 @@ +#include "standstill.h" +#include +using namespace std; +StandStill::StandStill(Player *owner): +Ritual{"Stansdtill","Ritual","Whenever a minion enters play, desdroy it",3,owner,4,2}{} + +StandStill::~StandStill(){} + +void StandStill::notify(const string event){ + if (actCost <= charge){ + if(event == "enter"){ + owner->getBoard()->getActive()->getMinion().pop_back(); + charge -= actCost; + cout << "remaining charge for stand still " << charge << endl; + } + if (charge==0) { + cout << "goes in 0 ritualcharge" << endl; + owner->setRitual(nullptr); + } + } +} diff --git a/standstill.h b/standstill.h new file mode 100644 index 0000000..91a3c93 --- /dev/null +++ b/standstill.h @@ -0,0 +1,12 @@ +#ifndef STANDSTILL_H +#define STANDSTILL_H +#include "ritual.h" +#include "player.h" +class StandStill :public Ritual { + public: + StandStill(Player *owner); + ~StandStill(); + void notify(const std::string event) override; +}; + +#endif diff --git a/textdisplay.cc b/textdisplay.cc new file mode 100644 index 0000000..fa375bd --- /dev/null +++ b/textdisplay.cc @@ -0,0 +1,267 @@ + +#include "textdisplay.h" +#include "board.h" +#include "player.h" +#include "minion.h" +#include "ascii_graphics.h" +#include +#include +#include "ritual.h" +using namespace std; + + + + + +void TextDisplay::inspectMinion(shared_ptr m){ + for(int i = 0; i < display_minion_no_ability("",1,1,1).size(); ++i){ + if(m->getType() == "Minion"){ + cout << "\033[1;33m"; //display minions in yellow + if(m->getAbCost() != 0){ + cout << display_minion_activated_ability(m->getName(),m->getCost(),m->getAttack(),m->getDefence(),m->getAbCost(),m->getDes())[i]; + }else if(m->getDes() != ""){ + cout << display_minion_triggered_ability(m->getName(),m->getCost(),m->getAttack(),m->getDefence(),m->getDes())[i]; + }else{ + cout << display_minion_no_ability(m->getName(),m->getCost(),m->getAttack(),m->getDefence())[i]; + } + } + cout << endl; + } + + vector > enchantments = m->getEnchants(); + int counter = 0; + int place = 0; + int line = 5; + int diff = -1; + if(enchantments.size() <= line){ + line = enchantments.size(); + } + for(int x = 0; x < enchantments.size(); ++x){ + if(diff == 0) + continue; + for(int i = 0; i < display_minion_no_ability("",1,1,1).size(); i++){ + for(int j = counter; j < line; ++j){ + cout << "\033[0;32m"; //display rituals in blue + if(enchantments[j]->getName() == "Enrage"){ + cout << display_enchantment_attack_defence(enchantments[j]->getName(), enchantments[j]->getCost(), enchantments[j]->getDes(), "*2", "*2")[i]; + } + else if(enchantments[j]->getName() == "Giant Strength"){ + cout << display_enchantment_attack_defence(enchantments[j]->getName(), enchantments[j]->getCost(), enchantments[j]->getDes(), "+2", "+2")[i]; + } + else{ + cout << display_enchantment(enchantments[j]->getName(), enchantments[j]->getCost(), enchantments[j]->getDes())[i]; + } + if(i == 0){ + place += 1; + } + } + cout << endl; + } + counter += place; + diff = enchantments.size() - line; + if(diff < 5){ + line += diff; + }else{ + line += 5; + } + } + cout << "\033[0m"; +} + +void TextDisplay::displayHand(Player *p){ + int handNum = p->getHand().size(); + vector> hand = p->getHand(); + for(int i = 0; i < display_minion_no_ability("",1,1,1).size(); ++i){ + for(int j = 0; j < handNum; ++j){ + if(hand[j]->getType() == "Minion"){ + cout << "\033[1;33m"; //display minions in yellow + if(hand[j]->getAbCost() != 0){ + cout << display_minion_activated_ability(hand[j]->getName(),hand[j]->getCost(),hand[j]->getAttack(),hand[j]->getDefence(),hand[j]->getAbCost(),hand[j]->getDes())[i]; + }else if(hand[j]->getDes() != ""){ + cout << display_minion_triggered_ability(hand[j]->getName(),hand[j]->getCost(),hand[j]->getAttack(),hand[j]->getDefence(),hand[j]->getDes())[i]; + }else{ + cout << display_minion_no_ability(hand[j]->getName(),hand[j]->getCost(),hand[j]->getAttack(),hand[j]->getDefence())[i]; + } + }else if(hand[j]->getType() == "Ritual"){ + cout << "\033[0;31m"; //display rituals in red + cout << display_ritual(hand[j]->getName(),hand[j]->getCost(),hand[j]->getRitualCost(),hand[j]->getDes(),hand[j]->getRitualCharge())[i]; + }else if(hand[j]->getType() == "Spell"){ + cout << "\033[0;34m"; //display Spells in blue + cout << display_spell(hand[j]->getName(), hand[j]->getCost(), hand[j]->getDes())[i]; + }else if(hand[j]->getType() == "Enchantment"){ + cout << "\033[0;32m"; //display enchantments in green + if(hand[j]->getName() == "Giant Strength"){ + cout << display_enchantment_attack_defence(hand[j]->getName(), hand[j]->getCost(), hand[j]->getDes(), "+2", "+2")[i]; + } + else if(hand[j]->getName() == "Enrage"){ + cout << display_enchantment_attack_defence(hand[j]->getName(), hand[j]->getCost(), hand[j]->getDes(), "*2", "*2")[i]; + } + else{ + cout << display_enchantment(hand[j]->getName(), hand[j]->getCost(), hand[j]->getDes())[i]; + } + } + } + cout << "\033[0m" << endl; //normalization to white + } +} + + +void TextDisplay::displayBoard(Board *b){ + int minionact = b->getActive()->getMinion().size(); + int minionin = b->getInactive()->getMinion().size(); + shared_ptr ritualact = b->getActive()->getRitual(); + shared_ptr ritualin = b->getInactive()->getRitual(); + bool graveyardact = false; + bool graveyardin = false; + if(b->getActive()->getGraveyard().size() > 0){ + graveyardact = true; + } + if(b->getInactive()->getGraveyard().size() > 0){ + graveyardin = true; + } + cout << "\033[0;36m"; + cout << EXTERNAL_BORDER_CHAR_TOP_LEFT; + for(int i = 0; i < 165; ++i){ + cout << EXTERNAL_BORDER_CHAR_LEFT_RIGHT; + } + cout << EXTERNAL_BORDER_CHAR_TOP_RIGHT << endl; + // done first row + for(int i = 0; i < display_minion_no_ability("Hi",1,3,2).size(); ++i){ + cout << EXTERNAL_BORDER_CHAR_UP_DOWN; + cout << "\033[0m"; + if(ritualact != nullptr){ + cout << "\033[0;31m"; // red + cout << display_ritual(ritualact->getName(),ritualact->getCost(),ritualact->getRitualCost(),ritualact->getDes(),ritualact->getRitualCharge())[i]; + cout << "\033[0m"; + }else{ + cout << CARD_TEMPLATE_EMPTY[i]; + } + cout << CARD_TEMPLATE_EMPTY[i]; + cout << "\033[0;95m"; + cout << display_player_card(1,b->getActive()->getName(),b->getActive()->getHealth(),b->getActive()->getMagic())[i]; + cout << "\033[0m"; + cout << CARD_TEMPLATE_EMPTY[i]; + if(graveyardact){ + shared_ptr dead = b->getActive()->getGraveyard().back(); + cout << "\033[0;31m"; + if(dead->getAbCost() != 0){ + cout << display_minion_activated_ability(dead->getName(),dead->getCost(),dead->getAttack(),dead->getDefence(),dead->getAbCost(),dead->getDes())[i]; + }else if(dead->getDes() != ""){ + cout << display_minion_triggered_ability(dead->getName(),dead->getCost(),dead->getAttack(),dead->getDefence(),dead->getDes())[i]; + }else{ + cout << display_minion_no_ability(dead->getName(),dead->getCost(),dead->getAttack(),dead->getDefence())[i]; + } + cout << "\033[0m"; + }else{ + cout << CARD_TEMPLATE_EMPTY[i]; + } + cout << "\033[0;36m"; + cout << EXTERNAL_BORDER_CHAR_UP_DOWN << endl; + } + //----END_OF---- + //Legit Second row + for(int i = 0; i < display_minion_no_ability("Hi",1,3,2).size(); ++i){ + cout << "\033[0;36m"; + cout << EXTERNAL_BORDER_CHAR_UP_DOWN; + vector> temp = b->getActive()->getMinion(); + cout << "\033[1;33m"; + for(int j = 0; j < minionact; ++j){ + if(temp[j]->getAbCost() != 0){ + cout << display_minion_activated_ability(temp[j]->getName(),temp[j]->getCost(),temp[j]->getAttack(),temp[j]->getDefence(),temp[j]->getAbCost(),temp[j]->getDes())[i]; + }else if(temp[j]->getDes() != ""){ + cout << display_minion_triggered_ability(temp[j]->getName(),temp[j]->getCost(),temp[j]->getAttack(),temp[j]->getDefence(),temp[j]->getDes())[i]; + }else{ + cout << display_minion_no_ability(temp[j]->getName(),temp[j]->getCost(),temp[j]->getAttack(),temp[j]->getDefence())[i]; + } + } + cout << "\033[0m"; + for(int x = 0; x < 5 - minionact; ++x){ + cout << CARD_TEMPLATE_EMPTY[i]; + } + cout << "\033[0;36m"; + cout << EXTERNAL_BORDER_CHAR_UP_DOWN << endl; + } + //----END_OF---- + //Center Graphic + for(int i = 0; i < CENTRE_GRAPHIC.size(); ++i){ + cout << "\033[0;35m" << CENTRE_GRAPHIC[i] << "\033[0m" << endl; + } + //----END_OF---- + //Legit Second row + for(int i = 0; i < display_minion_no_ability("Hi",1,3,2).size(); ++i){ + //always keep this since its a border + cout << "\033[0;36m"; + cout << EXTERNAL_BORDER_CHAR_UP_DOWN; + vector> temp = b->getInactive()->getMinion(); + cout << "\033[1;33m"; + for(int j = 0; j < minionin; ++j){ + if(temp[j]->getAbCost() != 0){ + cout << display_minion_activated_ability(temp[j]->getName(),temp[j]->getCost(),temp[j]->getAttack(),temp[j]->getDefence(),temp[j]->getAbCost(),temp[j]->getDes())[i]; + }else if(temp[j]->getDes()!=""){ + cout << display_minion_triggered_ability(temp[j]->getName(),temp[j]->getCost(),temp[j]->getAttack(),temp[j]->getDefence(),temp[j]->getDes())[i]; + }else{ + cout << display_minion_no_ability(temp[j]->getName(),temp[j]->getCost(),temp[j]->getAttack(),temp[j]->getDefence())[i]; + } + } + cout << "\033[0m"; + for(int x = 0; x < 5 - minionin; ++x){ + cout << CARD_TEMPLATE_EMPTY[i]; + } + cout << "\033[0;36m"; + cout << EXTERNAL_BORDER_CHAR_UP_DOWN << endl; + } + for(int i = 0; i < display_minion_no_ability("Hi",1,3,2).size(); ++i){ + //always keep this since its a border + cout << "\033[0;36m"; + cout << EXTERNAL_BORDER_CHAR_UP_DOWN; + if(ritualin != nullptr){ + cout << "\033[0;34m"; //display in blue for player 2's ritual + cout << display_ritual(ritualin->getName(),ritualin->getCost(),ritualin->getRitualCost(),ritualin->getDes(),ritualin->getRitualCharge())[i]; + cout << "\033[0m"; + }else{ + cout << CARD_TEMPLATE_EMPTY[i]; + } + cout << CARD_TEMPLATE_EMPTY[i]; + cout << "\033[0;95m"; + cout << display_player_card(1,b->getInactive()->getName(),b->getInactive()->getHealth(),b->getInactive()->getMagic())[i]; + cout << "\033[0m"; + cout << CARD_TEMPLATE_EMPTY[i]; + if(graveyardin){ + cout << "\033[0;31m"; //display in red for player 2's graveyard + shared_ptr temp = b->getInactive()->getGraveyard().back(); + if(temp->getAbCost() != 0){ + cout << display_minion_activated_ability(temp->getName(),temp->getCost(),temp->getAttack(),temp->getDefence(),temp->getAbCost(),temp->getDes())[i]; + }else if(temp->getDes()!=""){ + cout <getName(),temp->getCost(),temp->getAttack(),temp->getDefence(),temp->getDes())[i]; + }else{ + cout << display_minion_no_ability(temp->getName(),temp->getCost(),temp->getAttack(),temp->getDefence())[i]; + } + cout << "\033[0m"; + }else{ + cout << CARD_TEMPLATE_EMPTY[i]; + } + cout << "\033[0;36m"; + cout << EXTERNAL_BORDER_CHAR_UP_DOWN << endl; + } + cout << "\033[0;36m"; + cout << EXTERNAL_BORDER_CHAR_BOTTOM_LEFT; + for(int i = 0; i < 165; ++i){ + cout << EXTERNAL_BORDER_CHAR_LEFT_RIGHT; + } + cout << EXTERNAL_BORDER_CHAR_BOTTOM_RIGHT << endl; + cout << "\033[0m"; + //----END_OF---- +} + +/* void Prompt::switchMsg(Player *p1, Player *p2){ + string p1Name = p1->getName(); + string p2Name = p2->getName(); + cout << "Turn from " << p1Name << " to " << p2Name << endl; + cout << "Active player is now " << p2Name << endl; +} */ + +void TextDisplay::handFull(){ + cout << "Error! Hand is Full!" << endl; +} + + diff --git a/textdisplay.h b/textdisplay.h new file mode 100644 index 0000000..0a2daa3 --- /dev/null +++ b/textdisplay.h @@ -0,0 +1,16 @@ +#ifndef _TEXTDISPLAY_H_ +#define _TEXTDISPLAY_H_ +#include +class Board; +class Player; +class Card; + +class TextDisplay{ +public: + void displayBoard(Board *b); + void displayHand(Player *p); + void inspectMinion(std::shared_ptr m); + void handFull(); +}; + +#endif diff --git a/unsummon.cc b/unsummon.cc new file mode 100644 index 0000000..d02d29a --- /dev/null +++ b/unsummon.cc @@ -0,0 +1,21 @@ +#include "unsummon.h" +#include "card.h" +#include "player.h" +#include + +using namespace std; + +Unsummon::Unsummon(Player *owner):Spell{"Unsummon","Spell","Return target minion to its owner's hand",1,owner}{} + +Unsummon::~Unsummon(){} + + +void Unsummon::activate(shared_ptr c){ + int temp = c->getEnchants().size(); + for(int i = 0; i < temp; ++i){ + c->popEnchant(); + } + c->getOwner()->returnCard(c); + } + +void Unsummon::activate(){} diff --git a/unsummon.h b/unsummon.h new file mode 100644 index 0000000..e585046 --- /dev/null +++ b/unsummon.h @@ -0,0 +1,14 @@ +#ifndef __UNSUMMON_H_ +#define __UNSUMMON_H_ +#include "spell.h" +#include "card.h" + +class Unsummon: public Spell{ +public: + Unsummon(Player *owner); + ~Unsummon(); + void activate(std::shared_ptr) override; + void activate() override; +}; + +#endif