-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame_view.h
240 lines (172 loc) · 6.14 KB
/
game_view.h
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#ifndef GAME_VIEW_H
#define GAME_VIEW_H
#ifndef LOGIC_ONLY
#include "ccfwd.h"
#include "physical_controller.h"
#include "game.h"
#include "fps_clock.h"
#include "game_log.h"
#include "game_controller.h"
#include "game_resources.h"
#include "game_view_layout.h"
#include <SFML/Graphics.hpp>
#include <optional>
/// The game's main window
/// Displays the game class
class game_view
{
public:
explicit game_view(
const game& game = get_default_game(),
const game_controller& c = game_controller()
);
/// Run the game, until the user quits
void exec();
/// The the elapsed time in seconds
double get_elapsed_time_secs() const noexcept;
int get_fps() const noexcept { return m_fps_clock.get_fps(); }
auto& get_game() noexcept { return m_game; }
const auto& get_game() const noexcept { return m_game; }
const auto& get_game_controller() const noexcept { return m_game_controller; }
const auto& get_layout() const noexcept { return m_layout; }
auto& get_resources() noexcept { return m_game_resources; }
auto get_show_debug() const noexcept { return m_show_debug; }
bool get_show_squares_semitransparent() const noexcept { return true; }
/// Get the text log, i.e. things pieces have to say
const auto& get_log() const noexcept { return m_log; }
auto& get_window() noexcept { return m_window; }
private:
/// The game clock, to measure the elapsed time
sf::Clock m_clock;
/// The FPS clock
fps_clock m_fps_clock;
/// The game logic
game m_game;
/// The game controller, interacts with game
game_controller m_game_controller;
/// The game logic
game_view_layout m_layout;
/// The resources (images, sounds, etc.) of the game
game_resources m_game_resources;
/// The text log
game_log m_log;
/// Show the debug info
bool m_show_debug;
/// The window to draw to
sf::RenderWindow m_window;
/// Play the new sound effects
void play_pieces_sound_effects();
/// Process all events
/// @return if the user wants to quit
bool process_events();
/// Read the pieces' messages and play their sounds
void process_piece_messages();
/// Show the game on-screen
void show();
/// Show the mouse cursor on-screen
void show_mouse_cursor();
};
/// Convert 'true' to 'true' and 'false' to 'false'
std::string bool_to_str(const bool b) noexcept;
/// Create a black/dark square at the right size
sf::RectangleShape create_black_square(game_view& view);
/// Create a white/ligt square at the right size
sf::RectangleShape create_white_square(game_view& view);
/// Are selected squares shown on-screen?
bool do_show_selected(const game_view& view);
/// Get the controller for a certain side
const physical_controller& get_physical_controller(const game_view& view, const side player);
/// Get the controller type for a certain side
physical_controller_type get_physical_controller_type(const game_view& view, const side player);
/// Get the controls text for a player with a controller
std::string get_controls_text(
const game_view& view,
const game_controller& c,
const int key
);
/// Get the frames per second
int get_fps(const game_view& v) noexcept;
/// Get the last log messages for a player
std::string get_last_log_messages(
const game_view& v,
const side player
) noexcept;
/// Get the layout
const game_view_layout& get_layout(const game_view& v) noexcept;
/// Get the game options
const game_options& get_options(const game_view& v) noexcept;
/// Get the pieces
const std::vector<piece>& get_pieces(const game_view& v) noexcept;
/// Get the color of the player
chess_color get_player_color(
const game_view& v,
const side player
) noexcept;
/// Get the player position
const game_coordinat& get_cursor_pos(
const game_view& view,
const side player
) noexcept;
/// Get the text for an action, e.g.
/// 'Q\nSelect' for a keyboard player that has nothing selected
/// 'E\nAttack' for a keyboard player that has a piece select
/// 'LMB\nSelect' for a mouse player that has nothing selected'
std::string get_text_for_action(
const game_view& view,
const game_controller& c,
const int key
);
/// Get the time in the game
const delta_t& get_time(const game_view& v) noexcept;
/// Process the event, by letting the controllers
/// add actions to the game
/// sf::Event -> controllers -> control_action
void process_event(
game_controller& c,
const sf::Event& event,
const game_view_layout& layout
);
/// Show the board: squares, unit paths, pieces, health bars
void show_board(game_view& view);
/// Show the controls (e.g. for a unit) on-screen for a player
void show_controls(game_view& view, const side player);
/// Show debug info on-screen for a player
void show_debug(game_view& view, const side player_side);
/// Show the layout of the window: board and panels
void show_layout(game_view& view);
/// Show the log on-screen, i.e. things the pieces say
void show_log(game_view& view, const side player);
/// Show the map of the window
void show_map(game_view& view);
/// Show the squares that are occupied on-screen
/// Throws if this option is turned off
void show_occupied_squares(game_view& view);
/// Show the pieces of the board on-screen
void show_pieces(game_view& view);
/// Show the possible moves for the selected pieces.
/// e.g. put crosses on squares that can be attacked.
/// Does nothing if no pieces are selected
void show_possible_moves(game_view& view);
/// Show the info on the side-bar on-screen for a player
void show_sidebar(game_view& view, const side player_side);
/// Show the squares of the board on-screen
void show_squares(game_view& view);
/// Show the highlighted square under the cursor on-screen for a player
void show_square_under_cursor(
game_view& view,
const side player
);
/// Show the pieces' health bars on-screen
void show_unit_health_bars(game_view& view);
/// Show the planned paths for the units on-screen
void show_unit_paths(game_view& view);
/// Show the selected unit(s) on-screen for a player
void show_unit_sprites(game_view& view, const side player_side);
void test_game_view();
/// Would it be a valid move if the user would press LMB or RMB?
bool would_be_valid(
const game_view& view,
chess_color player_color
);
#endif // LOGIC_ONLY
#endif // GAME_VIEW_H