I have a vector of objects.. monsters. and i have a function "shoot". i want that when i kill one of the monsters the object to be deleted. i've tryed various ways but no succes. Here's how i've created the objects:
void AdaugareMonstru(vector<monstru>& Nmonstru){
int i = 0;
srand(time(0));
int a, b;
for (i; i < 4; i++){
a = (rand() % 5)+1;
b = (rand() % 8)+1;
while (a == 1 && b == 1){
a = (rand() % 5)+1;
b = (rand() % 8)+1;
}
monstru newMonstru(a,b);
Nmonstru.push_back(newMonstru);
}
}
And here is the function where i find the monster in front of my "hero" and i kill it... or not..cuz i don't know how to delete it :D I think there is a problem with my declaration of the "trage " function but i can't figure it out.
void trage(vector<monstru>& monstru, vector< vector<char> > map,int x,int y,int face){
if (face == 1)
{
for (int i = y; i < 10; i++){
if (monstru[0].GetX() == x && monstru[0].GetY() == i){
monstru[0].SetX(0);
monstru[0].SetY(0);
cout << "Ai ucis un monstru" << endl;
}
if (monstru[1].GetX() == x && monstru[0].GetY() == i){
monstru[1].SetX(0);
monstru[1].SetY(0);
cout << "Ai ucis un monstru" << endl;
}
if (monstru[2].GetX() == x && monstru[0].GetY() == i){
monstru[2].SetX(0);
monstru[2].SetY(0);
cout << "Ai ucis un monstru" << endl;
}
if (monstru[3].GetX() == x && monstru[0].GetY() == i){
monstru[3].SetX(0);
monstru[3].SetY(0);
// Instead of setting X and Y to 0 i want to delete the whole object.
monstru.erase(1); // doesn't work... no wonder:D
delete monstru[0]; // doesn't work either.
cout << "Ai ucis un monstru" << endl;
}
}
}
}