Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication33-2.cpp : Defines the entry point for the console application.
- //
- // ConsoleApplication33.cpp : Defines the entry point for the console application.
- //
- // ConsoleApplication32.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string>
- #include <fstream>
- #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, 128, _name);
- strcpy_s(type, 128, _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:
- float armorlvl;
- public:
- Warrior(const char* _name, float armorlvl) : Character(_name, "Warrior") { this->armorlvl = armorlvl; }
- void SetArmorlvl()
- {
- this->armorlvl = armorlvl;
- }
- float GetArmorlvl()
- {
- return armorlvl;
- }
- void Draw()
- {
- Character::Draw();
- cout << " Poziom panczerza: " << armorlvl;
- }
- };
- class Enemy : public Character
- {
- private:
- int bohaterowie;
- float strenght;
- public:
- Enemy(const char* _name, float strenght, int bohaterowie) : Character(_name, "Enemy") { this->strenght = strenght;this->bohaterowie = bohaterowie; }
- void SetStrenght(float strenght, int bohaterowie)
- {
- this->bohaterowie = bohaterowie;
- this->strenght = strenght;
- }
- float GetStrenght()
- {
- return bohaterowie;
- return strenght;
- }
- void Draw()
- {
- Character::Draw();
- cout << " Strenght:" << strenght << " Ilosc Bohaterow: " << bohaterowie;
- }
- };
- int main()
- {
- fstream Plik;
- Plik.open("plik.txt", ios::in);
- string typ, nazwa;
- float pom, pom2;
- int pom3 = 0;
- const int lenght = 5;
- std::ifstream inFile("plik.txt");
- //const int l = (std::count(std::istreambuf_iterator<char>(inFile),std::istreambuf_iterator<char>(), '\n'))/2;
- Character* characters[10] = {};
- if (Plik.good() == true)
- {
- while (!Plik.eof())
- {
- Plik >> typ;
- Plik >> nazwa >> pom;
- if (typ == "Bohater")
- {
- characters[pom3] = new Warrior(nazwa.c_str(), pom);
- }
- if (typ == "Enemy")
- {
- characters[pom3] = new Enemy(nazwa.c_str(), pom, 0);
- }
- pom3++;
- }
- Plik.close();
- }
- for (int i = 0;i < pom3-1;i++)
- {
- characters[i]->Draw();
- cout << endl;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement