diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4b04c6c --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +CC = g++ +CFLAGS = + +Spell.o: lib/Spell.cpp lib/Spell.hpp + g++ -c lib/Spell.cpp -o Spell.o + +Character.o: lib/Character.cpp lib/Character.hpp + g++ -c lib/Character.cpp -o Character.o + +spell-warz: Spell.o Character.o main.cpp lib/Character.hpp lib/Spell.hpp + g++ -static main.cpp -o spell-warz Spell.o Character.o + +clean: + rm *.o diff --git a/lib/Character.cpp b/lib/Character.cpp index c2488c1..94c3ac7 100644 --- a/lib/Character.cpp +++ b/lib/Character.cpp @@ -1,14 +1,5 @@ #include "Character.hpp" -std::vector Character::playerNames = { - "Abby", - "John", - "Adam", - "Johny", - "Christo", - "Greg", -}; - Character::Character(const char *n, int l, int e, int h, int m, int a, int d) { this->name = n; @@ -108,14 +99,6 @@ void Character::reduceMP(int n) this->curMP -= n; } -std::vector Character::Enemies = { - new Character("Red Mage", 1, 1, 10, 5, 1, 1), - new Character("Green Mage", 2, 3, 20, 10, 1, 1), - new Character("Blue Mage", 3, 7, 40, 25, 1, 1), - new Character("White Mage", 4, 11, 80, 40, 1, 1), - new Character("Black Mage", 5, 16, 160, 80, 1, 1), -}; - bool Character::isAlive() { return this->curHP > 0; diff --git a/lib/Character.hpp b/lib/Character.hpp index 393e2f0..a2d60a6 100644 --- a/lib/Character.hpp +++ b/lib/Character.hpp @@ -1,8 +1,6 @@ #ifndef SPELL_WARZ_CHARACTER_HPP #define SPELL_WARZ_CHARACTER_HPP 1 -#include - #include "Spell.hpp" class Character @@ -22,9 +20,6 @@ protected: int def; public: - static std::vector Enemies; - static std::vector playerNames; - Character(const char *, int, int, int, int, int, int); void restoreHP(int); diff --git a/lib/Spell.cpp b/lib/Spell.cpp index 13e11be..524f60f 100644 --- a/lib/Spell.cpp +++ b/lib/Spell.cpp @@ -27,14 +27,3 @@ const char *Spell::getName() { return this->name; } - -std::vector Spell::Book = { - new Spell("Spanish Inquisition", 1, 111111, 0), - new Spell("Mana Bolt", 1, 5, 1), - new Spell("Flame Bolt", 1, 8, 2), - new Spell("Mana Flare", 1, 10, 3), - new Spell("Ice Spear", 1, 13, 4), - new Spell("Mana Misile", 1, 15, 5), - new Spell("Thunder Strike", 1, 18, 6), - new Spell("Mana Blast", 1, 20, 7), -}; \ No newline at end of file diff --git a/lib/Spell.hpp b/lib/Spell.hpp index 61865a0..f771ae7 100644 --- a/lib/Spell.hpp +++ b/lib/Spell.hpp @@ -1,8 +1,6 @@ #ifndef SPELL_WARZ_SPELL_CPP #define SPELL_WARZ_SPELL_CPP 1 -#include - class Spell { protected: @@ -15,7 +13,6 @@ protected: public: int TYPE_RESTORATION = 0; int TYPE_DESTRUCTION = 1; - static std::vector Book; Spell(const char *, int, int, int); int getType(); diff --git a/main.cpp b/main.cpp index 9981f4d..425e8f0 100644 --- a/main.cpp +++ b/main.cpp @@ -11,6 +11,17 @@ #define INTERVAL 1000 #define FLAG_INTERVAL 250 +Spell spellBook[] = { + Spell("Spanish Inquisition", 1, 111111, 0), + Spell("Mana Bolt", 1, 5, 1), + Spell("Flame Bolt", 1, 8, 2), + Spell("Mana Flare", 1, 10, 3), + Spell("Ice Spear", 1, 13, 4), + Spell("Mana Misile", 1, 15, 5), + Spell("Thunder Strike", 1, 18, 6), + Spell("Mana Blast", 1, 20, 7), +}; + void sleep(int ms) { std::this_thread::sleep_for(std::chrono::milliseconds(ms)); @@ -86,24 +97,36 @@ int getNumber(const char *prompt, int min, int max) Character *chooseEnemy() { + Character Enemies[] = { + Character("Red Mage", 1, 1, 10, 5, 1, 1), + Character("Green Mage", 2, 3, 20, 10, 1, 1), + Character("Blue Mage", 3, 7, 40, 25, 1, 1), + Character("White Mage", 4, 11, 80, 40, 1, 1), + Character("Black Mage", 5, 16, 160, 80, 1, 1), + }; std::cout << "List of challenger:" << std::endl; - for (int i = 0; i < Character::Enemies.size(); i++) + for (int i = 0; i < 5; i++) { - std::cout << "[" << i << "] " << Character::Enemies[i]->getName() << std::endl; + std::cout << "[" << i << "] " << Enemies[i].getName() << std::endl; } int choice = 0; - do - { - choice = getNumber("Choose your enemy: ", 0, Character::Enemies.size()); - } while (!(choice >= 0 && choice < Character::Enemies.size())); - return Character::Enemies[choice]; + choice = getNumber("Choose your enemy: ", 0, 4); + return new Character(Enemies[choice]); } Character *generatePlayer() { + const char *playerNames[] = { + "Abby", + "John", + "Adam", + "Johny", + "Christo", + "Greg", + }; Character *tmp = new Character( - Character::playerNames[std::rand() % Character::playerNames.size()], + playerNames[std::rand() % 6], 1, 1, 100, @@ -156,16 +179,16 @@ Character *startBattle(Character *p1, Character *p2) printCharacterInfo(p2); std::cout << "===== Spell Books =====" << std::endl; - for (int i = 1; i <= p1->getLevel() && i < Spell::Book.size(); i++) + for (int i = 1; i <= p1->getLevel() && i < 8; i++) { - std::cout << "[" << i << "] " << Spell::Book[i]->getName() << std::endl; + std::cout << "[" << i << "] " << spellBook[i].getName() << std::endl; } - int p1Choice = getNumber("Choose your spell: ", 0, getLowest(p1->getLevel(), Spell::Book.size() - 1)); - int p2Choice = (std::rand() % getLowest(p2->getLevel(), Spell::Book.size() - 1)) + 1; + int p1Choice = getNumber("Choose your spell: ", 0, getLowest(p1->getLevel(), 8 - 1)); + int p2Choice = (std::rand() % getLowest(p2->getLevel(), 8 - 1)) + 1; - Spell *p1Spell = Spell::Book[p1Choice]; - Spell *p2Spell = Spell::Book[p2Choice]; + Spell *p1Spell = &spellBook[p1Choice]; + Spell *p2Spell = &spellBook[p2Choice]; if (p1->canCastSpell(p1Spell)) { diff --git a/makefile b/makefile deleted file mode 100644 index ee3ba6c..0000000 --- a/makefile +++ /dev/null @@ -1,18 +0,0 @@ -CC = g++ - -Spell.o: lib/Spell.cpp lib/Spell.hpp - g++ -c lib/Spell.cpp -o Spell.o - -Character.o: lib/Character.cpp lib/Character.hpp - g++ -c lib/Character.cpp -o Character.o - -main: Spell.o Character.o main.cpp lib/Character.hpp lib/Spell.hpp - g++ main.cpp -o main Spell.o Character.o - -clean: Spell.o Character.o - rm Spell.o Character.o - -striped: Spell.o Character.o main.cpp lib/Character.hpp lib/Spell.hpp - g++ -s main.cpp -o main Spell.o Character.o - -all: Spell.o Character.o main diff --git a/spell-warz b/spell-warz new file mode 100755 index 0000000..51de7c6 Binary files /dev/null and b/spell-warz differ