From 2b988d5743f2fa0e134ee217067f29a6505eb992 Mon Sep 17 00:00:00 2001 From: Theo Pannetier Date: Wed, 8 Nov 2023 17:30:56 +0000 Subject: [PATCH 1/9] progress on test #39 --- game.pro | 5 +---- player.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/game.pro b/game.pro index dae727f..2dfcf63 100644 --- a/game.pro +++ b/game.pro @@ -23,9 +23,6 @@ CONFIG(release, debug|release) { CONFIG(debug, debug|release) { # A warning is an error, only in debug mode QMAKE_CXXFLAGS += -Werror - - - QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage } # Qt5 @@ -34,7 +31,7 @@ QT += core gui # GNU/Linux unix:!macx { # gcov - + QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage LIBS += -lgcov LIBS += -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio } diff --git a/player.cpp b/player.cpp index 13b1a74..c60d7a0 100644 --- a/player.cpp +++ b/player.cpp @@ -17,5 +17,12 @@ void test_player() { //check player score assert(expected_player_score == player_score); - + // 39 - A player that scores increase its score count + player p; + bool is_player_inside_line; + // if player inside line + // should score 2 points + // if outside line + // should score 3 points + p.score(); } From 9f1c87553fadddc741abb8cb0eb2d85310a3ddc0 Mon Sep 17 00:00:00 2001 From: oggyoggelito Date: Wed, 8 Nov 2023 18:47:29 +0100 Subject: [PATCH 2/9] #39 --- player.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/player.cpp b/player.cpp index c60d7a0..d7eab29 100644 --- a/player.cpp +++ b/player.cpp @@ -19,8 +19,13 @@ void test_player() { // 39 - A player that scores increase its score count player p; - bool is_player_inside_line; // if player inside line + if (p == is_player_inside_line) { + p.score += 2; + } + else { + p.score += 3; + } // should score 2 points // if outside line // should score 3 points From cb2dd0b5b9ebb6c9b2b5326de239f68433595598 Mon Sep 17 00:00:00 2001 From: Theo Pannetier Date: Wed, 8 Nov 2023 18:03:11 +0000 Subject: [PATCH 3/9] test for #39 --- player.cpp | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/player.cpp b/player.cpp index d7eab29..777bf4f 100644 --- a/player.cpp +++ b/player.cpp @@ -10,24 +10,41 @@ int player::get_score() const { void test_player() { // Here write tests for players - // 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); - - // 39 - A player that scores increase its score count - player p; - // if player inside line - if (p == is_player_inside_line) { - p.score += 2; + { + // 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); } - else { - p.score += 3; + + { + // 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 int line_x_position = 30; // arbitrary value + + // the player is inside the line + p.set_position(line_x_position - 30); // 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 + 30); + + // it scores + p.score(line_x_position); + // its score should now be 7 + assert(p.get_score() == 7); } - // should score 2 points - // if outside line - // should score 3 points - p.score(); + // more tests... } From 3c88e98aebfab845eb405969837155361c005312 Mon Sep 17 00:00:00 2001 From: Theo Pannetier Date: Wed, 8 Nov 2023 18:44:01 +0000 Subject: [PATCH 4/9] space is continous --- player.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/player.cpp b/player.cpp index 777bf4f..4594fdb 100644 --- a/player.cpp +++ b/player.cpp @@ -25,10 +25,10 @@ void test_player() { // by 3 points if outside the line player p; - const int line_x_position = 30; // arbitrary value + const double line_x_position = 30.0; // arbitrary value // the player is inside the line - p.set_position(line_x_position - 30); // inside is below the line's x, arbitrary + p.set_position(line_x_position - 1.0); // inside is below the line's x, arbitrary // it scores p.score(line_x_position); @@ -39,7 +39,7 @@ void test_player() { // now its score should be 4 assert(p.get_score() == 4); // the player is now outside the line - p.set_position(line_x_position + 30); + p.set_position(line_x_position + 1.0); // it scores p.score(line_x_position); From 5c52d097d9d538f5f65bce2c04f005f5b0ca5d27 Mon Sep 17 00:00:00 2001 From: martprenger Date: Wed, 6 Dec 2023 17:31:06 +0100 Subject: [PATCH 5/9] finished #39 --- player.cpp | 14 +++++++++++++- player.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/player.cpp b/player.cpp index 4594fdb..f53fc8a 100644 --- a/player.cpp +++ b/player.cpp @@ -1,6 +1,6 @@ #include "player.h" #include -player::player(): m_score{0} { +player::player(): m_score{0}, m_line_x_position{0} { } @@ -8,6 +8,18 @@ int player::get_score() const { return m_score; } +void player::set_position(double line_x_position) { + m_line_x_position{line_x_position}; +} + +void player::score(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 players { diff --git a/player.h b/player.h index 36c37db..7f031a3 100644 --- a/player.h +++ b/player.h @@ -6,8 +6,11 @@ class player { public: player(); int get_score() const; + void set_position(double line_x_position); + void score(double line_x_position); private: int m_score; + double m_line_x_position; }; void test_player(); From 5f4b9dd4ade51281abf15fc1f7a3fe3a40be71a1 Mon Sep 17 00:00:00 2001 From: mart prenger Date: Wed, 6 Dec 2023 18:18:42 +0100 Subject: [PATCH 6/9] Update player.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Théo Pannetier --- player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/player.cpp b/player.cpp index cf83b49..5523c62 100644 --- a/player.cpp +++ b/player.cpp @@ -24,7 +24,7 @@ void player::set_position(double line_x_position) { } void player::score(double line_x_position) { - if (m_line_x_position < line_x_position) { + if (m_line_x_position <= line_x_position) { m_score += 2; } else { m_score += 3; From 7bdd9f8212f09189a7cf537a700682716e3d13e1 Mon Sep 17 00:00:00 2001 From: martprenger Date: Wed, 6 Dec 2023 18:22:26 +0100 Subject: [PATCH 7/9] worked on the changes of pull request review --- player.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/player.cpp b/player.cpp index cf83b49..5544718 100644 --- a/player.cpp +++ b/player.cpp @@ -3,8 +3,8 @@ player::player() : m_score{0}, - m_x{0}, - m_y{0}, + m_x{0.0}, + m_y{0.0}, m_line_x_position{0} { From 1d07f5c0da6b8d3aa4c53bd4a941920760764c0f Mon Sep 17 00:00:00 2001 From: martprenger Date: Wed, 6 Dec 2023 18:23:09 +0100 Subject: [PATCH 8/9] worked on the changes of pull request review --- player.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/player.h b/player.h index 64362b6..34ab246 100644 --- a/player.h +++ b/player.h @@ -11,7 +11,7 @@ class player { int get_score() const noexcept; void set_score(const int new_score); void set_position(double line_x_position); - void score(double line_x_position); + void score(const double line_x_position); private: int m_score; double m_x; From c0f81a1b601f8915e9d99d95637fe917a1aad673 Mon Sep 17 00:00:00 2001 From: martprenger Date: Wed, 6 Dec 2023 18:25:25 +0100 Subject: [PATCH 9/9] fixed pr review --- player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/player.cpp b/player.cpp index c6fbbb7..93751d9 100644 --- a/player.cpp +++ b/player.cpp @@ -24,7 +24,7 @@ void player::set_position(double line_x_position) { m_line_x_position = line_x_position; } -void player::score(double line_x_position) { +void player::score(const double line_x_position) { if (m_line_x_position <= line_x_position) { m_score += 2; } else {