This repository was archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_game.cpp
More file actions
44 lines (41 loc) · 1.4 KB
/
Copy pathinit_game.cpp
File metadata and controls
44 lines (41 loc) · 1.4 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
#include "init_game.hpp"
#include <fstream>
std::vector<std::string> read_values(game_settings & game){
std::vector<std::string> list;
std::ifstream input("player.txt");
if (input.is_open()) {
while(input.is_open()){
std::string name;
std::string attr;
input >> name;
if (name == "MUNTEN") {
input >> attr;
game.coins = stoi(attr);
} else if (name == "HIGH") {
input >> attr;
game.highscore = stoi(attr);
} else if (name == "EQUIPPED") {
input >> attr;
game.player = attr;
} else if (name == "PLAYER") {
input >> attr;
list.push_back(attr);
} else if(name.empty()){
return list;
}
}
}
return list;
}
void save(std::vector<std::string> player_list, game_settings & game){
std::ofstream output("player.txt");
while(output.is_open()){
output <<"MUNTEN " << std::to_string(game.coins) << "\n";
output << "HIGH " << std::to_string(game.highscore) << "\n";
output << "EQUIPPED " << game.player << "\n";
for(auto player : player_list){
output << "PLAYER " << player << "\n";
}
output.close();
}
}