#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <fstream>
using namespace std;
class Character
{
private:
int _hp;
string _nazwa;
public:
void setHp(int hp)
{
_hp = hp;
}
int getHp()
{
return _hp;
}
void setName(string nazwa)
{
_nazwa = nazwa;
}
string getName()
{
return _nazwa;
}
string to_String()
{
stringstream s;
s << "Postac nazywa sie " << _nazwa << " i ma " << _hp << " punktow zycia" << endl;
return s.str();
}
};
class CharacterEditor
{
private:
vector<Character> characters;
public:
Character createCharacter() // tworzenie postaci
{
Character temp;
cout << "Podaj nazwe: ";
string nazwa;
cin >> nazwa;
cout << "Podaj ilosc zycia: ";
int hp;
cin >> hp;
temp.setName(nazwa);
temp.setHp(hp);
characters.push_back(temp);
return temp;
}
string to_String() // tworzy jeden spojny string
{
cout << "Nasze postacie:" << endl;
stringstream s;
for (unsigned int i = 0; i < characters.size(); i++)
{
s << characters[i].to_String();
}
return s.str();
}
void saveToFile(string zapis) // zapisywanie postaci
{
fstream plik;
plik.open(zapis, ios::out);
for (unsigned int i = 0; i < characters.size(); i++)
{
plik << characters[i].getName();
plik << ":";
plik << characters[i].getHp() << ";" << endl; // rozdzielenie elementów obiektu dwukropek, koniec obiektu średnik;
}
plik.close();
}
void loadFromFile(string wczytaj) // wczytywanie postaci
{
characters.clear();
int y = 0;
string linia, tekst, tekst2;
fstream plik2;
plik2.open(wczytaj, ios::in);
if (plik2.good() == false)
{
cout << "Plik nie istnieje!" << endl;
}
while (getline(plik2, linia))
{
Character temp;
tekst = "";
tekst2 = "";
size_t dwukropek_pozycja = linia.find(':');
size_t srednik_pozycja = linia.find(';');
tekst.insert(0, linia, 0, dwukropek_pozycja);
tekst2.insert(0, linia, dwukropek_pozycja + 1, srednik_pozycja - dwukropek_pozycja - 1);
y = atoi(tekst2.c_str());
temp.setName(tekst);
temp.setHp(y);
characters.push_back(temp);
}
plik2.close();
}
};
int main()
{
CharacterEditor postacie;
char wybor = 'a';
for (;;)
{
cout << endl;
cout << "MENU GLOWNE" << endl;
cout << "-----------------" << endl;
cout << "1. Dodaj postac" << endl;
cout << "2. Zapisz" << endl;
cout << "3. Wczytaj" << endl;
cout << "4. Wyswietl postacie" << endl;
cout << "5. Koniec programu" << endl;
cout << endl;
wybor = getchar();
switch (wybor)
{
case '1':
postacie.createCharacter();
break;
case '2':
postacie.saveToFile("postacie.dat");
break;
case '3':
postacie.loadFromFile("postacie.dat");
break;
case '4':
postacie.to_String();
system("pause");
break;
case '5':
exit(0);
break;
default: cout << "Nie ma takiej opcji w menu!";
}
cin.get();
system("cls");
}
cin.get();
cin.get();
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}