This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.cpp
92 lines (70 loc) · 2.07 KB
/
player.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
#include "player.h"
#include <cassert>
player::player() :
m_score{0},
m_x{0.0},
m_y{0.0},
m_line_x_position{0}
{
}
int player::get_score() const noexcept {
return m_score;
}
void player::set_score(const int new_score) {
assert(new_score >= 0);
m_score = new_score;
}
void player::set_position(double line_x_position) {
m_line_x_position = line_x_position;
}
void player::score(const double line_x_position) {
if (m_line_x_position <= line_x_position) {
m_score += 2;
} else {
m_score += 3;
}
}
void test_player() {
// Here write tests for player
{
// 39 - A player that scores increase its score count
// by 2 points if inside the line
// by 3 points if outside the line
player p;
const double line_x_position = 30.0; // arbitrary value
// the player is inside the line
p.set_position(line_x_position - 1.0); // inside is below the line's x, arbitrary
// it scores
p.score(line_x_position);
// now its score should be 2
assert(p.get_score() == 2);
// it scores again
p.score(line_x_position);
// now its score should be 4
assert(p.get_score() == 4);
// the player is now outside the line
p.set_position(line_x_position + 1.0);
// it scores
p.score(line_x_position);
// its score should now be 7
assert(p.get_score() == 7);
}
// more tests...
// 17 - The player has a score counting system
const player player_g;
const int expected_player_score{0};
const int player_score{player_g.get_score()};
//check player score
assert(expected_player_score == player_score);
// 41 A player has a position in continuous space
const double x{player_g.get_x()};
const double y{player_g.get_y()};
assert(x == 0.0);
assert(y == 0.0);
{
player p;
const int some_score{3}; // just a value, can be any between zero and 19 (inclusive)
p.set_score(some_score);
assert(p.get_score() == some_score);
}
}