Skip to content

Commit

Permalink
aproape gata tema 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mariapreda19 committed Apr 28, 2023
1 parent 8cbf9d7 commit 7e9c849
Show file tree
Hide file tree
Showing 17 changed files with 773 additions and 128 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ endif()
###############################################################################

# NOTE: update executable name in .github/workflows/cmake.yml:25 when changing name here
add_executable(${PROJECT_NAME} main.cpp src/Player.cpp src/Game.cpp src/Question.cpp src/Button.cpp src/Timer.cpp)
add_executable(${PROJECT_NAME} main.cpp src/Player.cpp src/Game.cpp src/Question.cpp src/Button.cpp src/Timer.cpp src/Erori.cpp)

###############################################################################

Expand Down
Binary file added background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added button1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added button2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions headers/Button.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@


class Button{
sf::Vector2f position;
std::string text;
std::string texture; // path to texture

public:
Button (sf::Vector2f position_, std::string text, std::string texture_);
Button (std::string text, std::string texture_);

Button(const Button& other);

Button& operator=(const Button& other);

~Button();

bool displayButton(sf::RenderWindow &window);
bool displayButton(sf::RenderWindow &window, sf::Vector2f position);

friend std::ostream& operator<<(std::ostream& os, const Button& button);

Expand Down
19 changes: 19 additions & 0 deletions headers/Erori.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Created by 40773 on 23/04/2023.
//

#ifndef OOP_ERORI_H
#define OOP_ERORI_H
#include <stdexcept>

class eroare_fisier : public std::runtime_error {
public:
explicit eroare_fisier(const std::string& mesaj);
};

class eroare_fereastra : public std::runtime_error {
public:
explicit eroare_fereastra(const std::string& mesaj);
};

#endif //OOP_ERORI_H
7 changes: 3 additions & 4 deletions headers/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
#include <vector>
#include <fstream>
#include "SFML/Graphics.hpp"
#include "Erori.h"


class Game {
private:
std::vector<Question> questions;
Screen *startScreen;
std::vector<Screen *> questions;
std::vector<Player> players;

void loadQuestions(const std::string& filePath);
Expand All @@ -24,15 +26,12 @@ class Game {

explicit Game(const std::string& questionsFilePath, const std::vector<Player>& players_ = {});

Game([[maybe_unused]] const Game& other);

/*Game([[maybe_unused]] const Game&& other) noexcept {
questions = other.questions;
players = other.players;
}*/

Game& operator=(const Game& other);

friend std::ostream& operator<<(std::ostream& os, const Game& game);


Expand Down
53 changes: 39 additions & 14 deletions headers/Question.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <vector>
#include "Button.h"
#include "SFML/Graphics.hpp"
#include "Timer.h"

class Screen {
std::string text;
Expand All @@ -19,14 +20,20 @@ class Screen {

friend std::ostream& operator<<(std::ostream& os, const Screen& screen);

int displayScreen(sf::RenderWindow &window);
virtual int display(sf::RenderWindow &window);

[[nodiscard]] std::basic_string<char> getText() const;
[[nodiscard]] std::vector<Button> getOptions() const;


};



class Question: public Screen {

using Screen::Screen;
int correctAnswerIndex, category;

public:
explicit Question(std::string question = "", const std::vector<std::string> &options = {}, int correct = -1, int category_ = 0);

Expand All @@ -38,23 +45,41 @@ class Question: public Screen {

[[nodiscard]] int getCategory() const;

// void printQuestion() const;

[[nodiscard]] bool checkAnswer(int userAnswer) const;

[[nodiscard]] bool askQuestion() const;
int display(sf::RenderWindow &window) override;

};
/*
class Menu: public Screen{


class MenuScreen : public Screen {
using Screen::Screen;
Button single, competitive;
public:
explicit MenuScreen(std::string text = "", const std::vector<std::string> &button_options = {"Play again", "Menu", "Quit"});

MenuScreen(const MenuScreen &other);

private:
explicit Menu(std::string text = "", const std::vector<std::string> &button_options = {},
std::string button_texture = "", std::string button_texture_clicked = "");
Menu(const Menu &other);
Menu &operator=(const Menu &other);
MenuScreen &operator=(const MenuScreen &other);

//friend std::ostream &operator<<(std::ostream &os, const MenuScreen &screen);



int display(sf::RenderWindow &window) override;
};
*/

class CategoryScreen : public Screen {
using Screen::Screen;

public:
explicit CategoryScreen(std::string text, const std::vector<std::string> &button_options = {std::string ("Music"), std::string ("Geography"), std::string ("History"), std::string ("Art"), std::string ("Literature"), std::string ("Sports")});

CategoryScreen(const CategoryScreen &other);

CategoryScreen &operator=(const CategoryScreen &other);

//friend std::ostream &operator<<(std::ostream &os, const CategoryScreen &screen);

int display(sf::RenderWindow &window) override;
};
#endif //OOP_QUESTION_H
11 changes: 6 additions & 5 deletions headers/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
#include <chrono>
#include <ctime>


class Timer {
std::chrono::seconds duration_;
std::chrono::time_point<std::chrono::high_resolution_clock> start_;
public:
Timer(int durationSeconds);
bool isExpired() const;
explicit Timer(int durationSeconds);
[[nodiscard]] bool isExpired() const;
void reset();
private:
std::chrono::nanoseconds duration_;
std::chrono::time_point<std::chrono::high_resolution_clock> start_;
[[nodiscard]] int getRemainingSeconds() const;
};


Expand Down
Binary file added primaPoza.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7e9c849

Please sign in to comment.