Advertisement
Guest User

Untitled

a guest
May 20th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. // ConsoleApplication33-2.cpp : Defines the entry point for the console application.
  2. //
  3. // ConsoleApplication33.cpp : Defines the entry point for the console application.
  4. //
  5.  
  6. // ConsoleApplication32.cpp : Defines the entry point for the console application.
  7. //
  8.  
  9. #include "stdafx.h"
  10. #include <iostream>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string>
  14. #include <fstream>
  15. #include <conio.h>
  16.  
  17. using namespace std;
  18. class Character
  19. {
  20. private:
  21. char name[128];
  22. char type[128];
  23. public:
  24. Character(const char *_name, const char * _type)
  25. {
  26. strcpy_s(name, 128, _name);
  27. strcpy_s(type, 128, _type);
  28. }
  29. const char * GetType() const
  30. {
  31. return type;
  32. }
  33. const char * GetName() const
  34. {
  35. return name;
  36. }
  37. virtual void Draw()
  38. {
  39. cout << " Type: " << type << " Name: " << name;
  40.  
  41. }
  42.  
  43. };
  44.  
  45. class Warrior : public Character
  46. {
  47. private:
  48. float armorlvl;
  49. public:
  50. Warrior(const char* _name, float armorlvl) : Character(_name, "Warrior") { this->armorlvl = armorlvl; }
  51. void SetArmorlvl()
  52. {
  53. this->armorlvl = armorlvl;
  54. }
  55. float GetArmorlvl()
  56. {
  57. return armorlvl;
  58. }
  59. void Draw()
  60. {
  61. Character::Draw();
  62. cout << " Poziom panczerza: " << armorlvl;
  63. }
  64. };
  65. class Enemy : public Character
  66. {
  67. private:
  68. int bohaterowie;
  69. float strenght;
  70. public:
  71. Enemy(const char* _name, float strenght, int bohaterowie) : Character(_name, "Enemy") { this->strenght = strenght;this->bohaterowie = bohaterowie; }
  72. void SetStrenght(float strenght, int bohaterowie)
  73. {
  74. this->bohaterowie = bohaterowie;
  75. this->strenght = strenght;
  76. }
  77. float GetStrenght()
  78. {
  79. return bohaterowie;
  80. return strenght;
  81. }
  82. void Draw()
  83. {
  84. Character::Draw();
  85. cout << " Strenght:" << strenght << " Ilosc Bohaterow: " << bohaterowie;
  86. }
  87. };
  88.  
  89. int main()
  90. {
  91. fstream Plik;
  92. Plik.open("plik.txt", ios::in);
  93. string typ, nazwa;
  94. float pom, pom2;
  95. int pom3 = 0;
  96. const int lenght = 5;
  97. std::ifstream inFile("plik.txt");
  98. //const int l = (std::count(std::istreambuf_iterator<char>(inFile),std::istreambuf_iterator<char>(), '\n'))/2;
  99. Character* characters[10] = {};
  100. if (Plik.good() == true)
  101. {
  102. while (!Plik.eof())
  103. {
  104. Plik >> typ;
  105. Plik >> nazwa >> pom;
  106. if (typ == "Bohater")
  107. {
  108. characters[pom3] = new Warrior(nazwa.c_str(), pom);
  109. }
  110. if (typ == "Enemy")
  111. {
  112. characters[pom3] = new Enemy(nazwa.c_str(), pom, 0);
  113.  
  114. }
  115. pom3++;
  116. }
  117. Plik.close();
  118. }
  119. for (int i = 0;i < pom3-1;i++)
  120. {
  121. characters[i]->Draw();
  122. cout << endl;
  123. }
  124.  
  125. system("pause");
  126. return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement