Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //main.cpp
- #include "Engine.h"
- int main(){
- Engine eng;
- eng.runEngine();
- return EXIT_SUCCESS;
- }
- //engine.h
- #pragma once
- #include "Player.h"
- #include "Save.h"
- class Engine
- {
- public:
- Engine();
- ~Engine();
- void runEngine();
- protected:
- Save zapis;
- Player player;
- };
- //engine.cpp
- #include "Engine.h"
- #include <iostream>
- Engine::Engine()
- {
- if (zapis.wczytaj() == false){
- player.setHealth(2.f);
- zapis.zapisz();
- }
- }
- Engine::~Engine()
- {
- }
- void Engine::runEngine(){
- int a;
- cout << player.getHealth();
- cin >> a;
- }
- //player.h
- #pragma once
- using namespace std;
- class Player
- {
- public:
- Player();
- ~Player();
- float getHealth();
- void addHealth(float add);
- void setHealth(float set);
- private:
- float health;
- };
- //player.cpp
- #include "Player.h"
- Player::Player()
- {
- }
- Player::~Player()
- {
- }
- float Player::getHealth(){
- return health;
- }
- void Player::addHealth(float add){
- health += add;
- }
- void Player::setHealth(float set){
- health = set;
- }
- //save.h
- #include <fstream>
- #include "Player.h"
- using namespace std;
- class Save
- {
- public:
- Save();
- ~Save();
- bool zapisz();
- bool wczytaj();
- protected:
- fstream zapis;
- Player player;
- };
- //save.cpp
- #include "Save.h"
- Save::Save()
- {
- }
- Save::~Save()
- {
- }
- bool Save::zapisz(){
- zapis.open("Profile.save", ios::out);
- if (zapis.good() == true)
- {
- zapis << player.getHealth() << " ";
- zapis.close();
- return true;
- }
- else{
- zapis.close();
- return false;
- }
- }
- bool Save::wczytaj(){
- float test = 2;
- zapis.open("Profile.save", ios::in);
- if (zapis.good())
- {
- zapis >> test;
- player.setHealth(test);
- zapis.close();
- return true;
- }
- else{
- zapis.close();
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement