Conquer Chess
Chess and Starcraft combined
Loading...
Searching...
No Matches
game_view.h
Go to the documentation of this file.
1#ifndef GAME_VIEW_H
2#define GAME_VIEW_H
3
4#ifndef LOGIC_ONLY
5
6#include "ccfwd.h"
7#include "controls_bar.h"
9//#include "game.h"
10#include "game_log.h"
11#include "game_controller.h"
12#include "game_view_layout.h"
15#include "view.h"
16
17#include <SFML/Graphics.hpp>
18
19//#include <optional>
20
26class game_view : public view
27{
28public:
29 explicit game_view();
30
32 void draw_impl() override;
33
35 void tick_impl(delta_t dt) override;
36
38 double get_elapsed_time_secs() const noexcept;
39
40 const auto& get_game() const noexcept { return m_game_controller.get_game(); }
41
42 const auto& get_game_controller() const noexcept { return m_game_controller; }
43
44 const auto& get_game_options() const noexcept { return m_game_options; }
45
46 const auto& get_layout() const noexcept { return m_layout; }
47
49 const auto& get_log() const noexcept { return m_log; }
50
51 const auto& get_physical_controllers() const noexcept { return m_pc; }
52
53 [[nodiscard]] replay get_replay() const;
54
57 bool process_event_impl(sf::Event& event) override;
58
60 void process_resize_event_impl(sf::Event& event) override;
61
62 void set_game_options(const game_options& go) noexcept { m_game_options = go; }
63
64 void set_lobby_options(const lobby_options& lo) noexcept;
65
66 void start_impl() override;
67
68 void stop_impl() override;
69
70private:
71
73 sf::Clock m_clock;
74
75 controls_bar m_controls_bar;
76
77 game_options m_game_options;
78
80 game_controller m_game_controller;
81
83 game_view_layout m_layout;
84
85 lobby_options m_lobby_options;
86
88 game_log m_log;
89
91
92 game_statistics_output_file m_statistics_output_file;
93
94 game_statistics_in_time m_statistics_in_time;
95
96
98 void play_pieces_sound_effects();
99
101 void process_piece_messages();
102
104 void show_mouse_cursor();
105};
106
108sf::RectangleShape create_black_square(game_view& view);
109
111sf::RectangleShape create_white_square(game_view& view);
112
115
118
120std::vector<std::string> get_controls_texts(
121 const game_controller& c,
122 const side player_side
123);
124
126std::string get_last_log_messages(
127 const game_view& v,
128 const side player
129) noexcept;
130
132const game_view_layout& get_layout(const game_view& v) noexcept;
133
135const std::vector<piece>& get_pieces(const game_view& v) noexcept;
136
139 const game_view& view,
140 const side player
141) noexcept;
142
144const in_game_time& get_time(const game_view& v) noexcept;
145
149void process_event(
151 const physical_controllers& pc,
152 const sf::Event& event,
153 const game_view_layout& layout
154);
155
156
159
161void draw_board(
163 const bool show_occupied
164);
165
167void draw_controls(
169 const side player
170);
171
174
177
179void show_debug(game_view& view, const side player_side);
180
182void draw_log(game_view& view, const side player);
183
184
188
191
196
198void show_sidebar(game_view& view, const side player_side);
199
202
204void draw_cursor(
206 const side player
207);
208
211
214
216void draw_unit_info(game_view& view, const side player_side);
217
218void test_game_view();
219
221bool would_be_valid(
222 const game_view& view,
223 chess_color player_color
224);
225
226#endif // LOGIC_ONLY
227
228#endif // GAME_VIEW_H
chess_color
A chess piece color.
Definition chess_color.h:10
Definition controls_bar.h:12
A change of in_game_time}.
Definition delta_t.h:12
The class that acts as a controller for game}.
Definition game_controller.h:31
const game & get_game() const noexcept
Get the game.
Definition game_controller.h:48
An exact coordinate anywhere on the board.
Definition game_coordinate.h:32
The text log in the game.
Definition game_log.h:14
Options for the game.
Definition game_options.h:18
Definition game_statistics_in_time.h:8
File to save the game statistics too.
Definition game_statistics_output_file.h:11
The layout of the Game dialog.
Definition game_view_layout.h:61
The Game dialog.
Definition game_view.h:27
void draw_impl() override
Show the game on-screen.
Definition game_view.cpp:230
const auto & get_layout() const noexcept
Definition game_view.h:46
game_view()
Definition game_view.cpp:33
void set_game_options(const game_options &go) noexcept
Definition game_view.h:62
void start_impl() override
Prepare this window for being shown.
Definition game_view.cpp:639
const auto & get_game() const noexcept
Definition game_view.h:40
void stop_impl() override
Clean up after this window has been shown.
Definition game_view.cpp:661
double get_elapsed_time_secs() const noexcept
The the elapsed time in seconds.
Definition game_view.cpp:87
void process_resize_event_impl(sf::Event &event) override
Process a resize events.
Definition game_view.cpp:185
bool process_event_impl(sf::Event &event) override
Process all events.
Definition game_view.cpp:159
void set_lobby_options(const lobby_options &lo) noexcept
Definition game_view.cpp:633
const auto & get_game_options() const noexcept
Definition game_view.h:44
void tick_impl(delta_t dt) override
Run the game, until the user quits.
Definition game_view.cpp:44
const auto & get_log() const noexcept
Get the text log, i.e. things pieces have to say.
Definition game_view.h:49
replay get_replay() const
Definition game_view.cpp:114
const auto & get_physical_controllers() const noexcept
Definition game_view.h:51
const auto & get_game_controller() const noexcept
Definition game_view.h:42
The in-game time, in chess moves.
Definition in_game_time.h:16
The options that are set in the lobby.
Definition lobby_options.h:16
A physical controller.
Definition physical_controller.h:19
The physical controllers used by all players.
Definition physical_controllers.h:12
A replay.
Definition replay.h:23
The abstract base class of all other views.
Definition view.h:26
const in_game_time & get_time(const game_view &v) noexcept
Get the time in the game.
Definition game_view.cpp:154
const game_view_layout & get_layout(const game_view &v) noexcept
Get the layout.
Definition game_view.cpp:104
sf::RectangleShape create_white_square(game_view &view)
Create a white/ligt square at the right size.
void draw_unit_paths(game_view &view)
Show the planned paths for the units on-screen.
Definition game_view.cpp:587
void draw_board(game_view &view, const bool show_occupied)
Show the board: squares, unit paths, pieces, health bars.
Definition game_view.cpp:273
void show_occupied_squares(game_view &view)
Show the squares that are occupied on-screen Throws if this option is turned off.
Definition game_view.cpp:458
void draw_unit_health_bars(game_view &view)
Show the pieces' health bars on-screen.
Definition game_view.cpp:578
bool would_be_valid(const game_view &view, chess_color player_color)
Would it be a valid move if the user would press LMB or RMB?
Definition game_view.cpp:676
void show_sidebar(game_view &view, const side player_side)
Show the info on the side-bar on-screen for a player.
void draw_navigation_controls(game_view &view)
Show the controls (e.g. for a unit) on-screen for a player.
Definition game_view.cpp:369
std::string get_last_log_messages(const game_view &v, const side player) noexcept
Get the last log messages for a player.
Definition game_view.cpp:93
void test_game_view()
OCLINT tests may be many.
Definition game_view.cpp:670
void draw_controls(game_view &view, const side player)
Show the controls (e.g. for a unit) on-screen for a player.
Definition game_view.cpp:296
void draw_unit_info(game_view &view, const side player_side)
Show the selected unit(s) on-screen for a player.
Definition game_view.cpp:595
sf::RectangleShape create_black_square(game_view &view)
Create a black/dark square at the right size.
std::vector< std::string > get_controls_texts(const game_controller &c, const side player_side)
Get the controls text for a player with a controller.
Definition game_view.cpp:135
physical_controller_type get_physical_controller_type(const game_view &view, const side player)
Get the controller type for a certain side.
Definition game_view.cpp:82
void draw_log(game_view &view, const side player)
Show the log on-screen, i.e. things the pieces say.
Definition game_view.cpp:432
void draw_cursor(game_view &view, const side player)
Show the highlighted square under the cursor on-screen for a player.
Definition game_view.cpp:528
void show_debug(game_view &view, const side player_side)
Show debug info on-screen for a player.
Definition game_view.cpp:382
void draw_possible_moves(game_view &view)
Show the possible moves for the selected pieces.
Definition game_view.cpp:494
void draw_game_statistics_widget(game_view &view)
Show the game info, e.g. the time.
Definition game_view.cpp:361
const game_coordinate & get_cursor_pos(const game_view &view, const side player) noexcept
Get the player position.
Definition game_view.cpp:130
void draw_background(game_view &view)
Show the map of the window.
Definition game_view.cpp:448
void process_event(game_controller &c, const physical_controllers &pc, const sf::Event &event, const game_view_layout &layout)
Process the event, by letting the controllers add actions to the game sf::Event -> controllers -> con...
Definition game_view.cpp:199
const physical_controller & get_physical_controller(const game_view &view, const side player)
Get the controller for a certain side.
Definition game_view.cpp:77
void draw_squares(game_view &view)
Show the squares of the board on-screen.
Definition game_view.cpp:523
void draw_pieces(game_view &view)
Show the pieces of the board on-screen.
Definition game_view.cpp:483
const std::vector< piece > & get_pieces(const game_view &v) noexcept
Get the pieces.
Definition game_view.cpp:109
physical_controller_type
The type of controller.
Definition physical_controller_type.h:15
side
The side the player/piece is on.
Definition side.h:11