Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #include <iostream>
- using namespace std;
- enum type {Earth, Air, EarthAir};
- class Tower // klasa podstawowa wieży, za pomocą, której będą opisywane klasy pochodne wież
- {
- unsigned int level, strength, range, speed, cost; //
- type Tower_type; // zmienne podstawowe wspólne dla wszystkich typów wież, opisujące ich cechy
- string name; //
- public:
- Tower(); // konstruktor domyślny - póki co nie wykorzystywany
- Tower(const string _name, unsigned int level, unsigned int strength, unsigned int range, unsigned int speed, unsigned int cost, type Tower_type); // konstruktor parametryczny
- ~Tower(); // destruktor
- void DisplayStats() const; // wyświetlanie danych wieży
- void LevelUp(unsigned int level, unsigned int strength, unsigned int range, unsigned int speed, unsigned int cost); // metoda odpowiedzialna za ulepszanie wieży
- };
- 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
- {
- //this->name =_name;
- //this->level = level;
- //this->strength = strength;
- //this->range = range;
- //this->speed = speed;
- //this->cost = cost;
- //this->Tower_type = Tower_type;
- }
- void Tower::DisplayStats() const // wyświetlanie danych wieży
- {
- char *_Tower_Type; // zmienna tymczasowa potrzebna do wyświetlenia (nazwy) typu wieży
- switch(Tower_type) // typ wyliczeniowy działa na liczbach; Earth ma indeks 0 w enumeratorze, Air ma indeks 1, EarthAir ma indeks 2.
- {
- case 0 : {_Tower_Type = "Ziemia"; break;}
- case 1 : {_Tower_Type = "Powietrze"; break;}
- case 2 : {_Tower_Type = "Ziemia/Powietrze"; break;}
- } // 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
- cout << "Statystyki wiezy: " << endl << "Poziom: " << level << endl << "Sila: " << strength << endl << "Zasieg: " << range << endl << "Szybkosc: " << speed << endl << "Koszt: " << cost << endl << "Typ: " << _Tower_Type << endl << endl;
- }
- void Tower::LevelUp(unsigned int level, unsigned int strength, unsigned int range, unsigned int speed, unsigned int cost) // metoda odpowiedzialna za ulepszanie wieży
- {
- this->level++;
- this->strength += strength;
- this->range += range;
- this->speed += speed;
- this->cost += cost;
- }
- Tower::~Tower() // destruktor - póki co niewykorzystywany
- {
- }
- 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
- {
- public:
- MagicTower();
- 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
- ~MagicTower(); // destruktor
- };
- 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)
- {
- }
- //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
- //{
- // 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
- //}
- MagicTower::~MagicTower() //destruktor - póki co niewykorzystywany
- {
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- const string Magictower = "wieza_magiczna";
- const string Earthtower = "wieza_naziemna";
- Tower wieza_podstawowa(Earthtower, 1, 3, 3, 2, 20, Earth);
- MagicTower wieza_magiczna(Magictower, 1, 3, 3, 2, 30, Air);
- wieza_podstawowa.DisplayStats();
- wieza_magiczna.DisplayStats();
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement