Я пытаюсь вывести случайное значение вектора, и мне удалось сделать что-то вроде
srand(time(0));
cout << enemies[rand() % enemies.size()].getName() << endl;
Почему бы не вернуть значение
{5, 15, 0, "name1", 40, 20},
{10, 10, 0, "name2", 60, 30},
{5, 15, 0, "name3", 20, 20},
, но это возвращает "что-то" из
class Enemy : public Player
{
public:
int exp;
int money;
Enemy(int attack = 0, int defense = 0, int evasion = 0, string name = "something", int money = 0, int exp = 0)
Может ли кто-нибудь указать на то, что я здесь не понимаю? У меня есть класс, конструктор и вектор для хранения данных, и я хочу вывести случайное значение, чтобы получить случайного врага в столкновении. Пожалуйста.
#include <cstdlib>
#include <iostream>
#include <ctime>
#include <vector>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::vector;
class Player
{
public:
int attack;
int defense;
int evasion;
string name;
Player(int atk = 0, int def = 0, int eva = 0, string nameClass = "Wiz")
{
attack = atk;
defense = def;
evasion = eva;
name = nameClass;
}
void setAttack(int atk)
{
attack = atk;
}
int getAttack()
{
return attack;
}
void setDefense(int def)
{
defense = def;
}
int getDefense()
{
return defense;
}
void setEvasion(int evs)
{
evasion = evs;
}
int getEvasion()
{
return evasion;
}
string getName()
{
return name;
}
};
class Enemy : public Player
{
public:
int exp;
int money;
Enemy(int attack = 0, int defense = 0, int evasion = 0, string name = "Wiz", int money = 0, int exp = 0)
{
}
int getAttack()
{
return attack;
}
int getDefense()
{
return defense;
}
int getEvasion()
{
return evasion;
}
string getName()
{
return name;
}
int getMoney()
{
return money;
}
int getExp()
{
return exp;
}
};
int main()
{
srand(time(0));
Enemy timberWolf(5, 15, 0, "Timber Wolf", 40, 20);
Enemy dwarvenSharpshooter(10, 10, 0, "Dwarven Sharpshooter", 60, 30);
Enemy pharaohCat(5, 15, 0, "Pharaoh Cat", 20, 20);
Enemy swashbuckler(5, 20, 0, "Swashbuckler", 20, 10);
Enemy steelBeetle(30, 20, 30, "Steel Beetle", 160, 80);
Enemy scavengingHyena(45, 20, 30, "Scavenging Hyena", 180, 100);
Enemy manaWyrm(35, 45, 30, "Mana Wyrm", 170, 90);
Enemy manaCyclone(35, 20, 30, "Mana Cyclone", 180, 90);
Enemy pyromaniac(65, 35, 45, "Pyromaniac", 290, 160);
Enemy flamewalker(60, 50, 50, "Flamewalker", 320, 160);
Enemy arcaneAmplifier(65, 55, 45, "Arcane Amplifier", 320, 170);
Enemy voidTerror(55, 45, 55, "Void Terror", 310, 170);
Enemy mistwraith(85, 35, 65, "Mistwraith", 330, 175);
Enemy plaguebringer(75, 30, 70, "Plaguebringer", 310, 175);
Enemy henchClanBurglar(80, 35, 85, "Hench-Clan Burglar", 330, 165);
Enemy yeti(80, 40, 60, "Yeti", 320, 180);
Enemy oasisSurger(90, 45, 55, "Oasis Surger", 340, 175);
Enemy starvingBuzzard(85, 45, 60, "Starving Buzzard", 330, 190);
Enemy earthElemental(90, 45, 70, "Earth Elemental", 345, 180);
Enemy abomination(80, 55, 45, "Abomination", 340, 175);
Enemy cenarius(100, 65, 65, "Cenarius", 380, 210);
Enemy kingKrush(100, 70, 60, "King Krush", 400, 220);
Enemy archmageAntonidas(95, 65, 60, "Archmage Antonidas", 380, 210);
Enemy alAkirTheWindlord(90, 60, 65, "Al'Akir the Windlord", 360, 200);
Enemy deathWing(110, 90, 80, "Death Wing");
Player wizard(60, 40, 60, "Wizard");
Player warrior(50, 60, 40, "Warrior");
Player paladin(40, 70, 50, "Paladin");
Player druid(60, 40, 60, "Druid");
Player assassin(70, 30, 70, "Assassin");
vector<Enemy> enemies
{
{5, 15, 0, "Timber Wolf", 40, 20},
{10, 10, 0, "Dwarven Sharpshooter", 60, 30},
{5, 15, 0, "Pharaoh Cat", 20, 20},
{5, 20, 0, "Swashbuckler", 20, 10},
{30, 20, 30, "Steel Beetle", 160, 80},
{45, 20, 30, "Scavenging Hyena", 180, 100},
{35, 45, 30, "Mana Wyrm", 170, 90},
{35, 20, 30, "Mana Cyclone", 180, 90},
{65, 35, 45, "Pyromaniac", 290, 160},
{60, 50, 50, "Flamewalker", 320, 160},
{65, 55, 45, "Arcane Amplifier", 320, 170},
{55, 45, 55, "Void Terror", 310, 170},
{85, 35, 65, "Mistwraith", 330, 175},
{75, 30, 70, "Plaguebringer", 310, 175},
{80, 35, 85, "Hench-Clan Burglar", 330, 165},
{80, 40, 60, "Yeti", 320, 180},
{90, 45, 55, "Oasis Surger", 340, 175},
{85, 45, 60, "Starving Buzzard", 330, 190},
{90, 45, 70, "Earth Elemental", 345, 180},
{80, 55, 45, "Abomination", 340, 175},
{100, 65, 65, "Cenarius", 380, 210},
{100, 70, 60, "King Krush", 400, 220},
{95, 65, 60, "Archmage Antonidas", 380, 210},
{90, 60, 65, "Al'Akir the Windlord", 360, 200},
{110, 90, 80, "Death Wing"},
};
enemies.insert(enemies.begin(), 26);
cout << enemies[rand() % enemies.size()].getDefense() << endl;
return 0;
}