Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- struct savedinfo
- {
- std::string character_name;
- int level;
- long exp_to_next_level;
- std::string type_of_weapon;
- std::string mount_name;
- long defeated_enemies;
- int buddies;
- };
- void save_game(savedinfo sv);
- savedinfo load_game(savedinfo kek);
- int main()
- {
- savedinfo your_char;
- std::cout << "Dane z poprzedniej gry: \n";
- std::cout << "Postac " << your_char.character_name << ", poziom " << your_char.level << ",\n";
- std::cout << "Uzywana bron: " << your_char.type_of_weapon << ", imie wierzchowca: " << your_char.mount_name << ",\n";
- std::cout << "Pokonani przeciwnicy: " << your_char.defeated_enemies << ", odblokowani towarzysze: " << your_char.buddies << ",\n";
- std::cout << "Doswiadczenie do nastepnego poziomu: " << your_char.exp_to_next_level << "\n";
- save_game(your_char);
- return 0;
- }
- void save_game(savedinfo sv)
- {
- std::ofstream savinggame;
- savinggame.open("savegame.txt");
- std::cout << "Podaj imie postaci: ";
- getline(std::cin, sv.character_name);
- std::cin.clear();
- std::cout << "Podaj poziom postaci: ";
- std::cin >> sv.level;
- std::cin.clear();
- std::cout << "Podaj ilosc doswiadczenia do nastepnego poziomu: ";
- std::cin >> sv.exp_to_next_level;
- std::cin.clear();
- std::cin.clear();
- std::cout << "Podaj rodzaj broni: ";
- getline(std::cin, sv.type_of_weapon);
- std::cin.clear();
- std::cout << "Podaj imie wierzchowca: ";
- getline(std::cin, sv.mount_name);
- std::cin.clear();
- std::cout << "Podaj liczbe pokonanych wrogow: ";
- std::cin >> sv.defeated_enemies;
- std::cin.clear();
- std::cout << "Podaj liczbe odblokowanych towarzyszy: ";
- std::cin >> sv.buddies;
- std::cout << "Trwa zapisywanie...";
- savinggame << sv.character_name << "\n";
- savinggame << sv.level << "\n";
- savinggame << sv.exp_to_next_level << "\n";
- savinggame << sv.type_of_weapon << "\n";
- savinggame << sv.mount_name << "\n";
- savinggame << sv.defeated_enemies << "\n";
- savinggame << sv.buddies << "\n";
- savinggame.close();
- }
- savedinfo load_game(savedinfo kek)
- {
- std::ifstream loadinggame;
- loadinggame.open("savegame.txt");
- getline(loadinggame, kek.character_name);
- loadinggame >> kek.level;
- loadinggame >> kek.exp_to_next_level;
- getline(loadinggame, kek.type_of_weapon);
- getline(loadinggame, kek.mount_name);
- loadinggame >> kek.defeated_enemies;
- loadinggame >> kek.buddies;
- loadinggame.close();
- return kek;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement