AIUTO!Problema con lettura dei metodi da parte di un vettore

di il
2 risposte

AIUTO!Problema con lettura dei metodi da parte di un vettore

Ciao a tutti! non riesco a capire perché il vettore _atk definito nella classe Monster non legge i metodi che ho definito nella classe Attacks. Qualcuno mi può aiutare?


Attacks::Attacks(int ID): _ID(ID)
{
}

Attacks::Attacks(const Attacks & to_copy){
this->_ID=to_copy.ID();
this->_name=to_copy.name();
this->_PDB=to_copy.PDB();
this->_MSFA[0]=to_copy.MSFA0();
this->_MSFA[1]=to_copy.MSFA1();
this->_MSFA[2]=to_copy.MSFA2();
this->_MSFD[0]=to_copy.MSFD0();
this->_MSFD[1]=to_copy.MSFD1();
this->_MSFD[2]=to_copy.MSFD2();
}


Attacks:: Attacks(string line_entry){

stringstream ss(line_entry);
ss>> _ID>> _name>> _PDB;


for(unsigned int i=0; i< line_entry.size(); ++i){
int j;
if(line_entry.find("attaccante")!= string::npos){
if(line_entry.find("PA")!= string::npos){
j=0;
}
else if(line_entry.find("PD")!= string::npos){
j=1;
}
else if(line_entry.find("PV")!= string::npos){
j=2;
}

if(line_entry.find("-")!= string::npos){
_MSFA[j]=-1;
if(line_entry.find("-")!= string::npos){
_MSFA[j]--;
ss>>_MSFA[0]>>_MSFA[1]>>_MSFA[2];
}
else ss>>_MSFA[0]>>_MSFA[1]>>_MSFA[2];
}

else if(line_entry.find("+")!= string::npos){ // npos significa -1
_MSFA[j]=1;
if(line_entry.find("+")!= string::npos){
_MSFA[j]++;
ss>>_MSFA[0]>>_MSFA[1]>>_MSFA[2];
}
else ss>>_MSFA[0]>>_MSFA[1]>>_MSFA[2];
}
}


if(line_entry.find("difensore")!= string::npos){

if(line_entry.find("PA")!= string::npos){
j=0;
}
else if(line_entry.find("PD")!= string::npos){
j=1;
}
else if(line_entry.find("PV")!= string::npos){
j=2;
}

if(line_entry.find("-")!= string::npos){
_MSFD[j]=-1;
if(line_entry.find("-")!= string::npos){
_MSFD[j]--;
ss>>_MSFD[0]>>_MSFD[1]>>_MSFD[2];
}
else ss>>_MSFD[0]>>_MSFD[1]>>_MSFD[2];
}

else if(line_entry.find("+")!= string::npos){
_MSFD[j]=1;
if(line_entry.find("+")!= string::npos){
_MSFD[j]++;
ss>>_MSFD[0]>>_MSFD[1]>>_MSFD[2];
}
else ss>>_MSFD[0]>>_MSFD[1]>>_MSFD[2];
}
}

if(line_entry.find("p")!= string::npos){
_priority=true;

}
ss>>_priority;
}
}


int Attacks:: ID()const{
return _ID;
}

string Attacks:: name()const{
return _name;
}

int Attacks::PDB()const{
return _PDB;
}

int Attacks::MSFA0()const{
return _MSFA[0];
}

int Attacks::MSFA1()const{
return _MSFA[1];
}

int Attacks::MSFA2()const{
return _MSFA[2];
}

int Attacks::MSFD0()const{
return _MSFD[0];
}

int Attacks::MSFD1()const{
return _MSFD[1];
}

int Attacks::MSFD2()const{
return _MSFD[2];
}

bool Attacks:: priority()const{
return _priority;
}


#include "Attacks.h"
#include "Filemanager.h"
#include <string>
#include <sstream>
#include <vector>
#include <fstream>
#include <iostream>
using namespace std;

class Monster
{
public:
Monster();
Monster(const Monster & to_copy);
virtual ~Monster();
Monster(string line_entry);
string name()const;
int speed()const ;
int ID()const;
int PS()const;
int PA()const;
int PD()const;
void read_file_attacks();
vector <Attacks> _atk;

private:

FileManager _f_attacks;
string _name;
int _ID,_PS,_PA,_PD,_speed;

};

#endif // MONSTER_H



void Monster:: read_file_attacks(){

_f_attacks.openFile ( "attacchi.txt" );

while (!_f_attacks .testEof()){

string line=_f_attacks.readLine();
Attacks new_attacks(line);
_atk.push_back(new_attacks);

}
_f_attacks.closeFile();
}

2 Risposte

Devi accedere o registrarti per scrivere nel forum
2 risposte