Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //w mainie:
- Warrior w1;
- //w pliku .h
- class Warrior : public Player
- {
- int w_counter;//licznik warriorow
- protected:
- int shield;
- public:
- Warrior *first = new Warrior;
- Warrior *next;
- void add(string n);
- void dir();
- Warrior();
- ~Warrior();
- };
- //w pliku .cpp
- Warrior::Warrior()
- {
- w_counter++;
- first->hp=NULL;
- first->damage=NULL;
- first->shield=NULL;
- first->next=NULL;
- }
- Warrior::~Warrior()
- {
- w_counter--;
- first->hp=NULL;
- first->damage=NULL;
- first->shield=NULL;
- first->next=NULL;
- delete first;
- }
- void Warrior::add(string n)
- {
- Warrior *nju = new Warrior;
- Warrior *tmp = first;
- nju->name=n;
- cout<<endl<<"Podaj wartosc hp: ";
- cin>>nju->hp;
- cout<<endl<<"Podaj wartosc damage: ";
- cin>>nju->damage;
- cout<<"Podaj wartosc shield: ";
- cin>>nju->shield;
- if(first->hp == NULL)
- {
- first = nju;
- }
- else
- {
- while(tmp->next)
- {
- tmp=tmp->next;
- }
- tmp->next = nju;
- }
- }
- void Warrior::dir()
- {
- Warrior *tmp = first;
- cout<<endl<<"Lista obiektow typu Warrior: "<<endl<<endl;
- while(tmp)
- {
- cout<< tmp->name <<endl;
- tmp=tmp->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement