Advertisement
Guest User

Untitled

a guest
Oct 8th, 2015
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. //main.cpp
  2. #include "Engine.h"
  3.  
  4. int main(){
  5.     Engine eng;
  6.     eng.runEngine();
  7.  
  8.     return EXIT_SUCCESS;
  9. }
  10.  
  11. //engine.h
  12.  
  13. #pragma once
  14.  
  15. #include "Player.h"
  16. #include "Save.h"
  17.  
  18. class Engine
  19. {
  20. public:
  21.     Engine();
  22.     ~Engine();
  23.  
  24.     void runEngine();
  25. protected:
  26.     Save zapis;
  27.     Player player;
  28.  
  29. };
  30.  
  31. //engine.cpp
  32.  
  33. #include "Engine.h"
  34. #include <iostream>
  35.  
  36. Engine::Engine()
  37. {
  38.     if (zapis.wczytaj() == false){
  39.         player.setHealth(2.f);
  40.         zapis.zapisz();
  41.     }
  42.  
  43. }
  44.  
  45. Engine::~Engine()
  46. {
  47. }
  48.  
  49. void Engine::runEngine(){
  50.     int a;
  51.         cout << player.getHealth();
  52.         cin >> a;
  53.    
  54. }
  55.  
  56. //player.h
  57.  
  58. #pragma once
  59.  
  60. using namespace std;
  61.  
  62. class Player
  63. {
  64. public:
  65.     Player();
  66.     ~Player();
  67.  
  68.     float getHealth();
  69.  
  70.     void addHealth(float add);
  71.  
  72.     void setHealth(float set);
  73. private:
  74.     float health;
  75.  
  76. };
  77.  
  78. //player.cpp
  79.  
  80. #include "Player.h"
  81.  
  82.  
  83. Player::Player()
  84. {
  85. }
  86.  
  87. Player::~Player()
  88. {
  89. }
  90.  
  91. float Player::getHealth(){
  92.     return health;
  93. }
  94.  
  95. void Player::addHealth(float add){
  96.     health += add;
  97. }
  98.  
  99. void Player::setHealth(float set){
  100.     health = set;
  101. }
  102.  
  103. //save.h
  104. #include <fstream>
  105. #include "Player.h"
  106.  
  107. using namespace std;
  108.  
  109. class Save
  110. {
  111. public:
  112.     Save();
  113.     ~Save();
  114.  
  115.     bool zapisz();
  116.     bool wczytaj();
  117.    
  118.  
  119. protected:
  120.     fstream zapis;
  121.  
  122.     Player player;
  123. };
  124.  
  125. //save.cpp
  126.  
  127. #include "Save.h"
  128.  
  129. Save::Save()
  130. {
  131. }
  132.  
  133. Save::~Save()
  134. {
  135. }
  136.  
  137.  
  138. bool Save::zapisz(){
  139.     zapis.open("Profile.save", ios::out);
  140.     if (zapis.good() == true)
  141.     {
  142.         zapis << player.getHealth() << " ";
  143.         zapis.close();
  144.         return true;
  145.     }
  146.     else{
  147.         zapis.close();
  148.         return false;
  149.     }
  150. }
  151.  
  152. bool Save::wczytaj(){
  153.     float test = 2;
  154.     zapis.open("Profile.save", ios::in);
  155.     if (zapis.good())
  156.     {
  157.         zapis >> test;
  158.         player.setHealth(test);
  159.         zapis.close();
  160.         return true;
  161.     }
  162.     else{
  163.         zapis.close();
  164.         return false;
  165.     }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement