-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.cpp
More file actions
76 lines (66 loc) · 1.68 KB
/
Copy pathmodel.cpp
File metadata and controls
76 lines (66 loc) · 1.68 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
#include "model.h"
#include <fstream>
#include <iostream>
using namespace std;
ClickerModel::ClickerModel() : points(0), level(1) {}
void ClickerModel::incrementPoints() {
points++;
if (points % 5 == 0) {
level++;
}
}
int ClickerModel::getPoints() const {
return points;
}
int ClickerModel::getLevel() const {
return level;
}
void ClickerModel::saveGameState(const std::string& filename) const {
std::ofstream file(filename);
if (file.is_open()) {
file << points << std::endl;
file << level << std::endl;
file.close();
} else {
std::cerr << "Unable to open file " << filename << " for writing." << std::endl;
}
}
void ClickerModel::loadGameState(const std::string& filename) {
std::ifstream file(filename);
if (file.is_open()) {
file >> points;
file >> level;
file.close();
} else {
std::cerr << "Unable to open file " << filename << " for reading." << std::endl;
}
}
//void ClickerModel::getFilename(){
// std::cin<<filename;
//}
std::string ClickerModel::toRoman(int value) {
struct romandata_t { int value; std::string numeral; };
const struct romandata_t romandata[] = {
1000, "M",
900, "CM",
500, "D",
400, "CD",
100, "C",
90, "XC",
50, "L",
40, "XL",
10, "X",
9, "IX",
5, "V",
4, "IV",
1, "I"
};
std::string result;
for (const auto& data : romandata) {
while (value >= data.value) {
result += data.numeral;
value -= data.value;
}
}
return result;
}