Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. // nowyswojnaPO.cpp : Defines the entry point for the console application.
  2. //
  3. #define _CRT_SECURE_NO_WARNINGS
  4. #include "stdafx.h"
  5. #include <conio.h>
  6. #include <string>
  7. #include <iostream>
  8. #include <Windows.h>
  9. #include <exception>
  10.  
  11. using namespace std;
  12.  
  13. class WypierdalaBladStrenght :public exception {
  14. public:
  15. virtual const char* what() const throw()
  16. {
  17. return "nie moze byc kurwa za mala sila chuju\n";
  18. }
  19. };
  20.  
  21.  
  22. class Character {
  23. char Type[128];
  24. char Name[128];
  25. public:
  26. Character(char* _Type, char* _Name) {
  27. strcpy(Type, _Type);
  28. Type[128] = '\0';
  29. strcpy(Name, _Name);
  30. Name[128] = '\0';
  31. }
  32. char GetType() const { return *Type; }
  33. char GetName() const { return *Name; }
  34. virtual void Draw() = 0 {
  35. cout << "Type: " << Type << ", Name: " << Name << ", ";
  36. }
  37. };
  38.  
  39. class Warrior :public Character {
  40. float Armor;
  41. public:
  42. Warrior(char* _Name, float _Armor) :Character("Warrior", _Name), Armor(_Armor) {}
  43. float GetArmor() const { return Armor; }
  44. float SetArmor(int VolArmor) {
  45. Armor = VolArmor;
  46. return VolArmor;
  47. }
  48. virtual void Draw() {
  49. Character::Draw();
  50. cout << "ArmorLevel: " << Armor << endl;
  51. }
  52. };
  53.  
  54. class Enemy :public Character {
  55. float Strenght;
  56. int ConcurrentWarriors;
  57. public:
  58. Enemy(char* _Name,float _Strenght, int _ConcurrentWarriors) :Character("Enemy",_Name), ConcurrentWarriors(_ConcurrentWarriors)
  59. {
  60. if (Strenght < 0) throw WypierdalaBladStrenght();
  61. Strenght = _Strenght;
  62. }
  63. float GetStrenght() const { return Strenght; }
  64. float SetStrenght(float VolStrenght) {
  65. Strenght = VolStrenght;
  66. return VolStrenght;
  67. }
  68. int GetConcurrentWarriors() const { return ConcurrentWarriors; }
  69. virtual void Draw() {
  70. Character::Draw();
  71. cout << "Strenght: " << Strenght << ", ConcurrentWarriors: " << ConcurrentWarriors << endl;
  72. }
  73. };
  74.  
  75. int main()
  76. {
  77. const int CharacterCount = 6;
  78. Character* characters[CharacterCount] = {};
  79.  
  80. characters[0] = new Warrior("Batman", 10.2);
  81. characters[1] = new Enemy("Joker", 10.2, 3);
  82. characters[2] = new Warrior("Papryk", 1000);
  83. characters[3] = new Enemy("Pasierb_CHUJ", 0.01, 1);
  84. characters[4] = new Warrior("Bialy_Power_Ranger", 10.2);
  85. characters[5] = new Enemy("Czarni_Kitowcy", 5.25, 5);
  86.  
  87. try
  88. {
  89. Enemy postac("Pasierb", 12, 1);
  90. }
  91. catch (WypierdalaBladStrenght &blad)
  92. {
  93. cout << "wystapil blad: " << blad.what();
  94. }
  95.  
  96. for (unsigned int i = 0; i < CharacterCount; ++i) {
  97. characters[i]->Draw();
  98. }
  99.  
  100. for (unsigned int i = 0; i < CharacterCount; ++i) {
  101. if(characters[i]) delete characters[i];
  102. }
  103.  
  104. system("pause");
  105. _getch();
  106. return 0;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement