-
Notifications
You must be signed in to change notification settings - Fork 2
/
sfml_game_delegate.cpp
44 lines (36 loc) · 1009 Bytes
/
sfml_game_delegate.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
// Always include the header of the unit first
#include "sfml_game_delegate.h"
#include <cassert>
#include <SFML/Window/Event.hpp>
#include "sfml_game.h"
sfml_game_delegate::sfml_game_delegate(const int close_at, bool spawning, bool damage, bool score)
: m_close_at{close_at}, m_spawning{spawning}, m_damage{damage}, m_score{score} {}
bool sfml_game_delegate::do_actions(sfml_game &sg) {
// Nothing to do?
if (m_close_at < 0)
return false;
if (sg.get_n_displayed() % 2 == 0 && !sg.get_game().get_tiles().empty())
{
sg.select_random_tile();
}
if (sg.get_n_displayed() % 2 != 0)
{
sg.move_selected_tile_randomly();
}
// Close at a certain time
if (sg.get_n_displayed() > m_close_at) {
sg.close();
// Did something
return true;
}
// Done nothing
return false;
}
void test_sfml_game_delegate() {
// close_at must be stored correctly
{
const int close_at{42};
sfml_game_delegate d(close_at);
assert(d.get_close_at() == close_at);
}
}