Pārlūkot izejas kodu

removed vector

master
myitinos pirms 4 gadiem
vecāks
revīzija
10761eea20
8 mainītis faili ar 51 papildinājumiem un 68 dzēšanām
  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ārs
      spell-warz

+ 14
- 0
Makefile Parādīt failu

@ -0,0 +1,14 @@
CC = g++
CFLAGS =
Spell.o: lib/Spell.cpp lib/Spell.hpp
g++ -c lib/Spell.cpp -o Spell.o
Character.o: lib/Character.cpp lib/Character.hpp
g++ -c lib/Character.cpp -o Character.o
spell-warz: Spell.o Character.o main.cpp lib/Character.hpp lib/Spell.hpp
g++ -static main.cpp -o spell-warz Spell.o Character.o
clean:
rm *.o

+ 0
- 17
lib/Character.cpp Parādīt failu

@ -1,14 +1,5 @@
#include "Character.hpp"
std::vector<const char *> Character::playerNames = {
"Abby",
"John",
"Adam",
"Johny",
"Christo",
"Greg",
};
Character::Character(const char *n, int l, int e, int h, int m, int a, int d)
{
this->name = n;
@ -108,14 +99,6 @@ void Character::reduceMP(int n)
this->curMP -= n;
}
std::vector<Character *> Character::Enemies = {
new Character("Red Mage", 1, 1, 10, 5, 1, 1),
new Character("Green Mage", 2, 3, 20, 10, 1, 1),
new Character("Blue Mage", 3, 7, 40, 25, 1, 1),
new Character("White Mage", 4, 11, 80, 40, 1, 1),
new Character("Black Mage", 5, 16, 160, 80, 1, 1),
};
bool Character::isAlive()
{
return this->curHP > 0;

+ 0
- 5
lib/Character.hpp Parādīt failu

@ -1,8 +1,6 @@
#ifndef SPELL_WARZ_CHARACTER_HPP
#define SPELL_WARZ_CHARACTER_HPP 1
#include <vector>
#include "Spell.hpp"
class Character
@ -22,9 +20,6 @@ protected:
int def;
public:
static std::vector<Character *> Enemies;
static std::vector<const char *> playerNames;
Character(const char *, int, int, int, int, int, int);
void restoreHP(int);

+ 0
- 11
lib/Spell.cpp Parādīt failu

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

+ 0
- 3
lib/Spell.hpp Parādīt failu

@ -1,8 +1,6 @@
#ifndef SPELL_WARZ_SPELL_CPP
#define SPELL_WARZ_SPELL_CPP 1
#include <vector>
class Spell
{
protected:
@ -15,7 +13,6 @@ protected:
public:
int TYPE_RESTORATION = 0;
int TYPE_DESTRUCTION = 1;
static std::vector<Spell *> Book;
Spell(const char *, int, int, int);
int getType();

+ 37
- 14
main.cpp Parādīt failu

@ -11,6 +11,17 @@
#define INTERVAL 1000
#define FLAG_INTERVAL 250
Spell spellBook[] = {
Spell("Spanish Inquisition", 1, 111111, 0),
Spell("Mana Bolt", 1, 5, 1),
Spell("Flame Bolt", 1, 8, 2),
Spell("Mana Flare", 1, 10, 3),
Spell("Ice Spear", 1, 13, 4),
Spell("Mana Misile", 1, 15, 5),
Spell("Thunder Strike", 1, 18, 6),
Spell("Mana Blast", 1, 20, 7),
};
void sleep(int ms)
{
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
@ -86,24 +97,36 @@ int getNumber(const char *prompt, int min, int max)
Character *chooseEnemy()
{
Character Enemies[] = {
Character("Red Mage", 1, 1, 10, 5, 1, 1),
Character("Green Mage", 2, 3, 20, 10, 1, 1),
Character("Blue Mage", 3, 7, 40, 25, 1, 1),
Character("White Mage", 4, 11, 80, 40, 1, 1),
Character("Black Mage", 5, 16, 160, 80, 1, 1),
};
std::cout << "List of challenger:" << std::endl;
for (int i = 0; i < Character::Enemies.size(); i++)
for (int i = 0; i < 5; i++)
{
std::cout << "[" << i << "] " << Character::Enemies[i]->getName() << std::endl;
std::cout << "[" << i << "] " << Enemies[i].getName() << std::endl;
}
int choice = 0;
do
{
choice = getNumber("Choose your enemy: ", 0, Character::Enemies.size());
} while (!(choice >= 0 && choice < Character::Enemies.size()));
return Character::Enemies[choice];
choice = getNumber("Choose your enemy: ", 0, 4);
return new Character(Enemies[choice]);
}
Character *generatePlayer()
{
const char *playerNames[] = {
"Abby",
"John",
"Adam",
"Johny",
"Christo",
"Greg",
};
Character *tmp = new Character(
Character::playerNames[std::rand() % Character::playerNames.size()],
playerNames[std::rand() % 6],
1,
1,
100,
@ -156,16 +179,16 @@ Character *startBattle(Character *p1, Character *p2)
printCharacterInfo(p2);
std::cout << "===== Spell Books =====" << std::endl;
for (int i = 1; i <= p1->getLevel() && i < Spell::Book.size(); i++)
for (int i = 1; i <= p1->getLevel() && i < 8; i++)
{
std::cout << "[" << i << "] " << Spell::Book[i]->getName() << std::endl;
std::cout << "[" << i << "] " << spellBook[i].getName() << std::endl;
}
int p1Choice = getNumber("Choose your spell: ", 0, getLowest(p1->getLevel(), Spell::Book.size() - 1));
int p2Choice = (std::rand() % getLowest(p2->getLevel(), Spell::Book.size() - 1)) + 1;
int p1Choice = getNumber("Choose your spell: ", 0, getLowest(p1->getLevel(), 8 - 1));
int p2Choice = (std::rand() % getLowest(p2->getLevel(), 8 - 1)) + 1;
Spell *p1Spell = Spell::Book[p1Choice];
Spell *p2Spell = Spell::Book[p2Choice];
Spell *p1Spell = &spellBook[p1Choice];
Spell *p2Spell = &spellBook[p2Choice];
if (p1->canCastSpell(p1Spell))
{

+ 0
- 18
makefile Parādīt failu

@ -1,18 +0,0 @@
CC = g++
Spell.o: lib/Spell.cpp lib/Spell.hpp
g++ -c lib/Spell.cpp -o Spell.o
Character.o: lib/Character.cpp lib/Character.hpp
g++ -c lib/Character.cpp -o Character.o
main: Spell.o Character.o main.cpp lib/Character.hpp lib/Spell.hpp
g++ main.cpp -o main Spell.o Character.o
clean: Spell.o Character.o
rm Spell.o Character.o
striped: Spell.o Character.o main.cpp lib/Character.hpp lib/Spell.hpp
g++ -s main.cpp -o main Spell.o Character.o
all: Spell.o Character.o main

Binārs
spell-warz Parādīt failu


Notiek ielāde…
Atcelt
Saglabāt