Advertisement
Guest User

Boss_fight

a guest
May 25th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. MAIN
  2. #include <iostream>
  3. #include "Postacie.h"
  4.  
  5. int main(int argc, char *argv[]) {
  6. cout << "TEST" << endl;
  7. Healer resto;
  8. Tank guardian;
  9. Dps feral;
  10. Boss Smok(30, 18, 30, 30);
  11. cout << resto.opis() << endl;
  12. cout << guardian.opis() << endl;
  13. cout << feral.opis() << endl;
  14.  
  15. //Ustalenie kolejności ataku
  16. int tab_zre[3] = {guardian.zre(), feral.zre(), Smok.zre()};
  17. int kolejnosc[3] = {1, 2, 3};
  18. for(int i = 0; i < 3; i++) {
  19. for(int j = 0; j < 2; j++) {
  20. if(tab_zre[j] < tab_zre[j+1]) {
  21. swap(tab_zre[j], tab_zre[j+1]);
  22. swap(kolejnosc[j], kolejnosc[j+1]);
  23. }
  24. }
  25. }
  26.  
  27. for(int i = 0; i < 3; i++) cout << tab_zre[i] << " " << kolejnosc[i] << endl;
  28.  
  29. while(Smok.hp() > 0) {
  30. static int x = 0;
  31. if(kolejnosc[x] == 1) {
  32. cout << "Atakuje guardian" << endl;
  33. Smok.dmg(rand()%10);
  34. }
  35. else if(kolejnosc[x] == 2) {
  36. cout << "Atakuje feral" << endl;
  37. Smok.dmg(rand()%10);
  38. }
  39. else if(kolejnosc[x] == 3) {
  40. cout << "Atakuje Smok" << endl;
  41. }
  42. if(x == 3) cout << "Leczy healer" << endl;
  43. x++;
  44. if(x == 3) x = 0; // każdy atakował -> kolejka od nowa
  45. }
  46. }
  47.  
  48. Postacie.cpp
  49.  
  50. #include "Postacie.h"
  51. #include <stdlib.h>
  52. #include <stdio.h>
  53.  
  54.  
  55. Bohater::Bohater() {
  56. srand(time(NULL));
  57. _intel = rand()%30;
  58. _sila = rand()%30;
  59. _wytrz = rand()%30;
  60. _zre = rand()%30;
  61. _kryt = rand()%30;
  62. }
  63.  
  64. string Bohater::opis() {
  65. return "| Klasa | HP | ATAK | UNIK | BLOK |\n| " + _klasa + " | " + to_string(_hp) + " | " + to_string(_atak.moc) + " | " + to_string(_unik) + " | " + " |\n";
  66. }
  67.  
  68. Healer::Healer() {
  69. _klasa = "Healer";
  70. _hp = _wytrz * 10;
  71. _atak.moc = _intel * 2;
  72. _atak.szansa = rand()%100;
  73. _unik = _zre * 2;
  74. }
  75.  
  76. Tank::Tank() {
  77. _klasa = "Tank";
  78. _hp = _wytrz * 20;
  79. _atak.moc = _sila * 5;
  80. _atak.szansa = rand()%100;
  81. _unik = _zre * 5;
  82. _blok.moc = (_wytrz + _zre) * 2;
  83. _blok.szansa = rand()%100;
  84. }
  85.  
  86. Dps::Dps() {
  87. _klasa = "Dps";
  88. _hp = _wytrz * 7;
  89. _atak.moc = (_sila + _zre) * 4;
  90. _atak.szansa = rand()%100;
  91. _unik = _zre * 8;
  92. }
  93.  
  94. Boss::Boss(int sila, int zre, int hp, int ulti) {
  95. _sila = sila;
  96. _zre = zre;
  97. _hp = hp;
  98. _ulti = ulti;
  99. }
  100.  
  101. Postacie.h
  102.  
  103. #include <string>
  104. using namespace std;
  105.  
  106. struct parametr {
  107. int moc, szansa;
  108. };
  109.  
  110. class Bohater {
  111. protected:
  112. string _klasa;
  113. int _intel;
  114. int _sila;
  115. int _wytrz;
  116. int _zre;
  117. int _kryt;
  118. int _hp;
  119. parametr _atak;
  120. int _unik;
  121. parametr _blok;
  122. parametr _prowokacja;
  123. public:
  124. Bohater();
  125. string klasa() { return _klasa; }
  126. int intel() { return _intel; }
  127. int sila() { return _sila; }
  128. int wytrz() { return _wytrz; }
  129. int zre() { return _zre; }
  130. int kryt() { return _kryt; }
  131. int hp() { return _hp; }
  132. parametr atak() { return _atak; }
  133. int unik() { return _unik; }
  134. parametr blok() { return _blok; }
  135. int dmg(int ile) { _hp -= ile; }
  136. string opis();
  137. };
  138.  
  139. class Healer :public Bohater { public: Healer(); };
  140. class Tank :public Bohater { public: Tank(); };
  141. class Dps :public Bohater { public: Dps(); };
  142.  
  143. class Boss {
  144. int _sila;
  145. int _zre;
  146. int _hp;
  147. int _ulti; // szansa na użycie ulta
  148. public:
  149. Boss(int sila, int zre, int hp, int ulti);
  150. int sila() { return _sila; }
  151. int zre() { return _zre; }
  152. int hp() { return _hp; }
  153. int ulti() { return _ulti; }
  154. int dmg(int ile) { _hp -= ile; }
  155. };
  156.  
  157. Makefile
  158.  
  159. all:
  160. g++ -std=c++0x *.cpp -o Boss_fight
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement