-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
171 lines (159 loc) · 4.07 KB
/
main.cc
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// C++ headers
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <unistd.h>
#include <algorithm>
#include <memory>
#include <locale>
// Kerney headers
//#include "/public/colors.h"
//#include "/public/read.h"
// RPG headers
#include "tileset.cc"
#include "graphics.cc"
#include "combat.cc"
#include "class.h"
using namespace std;
void load_actors(vector<shared_ptr<Actor>>& cast, const string filename) {
ifstream in(filename);
if (!in) cerr << "Uh oh, no file found" << endl;
while (in) {
int x;
int y;
int health;
int shield;
int damage;
int resistance;
int level;
string emoji;
string class_type;
string name;
string type;
in >> class_type;
if (!in) break;
in >> name;
in >> type;
in >> x;
in >> y;
in >> emoji;
in >> health;
in >> shield;
in >> damage;
in >> resistance;
in >> level;
if (class_type == "hero") cast.push_back(make_shared<Hero> (class_type, name, type, x, y, emoji, health, shield, damage, resistance, level));
else if (class_type == "monster") cast.push_back(make_shared<Monster> (class_type, name, type, x, y, emoji, health, shield, damage, resistance, level));
}
}
void load_game_map() {}
int main() {
set_raw_mode(true);
show_cursor(false);
//set_alternate_window(true);
srand(time(0));
print_title("RPG - 41");
cout << endl;
cout << "New game (1);" << endl;
cout << "Load game (2);" << endl;
int choice;
cin >> choice;
vector<shared_ptr<Actor>> cast;
if (choice == 2) load_actors(cast, "save_actors.txt");
else load_actors(cast, "actors.txt");
draw_game_map(cast);
while (true) {
shared_ptr<Actor> h = cast.at(0);
for (size_t row = 0; row < game_map.size(); row++) {
char puzzle1 = '1';
char puzzle2 = '2';
char puzzle3 = '3';
char puzzle4 = '4';
char puzzle5 = '5';
char puzzle6 = '6';
auto found1 = game_map.at(row).find(puzzle1);
auto found2 = game_map.at(row).find(puzzle2);
auto found3 = game_map.at(row).find(puzzle3);
auto found4 = game_map.at(row).find(puzzle4);
auto found5 = game_map.at(row).find(puzzle5);
auto found6 = game_map.at(row).find(puzzle6);
if (found1 != string::npos) {
solved1 = 1;
}
if (found2 != string::npos) {
solved2 = 1;
}
if (found3 != string::npos) {
solved3 = 1;
}
if (found4 != string::npos) {
solved4 = 1;
}
if (found5 != string::npos) {
solved5 = 1;
}
if (found6 != string::npos) {
solved6 = 1;
}
}
int dir = quick_read();
if (dir == 119 || dir == UP_ARROW || dir == 'k') {
if (checkTile(cast, UP)) {
h->p->y--;
draw_game_map(cast);
}
}
else if (dir == 115 || dir == DOWN_ARROW || dir == 'j') {
if (checkTile(cast, DOWN)) {
h->p->y++;
draw_game_map(cast);
}
}
else if (dir == 97 || dir == LEFT_ARROW || dir == 'h') {
if (checkTile(cast, LEFT)) {
h->p->x--;
draw_game_map(cast);
}
}
else if (dir == 100 || dir == RIGHT_ARROW || dir == 'l') {
if (checkTile(cast, RIGHT)) {
h->p->x++;
draw_game_map(cast);
}
}
else if (dir == 'f') {
movecursor(10, 2 * game_map.at(0).size());
cout << "You have paid respects.";
movecursor(11, 2 * game_map.at(0).size());
cout << "Thank you for paying respects.";
}
else if (dir == ESC) {
system("clear");
ofstream file;
file.open("save_actors.txt");
//TODO: Do I need this? : static_pointer_cast<Hero>(h)->num_cheese++;
for (int i = 0; i < cast.size(); i++) {
file << cast.at(i)->get_class_type() << " ";
file << cast.at(i)->get_name() << " ";
file << cast.at(i)->get_type() << " ";
file << cast.at(i)->p->get_x() << " ";
file << cast.at(i)->p->get_y() << " ";
file << cast.at(i)->get_emoji() << " ";
file << cast.at(i)->get_health() << " ";
file << cast.at(i)->get_shield() << " ";
file << cast.at(i)->get_damage() << " ";
file << cast.at(i)->get_resistance() << " ";
file << cast.at(i)->get_level() << " ";
file << endl;
if (cast.at(i)->get_class_type() == "hero") {
}
}
file.close();
cout << "Exiting..." << endl;
show_cursor(true);
exit(1);
}
}
}