Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. //w mainie:
  2.  
  3. Warrior w1;
  4.  
  5. //w pliku .h
  6.  
  7. class Warrior : public Player
  8. {
  9. int w_counter;//licznik warriorow
  10.  
  11. protected:
  12. int shield;
  13.  
  14. public:
  15. Warrior *first = new Warrior;
  16. Warrior *next;
  17.  
  18. void add(string n);
  19. void dir();
  20.  
  21. Warrior();
  22. ~Warrior();
  23. };
  24.  
  25. //w pliku .cpp
  26.  
  27. Warrior::Warrior()
  28. {
  29. w_counter++;
  30. first->hp=NULL;
  31. first->damage=NULL;
  32. first->shield=NULL;
  33. first->next=NULL;
  34. }
  35.  
  36. Warrior::~Warrior()
  37. {
  38. w_counter--;
  39. first->hp=NULL;
  40. first->damage=NULL;
  41. first->shield=NULL;
  42. first->next=NULL;
  43. delete first;
  44. }
  45.  
  46. void Warrior::add(string n)
  47. {
  48. Warrior *nju = new Warrior;
  49. Warrior *tmp = first;
  50.  
  51. nju->name=n;
  52. cout<<endl<<"Podaj wartosc hp: ";
  53. cin>>nju->hp;
  54. cout<<endl<<"Podaj wartosc damage: ";
  55. cin>>nju->damage;
  56. cout<<"Podaj wartosc shield: ";
  57. cin>>nju->shield;
  58.  
  59. if(first->hp == NULL)
  60. {
  61. first = nju;
  62. }
  63. else
  64. {
  65. while(tmp->next)
  66. {
  67. tmp=tmp->next;
  68. }
  69. tmp->next = nju;
  70. }
  71. }
  72.  
  73. void Warrior::dir()
  74. {
  75. Warrior *tmp = first;
  76.  
  77. cout<<endl<<"Lista obiektow typu Warrior: "<<endl<<endl;
  78.  
  79. while(tmp)
  80. {
  81. cout<< tmp->name <<endl;
  82. tmp=tmp->next;
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement