Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Issue 39 #51

Merged
merged 12 commits into from
Dec 6, 2023
5 changes: 1 addition & 4 deletions game.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
50 changes: 48 additions & 2 deletions player.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#include "player.h"

Check notice on line 1 in player.cpp

View workflow job for this annotation

GitHub Actions / lint

Run clang-format on player.cpp

File player.cpp does not conform to LLVM style guidelines. (lines 4, 5, 6, 7, 8, 9, 14, 15, 18, 19, 23, 27, 28, 29, 30, 31, 35, 36, 38, 39, 40, 41, 43, 44, 46, 47, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 60, 61, 62, 63, 64, 65, 67, 68, 69, 70, 72, 73, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 87)

Check notice on line 1 in player.cpp

View workflow job for this annotation

GitHub Actions / lint

Run clang-format on player.cpp

File player.cpp does not conform to LLVM style guidelines. (lines 4, 5, 6, 7, 8, 9, 14, 15, 18, 19, 23, 27, 28, 29, 30, 31, 35, 36, 38, 39, 40, 41, 43, 44, 46, 47, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 60, 61, 62, 63, 64, 65, 67, 68, 69, 70, 72, 73, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 87)
#include <cassert>

player::player() :
m_score{0},
m_x{0.0},
m_y{0.0}
m_y{0.0},
m_line_x_position{0}
{


}

int player::get_score() const noexcept {
Expand All @@ -17,8 +20,50 @@
m_score = new_score;
}

void player::set_position(double line_x_position) {
m_line_x_position = line_x_position;
}
Comment on lines +23 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the intended solution by the test (the field's line should probably not be a property of the player!), but it does address the test. I'll allow it for now, eventually we'll have to break this (in #52).


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 players
// 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};
Expand All @@ -38,6 +83,7 @@
p.set_score(some_score);
assert(p.get_score() == some_score);
}

}


Expand Down
7 changes: 4 additions & 3 deletions player.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#ifndef PLAYER_H

Check notice on line 1 in player.h

View workflow job for this annotation

GitHub Actions / lint

Run clang-format on player.h

File player.h does not conform to LLVM style guidelines. (lines 2, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19)

Check notice on line 1 in player.h

View workflow job for this annotation

GitHub Actions / lint

Run clang-format on player.h

File player.h does not conform to LLVM style guidelines. (lines 2, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19)
#define PLAYER_H


class player {

Check failure on line 5 in player.h

View workflow job for this annotation

GitHub Actions / lint

/player.h:5:1 [clang-diagnostic-error]

unknown type name 'class'

Check warning on line 5 in player.h

View workflow job for this annotation

GitHub Actions / lint

/player.h:5:7 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'player' is non-const and globally accessible, consider making it const

Check failure on line 5 in player.h

View workflow job for this annotation

GitHub Actions / lint

/player.h:5:13 [clang-diagnostic-error]

expected ';' after top level declarator

Check failure on line 5 in player.h

View workflow job for this annotation

GitHub Actions / lint

/player.h:5:1 [clang-diagnostic-error]

unknown type name 'class'

Check warning on line 5 in player.h

View workflow job for this annotation

GitHub Actions / lint

/player.h:5:7 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'player' is non-const and globally accessible, consider making it const

Check failure on line 5 in player.h

View workflow job for this annotation

GitHub Actions / lint

/player.h:5:13 [clang-diagnostic-error]

expected ';' after top level declarator
public:
player();


double get_x() const noexcept { return m_x; }
double get_y() const noexcept { return m_y; }

int get_score() const noexcept;
void set_score(const int new_score);

void set_position(double line_x_position);
void score(const double line_x_position);
private:
int m_score;
double m_x;
double m_y;
double m_line_x_position;

};

void test_player();
Expand Down
Loading