diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 9d5a487..bf87f01 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -21,9 +21,15 @@ jobs: - name: Install Codecov run: sudo pip install codecov - - name: Allow measuring codecov + - name: Allow measuring codecov 1/2 + run: sed -i 's/# QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage/QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage/' game.pro + + - name: Allow measuring codecov 2/2 run: sed -i 's/# LIBS += -lgcov/LIBS += -lgcov/' game.pro + - name: Allow running with logic only + run: sed -i 's/# DEFINES += LOGIC_ONLY/DEFINES += LOGIC_ONLY/' game.pro + - name: qmake run: qmake game.pro diff --git a/README.md b/README.md index f18fcb6..f22f1a0 100644 --- a/README.md +++ b/README.md @@ -103,27 +103,6 @@ Videos: * [From design to feature](https://youtu.be/f-rzfZtsPKU) * [Splitting up an Issues to smaller Issues](https://youtu.be/mhIBXfxVxIU) +## Screenshots -```mermaid -classDiagram - Animal <|-- Duck - Animal <|-- Fish - Animal <|-- Zebra - Animal : +int age - Animal : +String gender - Animal: +isMammal() - Animal: +mate() - class Duck{ - +String beakColor - +swim() - +quack() - } - class Fish{ - -int sizeInFeet - -canEat() - } - class Zebra{ - +bool is_wild - +run() - } -``` +![State of the game on 21/02/2024](screenshots/20240221.png) diff --git a/game.pri b/game.pri index fd9d20a..85bc57b 100644 --- a/game.pri +++ b/game.pri @@ -7,6 +7,7 @@ SOURCES += \ $$PWD/ball.cpp \ $$PWD/game.cpp \ + $$PWD/game_view.cpp \ $$PWD/main.cpp \ $$PWD/player.cpp @@ -17,4 +18,5 @@ SOURCES += \ HEADERS += \ $$PWD/ball.h \ $$PWD/game.h \ + $$PWD/game_view.h \ $$PWD/player.h diff --git a/game.pro b/game.pro index faef39f..266265d 100644 --- a/game.pro +++ b/game.pro @@ -30,6 +30,10 @@ QT += core gui # GNU/Linux unix:!macx { + # Cannot do code coverage on a local computer + # + # This line will be uncommented by GitHub Actions + # # gcov # QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage # LIBS += -lgcov @@ -65,6 +69,11 @@ win32{ LIBS += -lopengl32 LIBS += -lgdi32 LIBS += -lwinmm - LIBS += -lgcov + # LIBS += -lgcov } +# Cannot show game on GitHub Actions +# +# This line will be uncommented by GitHub Actions +# +# DEFINES += LOGIC_ONLY diff --git a/game_view.cpp b/game_view.cpp new file mode 100644 index 0000000..6cea9bb --- /dev/null +++ b/game_view.cpp @@ -0,0 +1,56 @@ +#include "game_view.h" + +#ifndef LOGIC_ONLY // so this is NOT compiled on GitHub Actions + +#include "game.h" +#include +#include +#include + +game_view::game_view(sf::Vector2f window_size) : + m_game(), + m_window_size{window_size}, + m_window( + sf::VideoMode(m_window_size.x, m_window_size.y), + "tresinformal game" + ) +{ + // something +} + +void game_view::exec() noexcept +{ + // Open window + m_window.create( + sf::VideoMode(m_window_size.x, m_window_size.y), + "tresinformal game" + ); + + while (m_window.isOpen()) + { + show(); + } +} + +void game_view::show() noexcept +{ + // Start drawing the new frame, by clearing the screen + m_window.clear(); + + // Display all shapes + m_window.display(); +} + +void test_game_view() //!OCLINT tests may be many +{ +#ifndef NDEBUG // no tests in release + { + // Show the game for one frame + // (there will be a member function 'exec' for running the game) + game_view v; + v.show(); + } +#endif //NDEBUG +} + +#endif // LOGIC_ONLY diff --git a/game_view.h b/game_view.h new file mode 100644 index 0000000..b712699 --- /dev/null +++ b/game_view.h @@ -0,0 +1,54 @@ +#ifndef GAME_VIEW_H +#define GAME_VIEW_H + +#include "game.h" +#include + +/// The game's main window +/// Displays the game class +class game_view +{ +public: + game_view( + sf::Vector2f window_size = sf::Vector2f(1280, 720) + ); + + /// Show one frame + void show() noexcept; + + /// Run the game until the window is closed + void exec() noexcept; + + /// Process one timestep + //void tick() { m_game.tick(); } + + ///Gets a const ref to m_game + const game& get_game() const noexcept {return m_game; } + + // Get the size of the window + const sf::Vector2f& get_window_size() const noexcept { return m_window_size; } + + // Get the window's state, for testing purposes only + bool is_window_open() const { return m_window.isOpen(); } + + ///Gets constant ref to sf::RenderWindow m_window + const sf::RenderWindow& get_window() const noexcept {return m_window; } + +private: + /// Processes events in game and ouputs false if quit + /// is inputted + bool process_events(); + + /// The game logic + game m_game; + + // The size of the window to draw + sf::Vector2f m_window_size; + + /// The window to draw to + sf::RenderWindow m_window; +}; + +void test_game_view(); + +#endif // GAME_VIEW_H diff --git a/main.cpp b/main.cpp index 25afd5c..82c7656 100644 --- a/main.cpp +++ b/main.cpp @@ -9,17 +9,21 @@ #include "ball.h" #include "game.h" #include "player.h" +#include "game_view.h" void test() { - // TODO: populate with test functions test_ball(); test_game(); test_player(); + #ifndef LOGIC_ONLY + test_game_view(); + #endif } -int main(int argc, char **argv) { - // Do something with args to not get a warning - const std::vector args(argv, argv + argc); + +int main() //!OCLINT tests may be long +{ + #ifndef NDEBUG assert(0.1 > 0.0); //!OCLINT indeed a constant conditional test(); @@ -28,6 +32,14 @@ int main(int argc, char **argv) { assert(1 == 2); #endif +#ifdef LOGIC_ONLY + std::cout << "Compiled with LOGIC_ONLY\n"; +#else + // Cannot show game on GitHub Actions + game_view v; + v.exec(); +#endif + std::cout << "Hello Basketballers!\n"; - return 0; // Game completed succesfully + return 0; // Game completes successfully } diff --git a/screenshots/20240221.png b/screenshots/20240221.png new file mode 100644 index 0000000..8c343c3 Binary files /dev/null and b/screenshots/20240221.png differ