Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 2 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions game.pri
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
SOURCES += \
$$PWD/ball.cpp \
$$PWD/game.cpp \
$$PWD/game_view.cpp \
$$PWD/main.cpp \
$$PWD/player.cpp

Expand All @@ -17,4 +18,5 @@ SOURCES += \
HEADERS += \
$$PWD/ball.h \
$$PWD/game.h \
$$PWD/game_view.h \
$$PWD/player.h
11 changes: 10 additions & 1 deletion game.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
56 changes: 56 additions & 0 deletions game_view.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "game_view.h"

#ifndef LOGIC_ONLY // so this is NOT compiled on GitHub Actions

#include "game.h"
#include <SFML/Graphics.hpp>
#include <string>
#include <sstream>

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
54 changes: 54 additions & 0 deletions game_view.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef GAME_VIEW_H
#define GAME_VIEW_H

#include "game.h"
#include <SFML/Graphics.hpp>

/// 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
22 changes: 17 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> args(argv, argv + argc);

int main() //!OCLINT tests may be long
{

#ifndef NDEBUG
assert(0.1 > 0.0); //!OCLINT indeed a constant conditional
test();
Expand All @@ -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
}
Binary file added screenshots/20240221.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.