Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <string>
- #include <iostream>
- #include <fstream>
- using namespace std;
- class Character {
- private:
- char name[128];
- char type[128];
- protected:
- Character(const char* nameVal, const char* typeVal) {
- strcpy(name, nameVal);
- strcpy(type, typeVal);
- }
- public:
- char* const getName() { //Zwraca wskaznik na łańcuch znaków char* = string
- return name;
- }
- char* const getType() {
- return type;
- }
- virtual void Draw(){ //wystarczy virutal w klasie bazowej
- cout << name << " " << type << endl;
- }
- };
- class Warrior : public Character {
- private:
- double armorLevel;
- public:
- Warrior(const char* nameVal, const double armorLevelVal)
- : Character(nameVal, "Warrior")
- {
- if (armorLevelVal > 0) {
- armorLevel = armorLevelVal;
- }
- }
- double const getArmorLevel() {
- return armorLevel;
- }
- void setArmorLevel(const double armorLevelVal) {
- armorLevel = armorLevelVal;
- }
- virtual void Draw() {
- Character::Draw();
- cout << armorLevel << endl;
- }
- };
- class Enemy : public Character {
- private:
- double strength;
- int concurrentWarriors;
- public:
- Enemy(const char* nameVal, const double strengthVal, const int concurrentWarriorsVal)
- : Character(nameVal, "Enemy")
- {
- strength = strengthVal;
- concurrentWarriors = concurrentWarriorsVal;
- }
- double const GetStrength()
- {
- return strength;
- }
- void SetStrength(const double strengthVal)
- {
- strength = strengthVal;
- }
- int const GetconcurrentWarriors()
- {
- return concurrentWarriors;
- }
- virtual void Draw()
- {
- Character::Draw();
- cout << strength << " " << concurrentWarriors << endl;
- }
- };
- int main()
- {
- const int charactersCount = 255;
- Character* characters[charactersCount] = {};
- char typeTMP[128];
- char nameTMP[128];
- double valueWarrior;
- double valueEnemy;
- int valueEnemy_2;
- ifstream file("kubusblant.txt");
- if (!(file.is_open()))
- {
- cout << "Blad otwarcia pliku" << endl;
- }
- int j = 0;
- while (!(file.eof())) {
- file >> typeTMP >> nameTMP;
- if (strcmp(typeTMP, "Warrior") == 0)
- {
- file >> valueWarrior;
- characters[j] = new Warrior(nameTMP, valueWarrior);
- }
- if (strcmp(typeTMP, "Enemy") == 0)
- {
- file >> valueEnemy >> valueEnemy_2;
- characters[j] = new Enemy(nameTMP, valueEnemy, valueEnemy_2);
- }
- j++;
- }
- for (int i = 0; i < j; i++) {
- characters[i]->Draw();
- }
- for (int i = 0; i < j; i++) {
- if (characters[i])
- delete characters[i];
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement