Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <string.h>
- #include <conio.h>
- using namespace std;
- class Character {
- private:
- char name[128];
- char type[128];
- public:
- Character(const char* Name, const char* Type) {
- strcpy_s(name, Name);
- strcpy_s(type, Type);
- }
- const char* GetType() const {
- return type;
- }
- const char* GetName() const {
- return name;
- }
- virtual void Draw() {
- cout <<"Type: "<< type << ", Name: " << name;
- }
- };
- class Warrior :public Character {
- private:
- double armorlvl;
- public:
- Warrior(const char* Name, double armorlvl) :Character(Name, "Warrior") {
- this->armorlvl = armorlvl;
- };
- void SetArmorlvl() {
- this->armorlvl = armorlvl;
- }
- double GetArmorlvl() {
- return armorlvl;
- }
- virtual void Draw() {
- Character::Draw();
- cout << ", Armorlvl: " << armorlvl;
- }
- };
- class Enemy :public Character {
- private:
- double strength;
- int concurrentwarriors;
- public:
- Enemy(const char* Name, double strength, int concurrentwarriors) :Character(Name, "Enemy") {
- this->strength = strength;
- this->concurrentwarriors = concurrentwarriors;
- };
- void SetStrength() {
- this->strength = strength;
- }
- double GetStrength() {
- return strength;
- }
- int GetConcurrentWarriors() {
- return concurrentwarriors;
- }
- virtual void Draw() {
- Character::Draw();
- cout << ", Stength: " << strength << ", ConcurrentWarriors: " << concurrentwarriors;
- }
- };
- int main() {
- const int charactersCount = 6;
- Character* characters[charactersCount] = {};
- characters[0] = new Warrior("Batman", 10.2);
- characters[1] = new Enemy("Joker",5.1,3);
- characters[2] = new Warrior("Superman",55.3);
- characters[3] = new Enemy("Ultra-Humanite",17.2,10);
- characters[4] = new Warrior("Daredevil",33.7);
- characters[5] = new Enemy("Wilson Flask", 3.1, 10);
- for (int i = 0; i < charactersCount; i++) {
- characters[i]->Draw();
- cout << endl;
- }
- for (int i = 0; i < charactersCount; i++) {
- if (characters[i])
- delete characters[i];
- }
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement