-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile_man.cpp
More file actions
77 lines (67 loc) · 2.04 KB
/
File_man.cpp
File metadata and controls
77 lines (67 loc) · 2.04 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "File_man.h"
#include <cstdint>
#include <ios>
File_man::File_man() {
cout << "setting new file false..." << endl;
newFile = false;
};
void File_man::open_file() {
file.open("2nData.dat", std::ios::in | std::ios::binary | std::ios::out);
if (file.is_open()) {
cout << "File opened succesfully!" << endl;
} else {
cout << "Making new save file..." << endl;
std::ofstream file("2nData.dat");
cout << "setting new file true..." << endl;
newFile = true;
open_file();
}
}
int File_man::read_tile(int x, int y) {
file.seekg((x * options::tiles + y) + 2 + 8);
int buffer;
file.read((char *)&buffer, 1);
cout << "Read " << buffer << " at (" << x << "," << y << ")" << endl;
return buffer;
}
void File_man::write_tile(int x, int y, uint8_t val) {
int pos = (x * options::tiles + y) + 2 + 8;
file.seekp(pos);
cout << "Writing " << val << " to " << pos << " with size of " << sizeof(val)
<< endl;
file.write((char *)&val, sizeof(val));
}
bool File_man::is_new_file() {
cout << "New file? " << newFile << endl;
return newFile;
}
void File_man::write_score(uint64_t score) {
int pos = 2;
file.seekp(pos);
cout << "writing score " << score << " as " << (char *)&score << " to " << pos
<< " with size of " << sizeof(score) << endl;
file.write((char *)&score, sizeof(score));
}
uint64_t File_man::read_score() {
file.seekg(2);
cout << "Reading score..." << endl;
int buffer;
file.read((char *)&buffer, 8);
cout << "Read score as " << (uint64_t)buffer << endl;
return buffer;
}
uint16_t File_man::read_board_size() {
file.seekg(0);
cout << "Reading score..." << endl;
uint16_t buffer;
file.read((char *)&buffer, 2);
cout << "Read score as " << (uint16_t)buffer << endl;
return buffer;
}
void File_man::write_board_size(uint16_t boardSize) {
int pos = 0;
file.seekp(pos);
cout << "writing board size " << boardSize << " as " << (char *)&boardSize
<< " to " << pos << " with size of " << sizeof(boardSize) << endl;
file.write((char *)&boardSize, sizeof(boardSize));
}