Hi, I am building a text-based console game with Dev c++ v. 4.9.9.2.
So far, everything goes well. It saves the game in several save files
for each character (maximum 6 save slots) But when I open the save
files, it's just raw text and number data. Is there a simple way to
make it more unreadable for a normal person. I don't care about
hackers or cheaters but I don't wan it to be too easy to cheat.
Especially not with the standard notepad that comes with windows.
Here´s the codes I use to save and load the save files.
1 2 3 4 5 6 7
|
#include <iostream>
#include <fstream> // needed for writing or reading to a file (save/load game)
#include "StatusBuffer.h" // external linkage to all strings and integers to
// interact with the save files.
using namespace std;
|
To load the files, I use this lines lines of code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
// Load the full game file "SaveGame.save"
int GameLoad ()
{
ifstream infile;
// determines what file to interact with, depending on the saveChoice from Login.cpp
infile.open(saveChoice.c_str());
if (infile.is_open())
{
// imports file lines to integers and temporaly strings
string NoUse;
/* 001 */ getline(infile, name);
/* 002 */ getline(infile, swordname);
/* 003 */ getline(infile, NoUse); infile >> moneycurrent;
/* 005 */ getline(infile, chaptercleard);
/* 006 */ getline(infile, NoUse); infile >> healthmax;
/* 007 */ getline(infile, NoUse); infile >> manamax;
/* 008 */ getline(infile, NoUse); infile >> staminamax;
}
else {cout << "SaveGame() can't open file";}
infile.close();
}
|
And to save the files I use these lines of code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
// Saves the full game file "SaveGame.save"
int GameSave ()
{
ofstream outfile;
// determines what file to interact with, depending on the saveChoice from Login.cpp
outfile.open(saveChoice.c_str());
if (outfile.is_open())
{
/* 001 */ outfile << name << "\n";
/* 002 */ outfile << swordname << "\n";
/* 003 */ outfile << moneycurrent << "\n";
/* 005 */ outfile << chaptercleard << "\n";
/* 006 */ outfile << healthmax << "\n";
/* 007 */ outfile << manamax << "\n";
/* 008 */ outfile << staminamax << "\n";
}
else {cout << "SaveGame() can't open file";}
// outfile.close(); // Close the file
}
|
The number of strings and integers to save and load is: 65 but I dont see the idé of writing them all here when the actual codes around the values looks the same.