-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio.cpp
More file actions
34 lines (31 loc) · 1.05 KB
/
Copy pathio.cpp
File metadata and controls
34 lines (31 loc) · 1.05 KB
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
31
32
33
34
#include "io.h"
#include <fstream>
const std::string slotFiles[3] = {
"slot1.dat", "slot2.dat", "slot3.dat"
};
void saveGame(int slot,
int difficulty,
int playerHP,
int playerGold,
int waveNumber)
{
std::ofstream f(slotFiles[slot], std::ios::binary);
f.write(reinterpret_cast<char*>(&difficulty), sizeof(difficulty));
f.write(reinterpret_cast<char*>(&playerHP), sizeof(playerHP));
f.write(reinterpret_cast<char*>(&playerGold), sizeof(playerGold));
f.write(reinterpret_cast<char*>(&waveNumber), sizeof(waveNumber));
}
bool loadGame(int slot,
int& difficulty,
int& playerHP,
int& playerGold,
int& waveNumber)
{
std::ifstream f(slotFiles[slot], std::ios::binary);
if (!f) return false;
f.read(reinterpret_cast<char*>(&difficulty), sizeof(difficulty));
f.read(reinterpret_cast<char*>(&playerHP), sizeof(playerHP));
f.read(reinterpret_cast<char*>(&playerGold), sizeof(playerGold));
f.read(reinterpret_cast<char*>(&waveNumber), sizeof(waveNumber));
return true;
}