Skip to content

Commit

Permalink
Tema #2
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-velicu committed Nov 19, 2023
1 parent 2703291 commit 670bd3a
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 43 deletions.
Binary file modified .DS_Store
Binary file not shown.
21 changes: 0 additions & 21 deletions .vscode/launch.json

This file was deleted.

3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,18 @@ endif()
###############################################################################

# NOTE: update executable name in .github/workflows/cmake.yml:25 when changing name here
add_executable(${PROJECT_NAME} main.cpp doodle_jump/game/Game.cpp doodle_jump/platform/Platform.cpp doodle_jump/player/Player.cpp doodle_jump/screen/GameScreen.cpp doodle_jump/screen/MainMenu.cpp doodle_jump/screen/PlayScreen.cpp doodle_jump/screen/GameOver.cpp doodle_jump/game_object/GameObject.cpp doodle_jump/powerups/Powerups.cpp)
add_executable(${PROJECT_NAME} main.cpp
doodle_jump/player/Player.cpp
doodle_jump/game/Game.cpp
doodle_jump/game_object/GameObject.cpp
doodle_jump/platform/Platform.cpp
doodle_jump/powerups/Powerups.cpp
doodle_jump/screen/GameOver.cpp
doodle_jump/screen/GameScreen.cpp
doodle_jump/screen/MainMenu.cpp
doodle_jump/screen/PlayScreen.cpp
doodle_jump/exceptions/Exceptions.cpp
)

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

Expand Down Expand Up @@ -158,6 +169,5 @@ endif()
# copy binaries to "bin" folder; these are uploaded as artifacts on each release
# update name in .github/workflows/cmake.yml:29 when changing "bin" name here
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(DIRECTORY assets fonts DESTINATION bin)
# install(DIRECTORY some_dir1 some_dir2 DESTINATION bin)
install(DIRECTORY Assets DESTINATION bin)
# install(FILES some_file1.txt some_file2.md DESTINATION bin)
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#### In acest proiect voi recrea popularul joc mobil Doodle Jump folosind limbajul de programare C++ alaturi de libraria SFML pentru interfata grafica.

## Known Issues

This comment has been minimized.

Copy link
@mcmarius

mcmarius Dec 23, 2023

Poți să lași așa, dar pe viitor ți-aș recomanda din motive de "marketing" să nu pui astfel de secțiuni în prim plan: ai vrea să te lauzi cu ce merge, nu cu ce nu merge


- Peste scor ~30k playerul iese din ecran

### Tema 0

- [x] Nume proiect (poate fi schimbat ulterior)
Expand Down Expand Up @@ -39,11 +43,11 @@
- [x] smart pointers (recomandat, opțional)
- [x] `dynamic_cast`/`std::dynamic_pointer_cast` pentru downcast cu sens
- [x] suprascris cc/op= pentru copieri/atribuiri corecte, copy and swap
- [ ] excepții
- [ ] ierarhie proprie cu baza `std::exception` sau derivată din `std::exception`; minim 2 clase pentru erori specifice
- [ ] utilizare cu sens: de exemplu, `throw` în constructor, `try`/`catch` în `main`
- [ ] funcții și atribute `static`
- [ ] STL
- [x] excepții
- [x] ierarhie proprie cu baza `std::exception` sau derivată din `std::exception`; minim 2 clase pentru erori specifice
- [x] utilizare cu sens: de exemplu, `throw` în constructor, `try`/`catch` în `main`
- [x] funcții și atribute `static`
- [x] STL
- [x] cât mai multe `const`
- [ ] la sfârșit: commit separat cu adăugarea unei noi clase derivate fără a modifica restul codului, pe lângă cele 3 derivate deja adăugate
- noua derivată nu poate fi una existentă care a fost ștearsă și adăugată din nou
Expand Down
9 changes: 9 additions & 0 deletions doodle_jump/exceptions/Exceptions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "Exceptions.h"

const char* PlayerOutOfBoundException::what() const noexcept {
return "Player is out of bound";
}

const char* RandomException::what() const noexcept {
return "Random exception";
}
11 changes: 11 additions & 0 deletions doodle_jump/exceptions/Exceptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <iostream>

class PlayerOutOfBoundException : public std::exception {
public:
[[nodiscard]] const char* what() const noexcept override;
};

class RandomException : public std::exception {

This comment has been minimized.

Copy link
@mcmarius

mcmarius Dec 17, 2023

Ar trebui să ai o clasă de bază comună definită tot de tine ca să diferențiezi între excepțiile tale și altceva derivat din std::exception

public:
[[nodiscard]] const char* what() const noexcept override;
};
12 changes: 12 additions & 0 deletions doodle_jump/game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "./../screen/MainMenu.h"
#include "./../screen/PlayScreen.h"
#include "./../screen/GameOver.h"
#include "./../exceptions/Exceptions.h"
#include <iostream>
#include <memory>
#include <string>
Expand Down Expand Up @@ -99,6 +100,7 @@ void Game::reset() {

void Game::run() {
std::cout << "Game run called\n";
Game::setDifficulty(1);

while (window.isOpen()) {
sf::Event e = sf::Event();
Expand Down Expand Up @@ -155,6 +157,10 @@ void Game::run() {
}
}

void Game::setDifficulty(int difficulty) {
Game::difficulty = difficulty;
}

void Game::checkCollision() {
// Get only lower part of player sprite
sf::FloatRect lowerPlayerBounds = player.getSprite().getGlobalBounds();
Expand Down Expand Up @@ -264,6 +270,12 @@ void Game::play() {
gameObject->moveSprite({0.0f, velocity.y});
// player.moveSprite({0.0f, velocity.y});
}

// Check if player is out of bounds
if (player.getSprite().getPosition().y < 0.0f) {
throw PlayerOutOfBoundException();
}

player.moveSprite({velocity.x, 0.0f});

window.clear(sf::Color::White);
Expand Down
3 changes: 2 additions & 1 deletion doodle_jump/game/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Game {
float maxScore;
sf::Text scoreText;
Player player;
static int difficulty;

sf::Sprite backgroundSprite[2] = { sf::Sprite(), sf::Sprite() };
std::vector<sf::Texture> platformTextures = std::vector<sf::Texture>();
Expand All @@ -38,8 +39,8 @@ class Game {
void changeScreen(ScreenType screenType);
void play();
void reset();
// void displayDebugInfo();
void initTextures();
static void setDifficulty(int difficulty);
sf::Texture& pickTexture(PlatformType platformType);
sf::Texture& pickTexture(PowerupsType powerupsType);
void displayScore();
Expand Down
7 changes: 7 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <time.h>

#include "./doodle_jump/game/Game.h"
#include "./doodle_jump/exceptions/Exceptions.h"

#ifdef __linux__
#include <X11/Xlib.h>
Expand All @@ -16,6 +17,12 @@ int main() {

srand(time(NULL));

try {
throw RandomException();

This comment has been minimized.

Copy link
@mcmarius

mcmarius Dec 17, 2023

😕 ar trebui ceva mai cu sens; aici e fix degeaba: o dată ai doar un throw în blocul de try și apoi ai throw și catch fix în același loc, deci nu ajută cu nimic; e echivalent cu un if/else, dar complicat

} catch (const std::exception& e) {
std::cout << e.what() << '\n';
}

Game game = Game();
std::cout << game << '\n';

Expand Down
10 changes: 0 additions & 10 deletions my_files.txt

This file was deleted.

Empty file removed tastatura.txt
Empty file.

0 comments on commit 670bd3a

Please sign in to comment.