-
Notifications
You must be signed in to change notification settings - Fork 0
/
Application.cpp
156 lines (132 loc) · 4.93 KB
/
Application.cpp
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
#include "Application.h"
#include <utility>
void Application::start() {
Controller controller;
IReader *reader = new ConsoleCommandReader;
// int user_command = controller.getCommand(reader);
// if (user_command == 2) {
// Application::load();
// delete reader;
// return;
// }
// if (user_command == 3) {
// Application::exit();
// delete reader;
// return;
// }
bool is_file_logger = controller.isFileLogger(reader);
bool is_console_logger = controller.isConsoleLogger(reader);
bool is_trace_level, is_info_level, is_error_level;
if (!is_file_logger and !is_console_logger) {
is_trace_level = false;
is_info_level = false;
is_error_level = false;
} else {
is_trace_level = controller.isTraceLevel(reader);
is_info_level = controller.isInfoLevel(reader);
is_error_level = controller.isErrorLevel(reader);
}
Log *log = new Log{is_trace_level, is_info_level, is_error_level, is_file_logger, is_console_logger};
// controller.printUserInfo();
game_observer->gameStarted(*log);
InputCommands *file_input;
file_input = new FileInputCommands;
file_input->setObserver(*log);
try {
file_input->setCommands();
} catch (const FileInputException &e) {
file_input->getObserver()->wrongData(std::string(e.what()));
}
GameDifficulty difficulty = controller.getGameDifficulty(reader, game_observer, *log);
Field *field = nullptr;
if (difficulty == GameDifficulty::MEDIUM) {
FieldGenerator<BarrierRule<GameDifficulty::MEDIUM>, EnemyRule<GameDifficulty::MEDIUM>, FoodRule<GameDifficulty::MEDIUM>, MoneyRule<GameDifficulty::MEDIUM>, ExitPositionRule<GameDifficulty::MEDIUM>, TrapRule<GameDifficulty::MEDIUM>> generator1;
field = generator1.createField(controller.getFieldHeight(reader, game_observer, *log),
controller.getFieldWidth(reader, game_observer, *log), *log);
} else {
FieldGenerator<BarrierRule<GameDifficulty::EASY>, EnemyRule<GameDifficulty::EASY>, FoodRule<GameDifficulty::EASY>, MoneyRule<GameDifficulty::EASY>, ExitPositionRule<GameDifficulty::EASY>, TrapRule<GameDifficulty::EASY>> generator2;
field = generator2.createField(controller.getFieldHeight(reader, game_observer, *log),
controller.getFieldWidth(reader, game_observer, *log), *log);
}
field->setObserver(*log);
PrintField print_field(field);
Player player;
if (difficulty == GameDifficulty::MEDIUM)
player.setPointsToWin(200);
player.setObserver(*log);
this->initWindow(field->getHeight(), field->getWidth());
Direction direction;
controller.printPlayerInfo(player);
while (game and window->isOpen()) {
while (window->pollEvent(ev)) {
direction = controller.makeAction(game, player, field, reader, file_input, log, game_observer, this->window, this->ev);
window->clear();
print_field.print(*field, this->window, direction);
window->display();
}
}
game_observer->gameEnded(*log);
delete file_input;
delete reader;
delete field;
delete log;
}
Application::Application() : game(true) {
game_observer = new GameObserver;
}
Application::~Application() {
delete game_observer;
delete window;
}
void Application::load() {
// Controller controller;
// IReader *reader = new ConsoleCommandReader;
// Player player;
// try{
// controller.getIsFileValid();
// } catch(SaveException &e){
// std::cout << "[ERROR] Invalid file for load!\n";
// system("pause");
// return;
// } //!!!!!!!!exeption
// Log *log = nullptr;
// Field *field = nullptr;
// controller.loadData(game_observer, log);
//
// log = controller.loadLog();
// field = controller.loadField(*log);
// controller.loadPlayer(player);
//
// InputCommands *file_input;
// file_input = new FileInputCommands;
// controller.setFileInputObserver(log, file_input);
// file_input->setCommands();
//
// controller.setFieldObserver(field, log);
//
// PrintField print_field;
// controller.setPlayerObserver(player, log);
//
// print_field.print(*field);
//
//
// controller.printPlayerInfo(player);
// while (game) {
// controller.makeAction(game, player, field, reader, file_input, log, game_observer);
// print_field.print(*field);
// controller.printPlayerInfo(player);
// }
// game_observer->gameEnded(*log);
// delete file_input;
// delete reader;
// delete log;
// delete field;
}
void Application::exit() {
}
void Application::initWindow(int field_height, int field_width) {
this->videoMode.height = 80 * field_height;
this->videoMode.width = 80 * field_width;
this->window = new sf::RenderWindow(this->videoMode, "Game", sf::Style::Titlebar | sf::Style::Close);
this->window->setFramerateLimit(60);
}