Browse Source

removed vector

master
myitinos 8 months ago
parent
commit
10761eea20
8 changed files with 51 additions and 68 deletions
  1. 14
    0
      Makefile
  2. 0
    17
      lib/Character.cpp
  3. 0
    5
      lib/Character.hpp
  4. 0
    11
      lib/Spell.cpp
  5. 0
    3
      lib/Spell.hpp
  6. 37
    14
      main.cpp
  7. 0
    18
      makefile
  8. BIN
      spell-warz

+ 14
- 0
Makefile View File

@@ -0,0 +1,14 @@
1
+CC = g++
2
+CFLAGS = 
3
+
4
+Spell.o: lib/Spell.cpp lib/Spell.hpp
5
+	g++ -c lib/Spell.cpp -o Spell.o
6
+
7
+Character.o: lib/Character.cpp lib/Character.hpp
8
+	g++ -c lib/Character.cpp -o Character.o
9
+
10
+spell-warz: Spell.o Character.o main.cpp lib/Character.hpp lib/Spell.hpp
11
+	g++ -static main.cpp -o spell-warz Spell.o Character.o
12
+
13
+clean: 
14
+	rm *.o

+ 0
- 17
lib/Character.cpp View File

@@ -1,14 +1,5 @@
1 1
 #include "Character.hpp"
2 2
 
3
-std::vector<const char *> Character::playerNames = {
4
-    "Abby",
5
-    "John",
6
-    "Adam",
7
-    "Johny",
8
-    "Christo",
9
-    "Greg",
10
-};
11
-
12 3
 Character::Character(const char *n, int l, int e, int h, int m, int a, int d)
13 4
 {
14 5
     this->name = n;
@@ -108,14 +99,6 @@ void Character::reduceMP(int n)
108 99
     this->curMP -= n;
109 100
 }
110 101
 
111
-std::vector<Character *> Character::Enemies = {
112
-    new Character("Red Mage", 1, 1, 10, 5, 1, 1),
113
-    new Character("Green Mage", 2, 3, 20, 10, 1, 1),
114
-    new Character("Blue Mage", 3, 7, 40, 25, 1, 1),
115
-    new Character("White Mage", 4, 11, 80, 40, 1, 1),
116
-    new Character("Black Mage", 5, 16, 160, 80, 1, 1),
117
-};
118
-
119 102
 bool Character::isAlive()
120 103
 {
121 104
     return this->curHP > 0;

+ 0
- 5
lib/Character.hpp View File

@@ -1,8 +1,6 @@
1 1
 #ifndef SPELL_WARZ_CHARACTER_HPP
2 2
 #define SPELL_WARZ_CHARACTER_HPP 1
3 3
 
4
-#include <vector>
5
-
6 4
 #include "Spell.hpp"
7 5
 
8 6
 class Character
@@ -22,9 +20,6 @@ protected:
22 20
     int def;
23 21
 
24 22
 public:
25
-    static std::vector<Character *> Enemies;
26
-    static std::vector<const char *> playerNames;
27
-
28 23
     Character(const char *, int, int, int, int, int, int);
29 24
 
30 25
     void restoreHP(int);

+ 0
- 11
lib/Spell.cpp View File

@@ -27,14 +27,3 @@ const char *Spell::getName()
27 27
 {
28 28
     return this->name;
29 29
 }
30
-
31
-std::vector<Spell *> Spell::Book = {
32
-    new Spell("Spanish Inquisition", 1, 111111, 0),
33
-    new Spell("Mana Bolt", 1, 5, 1),
34
-    new Spell("Flame Bolt", 1, 8, 2),
35
-    new Spell("Mana Flare", 1, 10, 3),
36
-    new Spell("Ice Spear", 1, 13, 4),
37
-    new Spell("Mana Misile", 1, 15, 5),
38
-    new Spell("Thunder Strike", 1, 18, 6),
39
-    new Spell("Mana Blast", 1, 20, 7),
40
-};

+ 0
- 3
lib/Spell.hpp View File

@@ -1,8 +1,6 @@
1 1
 #ifndef SPELL_WARZ_SPELL_CPP
2 2
 #define SPELL_WARZ_SPELL_CPP 1
3 3
 
4
-#include <vector>
5
-
6 4
 class Spell
7 5
 {
8 6
 protected:
@@ -15,7 +13,6 @@ protected:
15 13
 public:
16 14
     int TYPE_RESTORATION = 0;
17 15
     int TYPE_DESTRUCTION = 1;
18
-    static std::vector<Spell *> Book;
19 16
 
20 17
     Spell(const char *, int, int, int);
21 18
     int getType();

+ 37
- 14
main.cpp View File

@@ -11,6 +11,17 @@
11 11
 #define INTERVAL 1000
12 12
 #define FLAG_INTERVAL 250
13 13
 
14
+Spell spellBook[] = {
15
+    Spell("Spanish Inquisition", 1, 111111, 0),
16
+    Spell("Mana Bolt", 1, 5, 1),
17
+    Spell("Flame Bolt", 1, 8, 2),
18
+    Spell("Mana Flare", 1, 10, 3),
19
+    Spell("Ice Spear", 1, 13, 4),
20
+    Spell("Mana Misile", 1, 15, 5),
21
+    Spell("Thunder Strike", 1, 18, 6),
22
+    Spell("Mana Blast", 1, 20, 7),
23
+};
24
+
14 25
 void sleep(int ms)
15 26
 {
16 27
     std::this_thread::sleep_for(std::chrono::milliseconds(ms));
@@ -86,24 +97,36 @@ int getNumber(const char *prompt, int min, int max)
86 97
 
87 98
 Character *chooseEnemy()
88 99
 {
100
+    Character Enemies[] = {
101
+        Character("Red Mage", 1, 1, 10, 5, 1, 1),
102
+        Character("Green Mage", 2, 3, 20, 10, 1, 1),
103
+        Character("Blue Mage", 3, 7, 40, 25, 1, 1),
104
+        Character("White Mage", 4, 11, 80, 40, 1, 1),
105
+        Character("Black Mage", 5, 16, 160, 80, 1, 1),
106
+    };
89 107
     std::cout << "List of challenger:" << std::endl;
90
-    for (int i = 0; i < Character::Enemies.size(); i++)
108
+    for (int i = 0; i < 5; i++)
91 109
     {
92
-        std::cout << "[" << i << "] " << Character::Enemies[i]->getName() << std::endl;
110
+        std::cout << "[" << i << "] " << Enemies[i].getName() << std::endl;
93 111
     }
94 112
 
95 113
     int choice = 0;
96
-    do
97
-    {
98
-        choice = getNumber("Choose your enemy: ", 0, Character::Enemies.size());
99
-    } while (!(choice >= 0 && choice < Character::Enemies.size()));
100
-    return Character::Enemies[choice];
114
+    choice = getNumber("Choose your enemy: ", 0, 4);
115
+    return new Character(Enemies[choice]);
101 116
 }
102 117
 
103 118
 Character *generatePlayer()
104 119
 {
120
+    const char *playerNames[] = {
121
+        "Abby",
122
+        "John",
123
+        "Adam",
124
+        "Johny",
125
+        "Christo",
126
+        "Greg",
127
+    };
105 128
     Character *tmp = new Character(
106
-        Character::playerNames[std::rand() % Character::playerNames.size()],
129
+        playerNames[std::rand() % 6],
107 130
         1,
108 131
         1,
109 132
         100,
@@ -156,16 +179,16 @@ Character *startBattle(Character *p1, Character *p2)
156 179
         printCharacterInfo(p2);
157 180
 
158 181
         std::cout << "===== Spell Books =====" << std::endl;
159
-        for (int i = 1; i <= p1->getLevel() && i < Spell::Book.size(); i++)
182
+        for (int i = 1; i <= p1->getLevel() && i < 8; i++)
160 183
         {
161
-            std::cout << "[" << i << "] " << Spell::Book[i]->getName() << std::endl;
184
+            std::cout << "[" << i << "] " << spellBook[i].getName() << std::endl;
162 185
         }
163 186
 
164
-        int p1Choice = getNumber("Choose your spell: ", 0, getLowest(p1->getLevel(), Spell::Book.size() - 1));
165
-        int p2Choice = (std::rand() % getLowest(p2->getLevel(), Spell::Book.size() - 1)) + 1;
187
+        int p1Choice = getNumber("Choose your spell: ", 0, getLowest(p1->getLevel(), 8 - 1));
188
+        int p2Choice = (std::rand() % getLowest(p2->getLevel(), 8 - 1)) + 1;
166 189
 
167
-        Spell *p1Spell = Spell::Book[p1Choice];
168
-        Spell *p2Spell = Spell::Book[p2Choice];
190
+        Spell *p1Spell = &spellBook[p1Choice];
191
+        Spell *p2Spell = &spellBook[p2Choice];
169 192
 
170 193
         if (p1->canCastSpell(p1Spell))
171 194
         {

+ 0
- 18
makefile View File

@@ -1,18 +0,0 @@
1
-CC = g++
2
-
3
-Spell.o: lib/Spell.cpp lib/Spell.hpp
4
-	g++ -c lib/Spell.cpp -o Spell.o
5
-
6
-Character.o: lib/Character.cpp lib/Character.hpp
7
-	g++ -c lib/Character.cpp -o Character.o
8
-
9
-main: Spell.o Character.o main.cpp lib/Character.hpp lib/Spell.hpp
10
-	g++ main.cpp -o main Spell.o Character.o
11
-
12
-clean: Spell.o Character.o
13
-	rm Spell.o Character.o
14
-
15
-striped: Spell.o Character.o main.cpp lib/Character.hpp lib/Spell.hpp
16
-	g++ -s main.cpp -o main Spell.o Character.o
17
-
18
-all: Spell.o Character.o main

BIN
spell-warz View File


Loading…
Cancel
Save