-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame_options.cpp
148 lines (136 loc) · 4.66 KB
/
game_options.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
#include "game_options.h"
#include "physical_controllers.h"
#include "game_view_layout.h"
#include "pieces.h"
#include "lobby_options.h"
#include <cassert>
#include <iostream>
#include <sstream>
game_options::game_options(
const screen_coordinat& screen_size,
const starting_position_type starting_position,
const game_speed speed,
const int margin_width
) : m_click_distance{0.5},
m_game_speed{speed},
m_margin_width{margin_width},
m_replayer(replay("")),
m_screen_size{screen_size},
m_starting_position{starting_position},
m_music_volume{10},
m_sound_effects_volume{20} // percent
{
assert(m_click_distance > 0.0);
assert(m_margin_width >= 0);
assert(m_screen_size.get_x() > 0);
assert(m_screen_size.get_y() > 0);
}
game_options create_default_game_options() noexcept
{
return game_options(
get_default_screen_size(),
get_default_starting_position(),
get_default_game_speed(),
get_default_margin_width()
);
}
bool do_show_selected(const game_options& options) noexcept
{
return options.do_show_selected();
}
const volume& get_music_volume(const game_options& options) noexcept
{
return options.get_music_volume();
}
double get_music_volume_as_percentage(const game_options& options) noexcept
{
return get_music_volume(options).get_percentage();
}
const volume& get_sound_effects_volume(const game_options& options) noexcept
{
return options.get_sound_effects_volume();
}
starting_position_type get_starting_position(const game_options& options) noexcept
{
return options.get_starting_position();
}
void test_game_options()
{
#ifndef NDEBUG
// get_starting_position and game::get_starting_position
{
const auto options{create_default_game_options()};
assert(options.get_starting_position() == get_starting_position(options));
}
// game_options::get_music_volume
{
const auto options{create_default_game_options()};
assert(options.get_music_volume().get_percentage() >= 0.0);
}
// game_options::get_music_volume
{
const auto options{create_default_game_options()};
assert(get_music_volume_as_percentage(options) >= 0.0);
}
// game_options::get_sound_effects_volume
{
const auto options{create_default_game_options()};
assert(options.get_sound_effects_volume().get_percentage() >= 0.0);
}
// game_options::get_starting_position
{
const auto options{create_default_game_options()};
assert(options.get_starting_position() == get_starting_position(options));
}
// game_options::set_music_volume
{
auto options{create_default_game_options()};
const volume v(31);
options.set_volume(v);
assert(options.get_music_volume() == v);
}
// 40: operator<<
{
const auto options{create_default_game_options()};
std::stringstream s;
s << options;
assert(!s.str().empty());
}
#endif // NDEBUG
}
bool operator==(const game_options& lhs, const game_options& rhs) noexcept
{
return lhs.do_show_occupied() == rhs.do_show_occupied()
&& lhs.do_show_selected() == rhs.do_show_selected()
&& lhs.get_click_distance() == rhs.get_click_distance()
&& lhs.get_damage_per_chess_move() == rhs.get_damage_per_chess_move()
&& lhs.get_game_speed() == rhs.get_game_speed()
// && lhs.get_left_player_color() == rhs.get_left_player_color()
&& lhs.get_margin_width() == rhs.get_margin_width()
&& lhs.get_message_display_time_secs() == rhs.get_message_display_time_secs()
&& lhs.get_replayer() == rhs.get_replayer()
&& lhs.get_screen_size() == rhs.get_screen_size()
&& lhs.get_starting_position() == rhs.get_starting_position()
&& lhs.get_music_volume() == rhs.get_music_volume()
&& lhs.get_sound_effects_volume() == rhs.get_sound_effects_volume()
;
}
std::ostream& operator<<(std::ostream& os, const game_options& options) noexcept
{
os
<< "click distance: " << options.get_click_distance() << '\n'
//<< "LHS controller: " << options.get_physical_controller(side::lhs) << '\n'
//<< "RHS controller: " << options.get_physical_controller(side::rhs) << '\n'
<< "damage per chess move: " << options.get_damage_per_chess_move() << '\n'
<< "game speed: " << options.get_game_speed() << '\n'
//<< "LHS color: " << options.get_left_player_color() << '\n'
<< "Margin width: " << options.get_margin_width() << '\n'
<< "Message display time (sec): " << options.get_message_display_time_secs() << '\n'
<< "Replayer: " << options.get_replayer() << '\n'
<< "Screen size: " << options.get_screen_size() << '\n'
<< "Starting position: " << options.get_starting_position() << '\n'
<< "Music volume: " << options.get_music_volume() << '\n'
<< "Sound effects volume: " << options.get_sound_effects_volume()
;
return os;
}