Advertisement
Sachees

nie wchodzic

Nov 29th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. struct savedinfo
  5. {
  6. std::string character_name;
  7. int level;
  8. long exp_to_next_level;
  9. std::string type_of_weapon;
  10. std::string mount_name;
  11. long defeated_enemies;
  12. int buddies;
  13. };
  14.  
  15. void save_game(savedinfo sv);
  16. savedinfo load_game(savedinfo kek);
  17. int main()
  18. {
  19. savedinfo your_char;
  20. std::cout << "Dane z poprzedniej gry: \n";
  21. std::cout << "Postac " << your_char.character_name << ", poziom " << your_char.level << ",\n";
  22. std::cout << "Uzywana bron: " << your_char.type_of_weapon << ", imie wierzchowca: " << your_char.mount_name << ",\n";
  23. std::cout << "Pokonani przeciwnicy: " << your_char.defeated_enemies << ", odblokowani towarzysze: " << your_char.buddies << ",\n";
  24. std::cout << "Doswiadczenie do nastepnego poziomu: " << your_char.exp_to_next_level << "\n";
  25. save_game(your_char);
  26. return 0;
  27. }
  28.  
  29. void save_game(savedinfo sv)
  30. {
  31. std::ofstream savinggame;
  32. savinggame.open("savegame.txt");
  33. std::cout << "Podaj imie postaci: ";
  34. getline(std::cin, sv.character_name);
  35. std::cin.clear();
  36. std::cout << "Podaj poziom postaci: ";
  37. std::cin >> sv.level;
  38. std::cin.clear();
  39. std::cout << "Podaj ilosc doswiadczenia do nastepnego poziomu: ";
  40. std::cin >> sv.exp_to_next_level;
  41. std::cin.clear();
  42. std::cin.clear();
  43. std::cout << "Podaj rodzaj broni: ";
  44. getline(std::cin, sv.type_of_weapon);
  45. std::cin.clear();
  46. std::cout << "Podaj imie wierzchowca: ";
  47. getline(std::cin, sv.mount_name);
  48. std::cin.clear();
  49. std::cout << "Podaj liczbe pokonanych wrogow: ";
  50. std::cin >> sv.defeated_enemies;
  51. std::cin.clear();
  52. std::cout << "Podaj liczbe odblokowanych towarzyszy: ";
  53. std::cin >> sv.buddies;
  54. std::cout << "Trwa zapisywanie...";
  55. savinggame << sv.character_name << "\n";
  56. savinggame << sv.level << "\n";
  57. savinggame << sv.exp_to_next_level << "\n";
  58. savinggame << sv.type_of_weapon << "\n";
  59. savinggame << sv.mount_name << "\n";
  60. savinggame << sv.defeated_enemies << "\n";
  61. savinggame << sv.buddies << "\n";
  62. savinggame.close();
  63. }
  64. savedinfo load_game(savedinfo kek)
  65. {
  66. std::ifstream loadinggame;
  67. loadinggame.open("savegame.txt");
  68. getline(loadinggame, kek.character_name);
  69. loadinggame >> kek.level;
  70. loadinggame >> kek.exp_to_next_level;
  71. getline(loadinggame, kek.type_of_weapon);
  72. getline(loadinggame, kek.mount_name);
  73. loadinggame >> kek.defeated_enemies;
  74. loadinggame >> kek.buddies;
  75. loadinggame.close();
  76. return kek;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement