Advertisement
pieniakoskar

Character

May 21st, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <conio.h>
  5.  
  6. using namespace std;
  7. class Character {
  8. private:
  9. char name[128];
  10. char type[128];
  11. public:
  12. Character(const char* Name, const char* Type) {
  13. strcpy_s(name, Name);
  14. strcpy_s(type, Type);
  15. }
  16. const char* GetType() const {
  17. return type;
  18. }
  19. const char* GetName() const {
  20. return name;
  21. }
  22. virtual void Draw() {
  23. cout <<"Type: "<< type << ", Name: " << name;
  24. }
  25. };
  26.  
  27. class Warrior :public Character {
  28. private:
  29. double armorlvl;
  30. public:
  31. Warrior(const char* Name, double armorlvl) :Character(Name, "Warrior") {
  32. this->armorlvl = armorlvl;
  33. };
  34. void SetArmorlvl() {
  35. this->armorlvl = armorlvl;
  36. }
  37. double GetArmorlvl() {
  38. return armorlvl;
  39. }
  40. virtual void Draw() {
  41. Character::Draw();
  42. cout << ", Armorlvl: " << armorlvl;
  43. }
  44. };
  45.  
  46. class Enemy :public Character {
  47. private:
  48. double strength;
  49. int concurrentwarriors;
  50. public:
  51. Enemy(const char* Name, double strength, int concurrentwarriors) :Character(Name, "Enemy") {
  52. this->strength = strength;
  53. this->concurrentwarriors = concurrentwarriors;
  54. };
  55. void SetStrength() {
  56. this->strength = strength;
  57. }
  58. double GetStrength() {
  59. return strength;
  60. }
  61. int GetConcurrentWarriors() {
  62. return concurrentwarriors;
  63. }
  64. virtual void Draw() {
  65. Character::Draw();
  66. cout << ", Stength: " << strength << ", ConcurrentWarriors: " << concurrentwarriors;
  67. }
  68. };
  69.  
  70. int main() {
  71. const int charactersCount = 6;
  72. Character* characters[charactersCount] = {};
  73.  
  74. characters[0] = new Warrior("Batman", 10.2);
  75. characters[1] = new Enemy("Joker",5.1,3);
  76. characters[2] = new Warrior("Superman",55.3);
  77. characters[3] = new Enemy("Ultra-Humanite",17.2,10);
  78. characters[4] = new Warrior("Daredevil",33.7);
  79. characters[5] = new Enemy("Wilson Flask", 3.1, 10);
  80.  
  81. for (int i = 0; i < charactersCount; i++) {
  82. characters[i]->Draw();
  83. cout << endl;
  84. }
  85.  
  86. for (int i = 0; i < charactersCount; i++) {
  87. if (characters[i])
  88. delete characters[i];
  89. }
  90. _getch();
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement