Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.16 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <string.h>
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. enum type {Earth, Air, EarthAir};
  10.  
  11. class Tower             // klasa podstawowa wieży, za pomocą, której będą opisywane klasy pochodne wież
  12. {
  13.     unsigned int level, strength, range, speed, cost;       //
  14.     type Tower_type;                                        //  zmienne podstawowe wspólne dla wszystkich typów wież, opisujące ich cechy
  15.     string name;                                            //
  16. public:
  17.     Tower();                                                // konstruktor domyślny - póki co nie wykorzystywany
  18.     Tower(const string _name, unsigned int level, unsigned int strength, unsigned int range, unsigned int speed, unsigned int cost, type Tower_type);       // konstruktor parametryczny
  19.     ~Tower();                                   // destruktor
  20.     void DisplayStats() const;                  // wyświetlanie danych wieży
  21.     void LevelUp(unsigned int level, unsigned int strength, unsigned int range, unsigned int speed, unsigned int cost);         // metoda odpowiedzialna za ulepszanie wieży
  22. };
  23.  
  24. Tower::Tower(const string _name, unsigned int level, unsigned int strength, unsigned int range, unsigned int speed, unsigned int cost, type Tower_type) : name(_name), level(level), strength(strength), range(range), speed(speed), cost(cost), Tower_type(Tower_type)     // konstruktor parametryczny
  25. {
  26.     //this->name =_name;
  27.     //this->level = level;
  28.     //this->strength = strength;
  29.     //this->range = range;
  30.     //this->speed = speed;
  31.     //this->cost = cost;
  32.     //this->Tower_type = Tower_type;
  33. }
  34. void Tower::DisplayStats() const            // wyświetlanie danych wieży
  35. {
  36.     char *_Tower_Type;                      // zmienna tymczasowa potrzebna do wyświetlenia (nazwy) typu wieży
  37.     switch(Tower_type)                      // typ wyliczeniowy działa na liczbach; Earth ma indeks 0 w enumeratorze, Air ma indeks 1, EarthAir ma indeks 2.
  38.     {
  39.         case 0 : {_Tower_Type = "Ziemia"; break;}
  40.         case 1 : {_Tower_Type = "Powietrze"; break;}
  41.         case 2 : {_Tower_Type = "Ziemia/Powietrze"; break;}
  42.     }                                                               // w zależności jaki nr indeksu ma wieża, do zmiennej tymczasowej wpisujemy nazwę odpowiednią i używamy ją poniżej do wyświetlenia wraz z pozostałymi danymi wieży
  43.     cout << "Statystyki wiezy: " << endl << "Poziom: " << level << endl << "Sila: " << strength << endl << "Zasieg: " << range << endl << "Szybkosc: " << speed << endl << "Koszt: " << cost << endl << "Typ: " << _Tower_Type << endl << endl;
  44. }
  45. void Tower::LevelUp(unsigned int level, unsigned int strength, unsigned int range, unsigned int speed, unsigned int cost)       // metoda odpowiedzialna za ulepszanie wieży
  46. {
  47.     this->level++;
  48.     this->strength += strength;
  49.     this->range += range;
  50.     this->speed += speed;
  51.     this->cost += cost;
  52. }
  53.  
  54. Tower::~Tower()             // destruktor - póki co niewykorzystywany
  55. {
  56. }
  57.  
  58. class MagicTower : public Tower     // klasa wieży magicznej dziedziczy po klasie podstawowej Tower w sposób publiczny, czyli zachowuje taki sam poziom dostepu do pól klasy
  59. {
  60. public:
  61.     MagicTower();
  62.     MagicTower(const string _name, unsigned int level, unsigned int strength, unsigned int range, unsigned int speed, unsigned int cost, type Tower_type);              // konstruktor domyślny
  63.     ~MagicTower();              // destruktor
  64. };
  65.  
  66. MagicTower::MagicTower(const string _name, unsigned int level, unsigned int strength, unsigned int range, unsigned int speed, unsigned int cost, type Tower_type) : Tower(_name, level, strength, range, speed, cost, Tower_type)
  67. {
  68. }
  69. //MagicTower::MagicTower(string _name, unsigned short level, unsigned short strength, unsigned short range, unsigned short speed, unsigned short cost, type Tower_type);                    // konstruktor domyślny klasy wieży magicznej
  70. //{
  71. //  Tower::Tower("wieża magiczna", 1, 3, 3, 2, 30, Air);       // wewnątrz wywołujemy konstruktor parametryczny klasy wieży podstawowej i przekazujemy dane odpowiednie dla wieży magicznej
  72. //}
  73.  
  74.  
  75. MagicTower::~MagicTower()                   //destruktor - póki co niewykorzystywany
  76. {
  77. }
  78.  
  79. int _tmain(int argc, _TCHAR* argv[])
  80. {
  81.     const string Magictower = "wieza_magiczna";
  82.     const string Earthtower = "wieza_naziemna";
  83.  
  84.     Tower wieza_podstawowa(Earthtower, 1, 3, 3, 2, 20, Earth);
  85.     MagicTower wieza_magiczna(Magictower, 1, 3, 3, 2, 30, Air);
  86.     wieza_podstawowa.DisplayStats();
  87.     wieza_magiczna.DisplayStats();
  88.     _getch();
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement