Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // nowyswojnaPO.cpp : Defines the entry point for the console application.
- //
- #define _CRT_SECURE_NO_WARNINGS
- #include "stdafx.h"
- #include <conio.h>
- #include <string>
- #include <iostream>
- #include <Windows.h>
- #include <exception>
- using namespace std;
- class WypierdalaBladStrenght :public exception {
- public:
- virtual const char* what() const throw()
- {
- return "nie moze byc kurwa za mala sila chuju\n";
- }
- };
- class Character {
- char Type[128];
- char Name[128];
- public:
- Character(char* _Type, char* _Name) {
- strcpy(Type, _Type);
- Type[128] = '\0';
- strcpy(Name, _Name);
- Name[128] = '\0';
- }
- char GetType() const { return *Type; }
- char GetName() const { return *Name; }
- virtual void Draw() = 0 {
- cout << "Type: " << Type << ", Name: " << Name << ", ";
- }
- };
- class Warrior :public Character {
- float Armor;
- public:
- Warrior(char* _Name, float _Armor) :Character("Warrior", _Name), Armor(_Armor) {}
- float GetArmor() const { return Armor; }
- float SetArmor(int VolArmor) {
- Armor = VolArmor;
- return VolArmor;
- }
- virtual void Draw() {
- Character::Draw();
- cout << "ArmorLevel: " << Armor << endl;
- }
- };
- class Enemy :public Character {
- float Strenght;
- int ConcurrentWarriors;
- public:
- Enemy(char* _Name,float _Strenght, int _ConcurrentWarriors) :Character("Enemy",_Name), ConcurrentWarriors(_ConcurrentWarriors)
- {
- if (Strenght < 0) throw WypierdalaBladStrenght();
- Strenght = _Strenght;
- }
- float GetStrenght() const { return Strenght; }
- float SetStrenght(float VolStrenght) {
- Strenght = VolStrenght;
- return VolStrenght;
- }
- int GetConcurrentWarriors() const { return ConcurrentWarriors; }
- virtual void Draw() {
- Character::Draw();
- cout << "Strenght: " << Strenght << ", ConcurrentWarriors: " << ConcurrentWarriors << endl;
- }
- };
- int main()
- {
- const int CharacterCount = 6;
- Character* characters[CharacterCount] = {};
- characters[0] = new Warrior("Batman", 10.2);
- characters[1] = new Enemy("Joker", 10.2, 3);
- characters[2] = new Warrior("Papryk", 1000);
- characters[3] = new Enemy("Pasierb_CHUJ", 0.01, 1);
- characters[4] = new Warrior("Bialy_Power_Ranger", 10.2);
- characters[5] = new Enemy("Czarni_Kitowcy", 5.25, 5);
- try
- {
- Enemy postac("Pasierb", 12, 1);
- }
- catch (WypierdalaBladStrenght &blad)
- {
- cout << "wystapil blad: " << blad.what();
- }
- for (unsigned int i = 0; i < CharacterCount; ++i) {
- characters[i]->Draw();
- }
- for (unsigned int i = 0; i < CharacterCount; ++i) {
- if(characters[i]) delete characters[i];
- }
- system("pause");
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement