From 7694fe55f3751600e59d8a95efb44baae4244bac Mon Sep 17 00:00:00 2001 From: 6im0n Date: Fri, 5 Apr 2024 20:18:50 +0200 Subject: [PATCH 1/9] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20file=20path?= =?UTF-8?q?s=20in=20Makefile=20to=20use=20correct=20capitalization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index fccd8e1..f9c2f8d 100644 --- a/Makefile +++ b/Makefile @@ -35,11 +35,11 @@ SNAKE_SRC = src/snake/Entities/Void.cpp \ classes/Timer.cpp \ classes/Color.cpp \ -NCURSES_SRC = src/ncurses/ncurses.cpp \ +NCURSES_SRC = src/ncurses/Ncurses.cpp \ SFML_SRC = src/sfml/Sfml.cpp \ -SDL_SRC = src/sdl/sdl.cpp \ +SDL_SRC = src/sdl/Sdl.cpp \ SRC_TEST = tests/tests_color.cpp \ classes/Color.cpp \ @@ -116,12 +116,12 @@ games: $(NAME_PACMAN) $(NAME_SNAKE) $(call YELLOW,"❌ $<") $(NAME_PACMAN) : $(OBJ_PACMAN) - @$(LINKER) -shared -o $(NAME_PACMAN) $(OBJ_PACMAN) $(CXXFLAGS) && \ + @$(LINKER) -shared -fPIC -fPIC -o $(NAME_PACMAN) $(OBJ_PACMAN) $(CXXFLAGS) && \ $(call YELLOW,"✅ $@") || \ $(call YELLOW,"❌ $@") $(NAME_SNAKE) : $(OBJ_SNAKE) - @$(LINKER) -shared -o $(NAME_SNAKE) $(OBJ_SNAKE) $(CXXFLAGS) && \ + @$(LINKER) -shared -fPIC -fPIC -fPIC -o $(NAME_SNAKE) $(OBJ_SNAKE) $(CXXFLAGS) && \ $(call YELLOW,"✅ $@") || \ $(call YELLOW,"❌ $@") @@ -149,17 +149,17 @@ graphicals: $(NAME_NCURSES) $(NAME_SFML) $(NAME_SDL) $(call YELLOW,"❌ $<") $(NAME_NCURSES) : $(OBJ_NCURSES) - @$(LINKER) -shared -o $(NAME_NCURSES) $(OBJ_NCURSES) $(CXXFLAGS) $(NCURSES_FLAGS) && \ + @$(LINKER) -shared -fPIC -o $(NAME_NCURSES) $(OBJ_NCURSES) $(CXXFLAGS) $(NCURSES_FLAGS) && \ $(call YELLOW,"✅ $@") || \ $(call YELLOW,"❌ $@") $(NAME_SFML) : $(OBJ_SFML) - @$(LINKER) -shared -o $(NAME_SFML) $(OBJ_SFML) $(CXXFLAGS) $(SFML_FLAGS) && \ + @$(LINKER) -shared -fPIC -o $(NAME_SFML) $(OBJ_SFML) $(CXXFLAGS) $(SFML_FLAGS) && \ $(call YELLOW,"✅ $@") || \ $(call YELLOW,"❌ $@") $(NAME_SDL) : $(OBJ_SDL) - @$(LINKER) -shared -o $(NAME_SDL) $(OBJ_SDL) $(CXXFLAGS) $(SDL_FLAGS) && \ + @$(LINKER) -shared -fPIC -o $(NAME_SDL) $(OBJ_SDL) $(CXXFLAGS) $(SDL_FLAGS) && \ $(call YELLOW,"✅ $@") || \ $(call YELLOW,"❌ $@") From 91fab4a824aa7ccc9187de6b466415854478047a Mon Sep 17 00:00:00 2001 From: 6im0n Date: Fri, 5 Apr 2024 20:19:16 +0200 Subject: [PATCH 2/9] =?UTF-8?q?=F0=9F=94=A5=20Remove=20ncurses=20implement?= =?UTF-8?q?ation=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ncurses/ncurses.cpp | 78 ----------------------------------------- src/ncurses/ncurses.hpp | 37 ------------------- 2 files changed, 115 deletions(-) delete mode 100644 src/ncurses/ncurses.cpp delete mode 100644 src/ncurses/ncurses.hpp diff --git a/src/ncurses/ncurses.cpp b/src/ncurses/ncurses.cpp deleted file mode 100644 index e498d2f..0000000 --- a/src/ncurses/ncurses.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* -** EPITECH PROJECT, 2024 -** Arcade -** File description: -** ncurses.cpp -*/ - -#include "ncurses.hpp" -#include "includes/Keys.hpp" -#include -#include - -int init(void) -{ - return 0; -} - -Arcade::Ncurses::Ncurses() -{ -} - -bool Arcade::Ncurses::isWindowOpen() const -{ - return false; -} - -void Arcade::Ncurses::closeWindow() -{ -} - -void Arcade::Ncurses::clearWindow() -{ -} - -int Arcade::Ncurses::getKeyEvent() -{ - return Keys::A; -} - -void Arcade::Ncurses::displayWindow() -{ -} - -void Arcade::Ncurses::displayEntities(std::vector> entities) -{ - (void)entities; -} - -void Arcade::Ncurses::displayText(std::vector> texts) -{ - (void)texts; -} - -void Arcade::Ncurses::playSound(std::vector> sounds) -{ - (void)sounds; -} - -std::pair Arcade::Ncurses::getMousePosition() -{ - return std::make_pair(0, 0); -} - -extern "C" -{ - __attribute__((constructor)) - void constructor() - { - } - __attribute__((destructor)) - void destructor() - { - } - Arcade::Ncurses *loadGraphicInstance() - { - return new Arcade::Ncurses(); - } -} diff --git a/src/ncurses/ncurses.hpp b/src/ncurses/ncurses.hpp deleted file mode 100644 index 9af622a..0000000 --- a/src/ncurses/ncurses.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* -** EPITECH PROJECT, 2024 -** Arcade -** File description: -** ncurses.hpp -*/ - -#pragma once - -#include "Interfaces/IGraphic.hpp" -#include "includes/Keys.hpp" - -namespace Arcade { - class Ncurses : public IGraphic { - public: - Ncurses(); - ~Ncurses() = default; - bool isWindowOpen() const override; - void closeWindow(); - void clearWindow(); - - //Event - int getKeyEvent() override; - std::pair getMousePosition(); - - //Display - void displayWindow(); - void displayEntities(std::vector> entities) override; - void displayText(std::vector> texts) override; - void playSound(std::vector> sounds) override; - private: - std::vector _entities; - std::vector _texts; - std::vector _sounds; - Keys _key; - }; -} From 63b45ac37b5ca1a7984de439b9277e5e402f2cc3 Mon Sep 17 00:00:00 2001 From: 6im0n Date: Fri, 5 Apr 2024 20:19:46 +0200 Subject: [PATCH 3/9] =?UTF-8?q?=F0=9F=9A=A7=20Work=20in=20progress=20the?= =?UTF-8?q?=20ncurse=20implementation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ncurses/Ncurses.cpp | 150 ++++++++++++++++++++++++++++++++++++++++ src/ncurses/Ncurses.hpp | 38 ++++++++++ 2 files changed, 188 insertions(+) create mode 100644 src/ncurses/Ncurses.cpp create mode 100644 src/ncurses/Ncurses.hpp diff --git a/src/ncurses/Ncurses.cpp b/src/ncurses/Ncurses.cpp new file mode 100644 index 0000000..ba43ad4 --- /dev/null +++ b/src/ncurses/Ncurses.cpp @@ -0,0 +1,150 @@ +/* +** EPITECH PROJECT, 2024 +** Arcade +** File description: +** ncurses.cpp +*/ + +#include "Ncurses.hpp" +#include "includes/Keys.hpp" +#include +#include + +Arcade::Ncurses::Ncurses() +{ + initscr(); +} + +bool Arcade::Ncurses::isWindowOpen() const +{ + return true; +} + +void Arcade::Ncurses::closeWindow() +{ + endwin(); +} + +void Arcade::Ncurses::clearWindow() +{ + clear(); +} + +int Arcade::Ncurses::getKeyEvent() +{ + int key = getch(); + if (key == 27) + return Arcade::Keys::ESCAPE; + if (key == 10) + return Arcade::Keys::ENTER; + if (key == 32) + return Arcade::Keys::SPACE; + if (key == 65) + return Arcade::Keys::UP; + if (key == 66) + return Arcade::Keys::DOWN; + if (key == 67) + return Arcade::Keys::RIGHT; + if (key == 68) + return Arcade::Keys::LEFT; + if (key == 97) + return Arcade::Keys::A; + if (key == 98) + return Arcade::Keys::B; + if (key == 99) + return Arcade::Keys::C; + if (key == 100) + return Arcade::Keys::D; + if (key == 101) + return Arcade::Keys::E; + if (key == 102) + return Arcade::Keys::F; + if (key == 103) + return Arcade::Keys::G; + if (key == 104) + return Arcade::Keys::H; + if (key == 105) + return Arcade::Keys::I; + if (key == 106) + return Arcade::Keys::J; + if (key == 107) + return Arcade::Keys::K; + if (key == 108) + return Arcade::Keys::L; + if (key == 109) + return Arcade::Keys::M; + if (key == 110) + return Arcade::Keys::N; + if (key == 111) + return Arcade::Keys::O; + if (key == 112) + return Arcade::Keys::P; + if (key == 113) + return Arcade::Keys::Q; + if (key == 114) + return Arcade::Keys::R; + if (key == 115) + return Arcade::Keys::S; + if (key == 116) + return Arcade::Keys::T; + if (key == 117) + return Arcade::Keys::U; + if (key == 118) + return Arcade::Keys::V; + if (key == 119) + return Arcade::Keys::W; + if (key == 120) + return Arcade::Keys::X; + + return -1; +} + +std::pair Arcade::Ncurses::getMousePosition() +{ + return std::make_pair(0, 0); +} + +void Arcade::Ncurses::displayWindow() +{ + refresh(); +} + +void Arcade::Ncurses::displayEntities(std::vector> entities) +{ + for (auto &entity : entities) { + auto color = entity->getColor(); + start_color(); + init_pair(255,255,255); + attron(COLOR_PAIR(1)); + mvprintw(entity->getPos()[1] * 29 , entity->getPos()[0] *29, "%c", entity->getChar()); + attroff(COLOR_PAIR(1)); + } +} + +void Arcade::Ncurses::displayText(std::vector> texts) +{ + for (auto &text : texts) { + mvprintw(text->getPos()[1] *29 , text->getPos()[0] * 29, "%s", text->getText().c_str()); + } +} + +void Arcade::Ncurses::playSound(std::vector> sounds) +{ + (void)sounds; +} + +extern "C" +{ + __attribute__((constructor)) + void constructor() + { + } + __attribute__((destructor)) + void destructor() + { + } + Arcade::Ncurses *loadGraphicInstance() + { + return new Arcade::Ncurses(); + } +} diff --git a/src/ncurses/Ncurses.hpp b/src/ncurses/Ncurses.hpp new file mode 100644 index 0000000..743a8f8 --- /dev/null +++ b/src/ncurses/Ncurses.hpp @@ -0,0 +1,38 @@ +/* +** EPITECH PROJECT, 2024 +** Arcade +** File description: +** ncurses.hpp +*/ + +#pragma once + +#include "Interfaces/IGraphic.hpp" +#include "includes/Keys.hpp" +#include + +namespace Arcade { + class Ncurses : public IGraphic { + public: + Ncurses(); + ~Ncurses() = default; + bool isWindowOpen() const override; + void closeWindow() override; + void clearWindow() override; + + //Event + int getKeyEvent() override; + std::pair getMousePosition() override; + + //Display + void displayWindow() override; + void displayEntities(std::vector> entities) override; + void displayText(std::vector> texts) override; + void playSound(std::vector> sounds) override; + private: + std::vector _entities; + std::vector _texts; + std::vector _sounds; + Keys _key; + }; +} From 1161d77a2c5fb916d1584fa9fcf3d94ff9aac04f Mon Sep 17 00:00:00 2001 From: 6im0n Date: Sat, 6 Apr 2024 04:20:27 +0200 Subject: [PATCH 4/9] =?UTF-8?q?=E2=9C=A8=20Add=20the=20implementation=20of?= =?UTF-8?q?=20the=20ncurse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ncurses/Ncurses.cpp | 188 ++++++++++++++++++++++++---------------- src/ncurses/Ncurses.hpp | 3 +- 2 files changed, 117 insertions(+), 74 deletions(-) diff --git a/src/ncurses/Ncurses.cpp b/src/ncurses/Ncurses.cpp index ba43ad4..3c60237 100644 --- a/src/ncurses/Ncurses.cpp +++ b/src/ncurses/Ncurses.cpp @@ -7,12 +7,31 @@ #include "Ncurses.hpp" #include "includes/Keys.hpp" +#include +#include #include #include + Arcade::Ncurses::Ncurses() { initscr(); + noecho(); + keypad(stdscr, TRUE); + nodelay(stdscr, TRUE); + curs_set(0); + start_color(); + init_color(COLOR_BLACK, 0, 0, 0); + init_pair(1, COLOR_WHITE, COLOR_BLACK); + init_pair(2, COLOR_RED, COLOR_BLACK); + init_pair(3, COLOR_GREEN, COLOR_BLACK); + init_pair(4, COLOR_BLUE, COLOR_BLACK); + init_pair(5, COLOR_YELLOW, COLOR_BLACK); + init_pair(6, COLOR_MAGENTA, COLOR_BLACK); + init_pair(7, COLOR_CYAN, COLOR_BLACK); + init_pair(8, COLOR_WHITE, COLOR_BLACK); + wbkgd(stdscr, COLOR_PAIR(1)); + } bool Arcade::Ncurses::isWindowOpen() const @@ -27,81 +46,74 @@ void Arcade::Ncurses::closeWindow() void Arcade::Ncurses::clearWindow() { - clear(); + for (int i = 0; i < LINES; i++) { + for (int j = 0; j < COLS; j++) { + mvprintw(i, j, " "); + } + } } int Arcade::Ncurses::getKeyEvent() { int key = getch(); - if (key == 27) - return Arcade::Keys::ESCAPE; - if (key == 10) - return Arcade::Keys::ENTER; - if (key == 32) - return Arcade::Keys::SPACE; - if (key == 65) - return Arcade::Keys::UP; - if (key == 66) - return Arcade::Keys::DOWN; - if (key == 67) - return Arcade::Keys::RIGHT; - if (key == 68) - return Arcade::Keys::LEFT; - if (key == 97) - return Arcade::Keys::A; - if (key == 98) - return Arcade::Keys::B; - if (key == 99) - return Arcade::Keys::C; - if (key == 100) - return Arcade::Keys::D; - if (key == 101) - return Arcade::Keys::E; - if (key == 102) - return Arcade::Keys::F; - if (key == 103) - return Arcade::Keys::G; - if (key == 104) - return Arcade::Keys::H; - if (key == 105) - return Arcade::Keys::I; - if (key == 106) - return Arcade::Keys::J; - if (key == 107) - return Arcade::Keys::K; - if (key == 108) - return Arcade::Keys::L; - if (key == 109) - return Arcade::Keys::M; - if (key == 110) - return Arcade::Keys::N; - if (key == 111) - return Arcade::Keys::O; - if (key == 112) - return Arcade::Keys::P; - if (key == 113) - return Arcade::Keys::Q; - if (key == 114) - return Arcade::Keys::R; - if (key == 115) - return Arcade::Keys::S; - if (key == 116) - return Arcade::Keys::T; - if (key == 117) - return Arcade::Keys::U; - if (key == 118) - return Arcade::Keys::V; - if (key == 119) - return Arcade::Keys::W; - if (key == 120) - return Arcade::Keys::X; - - return -1; + static std::map keyMap = { + {'A', Arcade::Keys::A}, + {'B', Arcade::Keys::B}, + {'C', Arcade::Keys::C}, + {'D', Arcade::Keys::D}, + {'E', Arcade::Keys::E}, + {'F', Arcade::Keys::F}, + {'G', Arcade::Keys::G}, + {'H', Arcade::Keys::H}, + {'I', Arcade::Keys::I}, + {'J', Arcade::Keys::J}, + {'K', Arcade::Keys::K}, + {'L', Arcade::Keys::L}, + {'M', Arcade::Keys::M}, + {'N', Arcade::Keys::N}, + {'O', Arcade::Keys::O}, + {'P', Arcade::Keys::P}, + {'Q', Arcade::Keys::Q}, + {'R', Arcade::Keys::R}, + {'S', Arcade::Keys::S}, + {'T', Arcade::Keys::T}, + {'U', Arcade::Keys::U}, + {'V', Arcade::Keys::V}, + {'W', Arcade::Keys::W}, + {'X', Arcade::Keys::X}, + {'Y', Arcade::Keys::Y}, + {'Z', Arcade::Keys::Z}, + {'1', Arcade::Keys::ONE}, + {'2', Arcade::Keys::TWO}, + {'3', Arcade::Keys::THREE}, + {'4', Arcade::Keys::FOUR}, + {'5', Arcade::Keys::FIVE}, + {'6', Arcade::Keys::SIX}, + {'7', Arcade::Keys::SEVEN}, + {'8', Arcade::Keys::EIGHT}, + {'9', Arcade::Keys::NINE}, + {'0', Arcade::Keys::ZERO}, + {27, Arcade::Keys::ESCAPE}, + {9, Arcade::Keys::TAB}, + {KEY_BACKSPACE, Arcade::Keys::BACKSPACE}, + {KEY_UP, Arcade::Keys::UP}, + {KEY_DOWN, Arcade::Keys::DOWN}, + {KEY_LEFT, Arcade::Keys::LEFT}, + {KEY_RIGHT, Arcade::Keys::RIGHT}, + {10, Arcade::Keys::ENTER}, + {32, Arcade::Keys::SPACE}, + {KEY_MOUSE, Arcade::Keys::MOUSE_LEFT} + }; + return keyMap[key]; } std::pair Arcade::Ncurses::getMousePosition() { - return std::make_pair(0, 0); + MEVENT event; + if (getmouse(&event) == OK) { + return {event.x * 29 , event.y * 29}; + } + return {-1, -1}; } void Arcade::Ncurses::displayWindow() @@ -109,22 +121,52 @@ void Arcade::Ncurses::displayWindow() refresh(); } +int Arcade::Ncurses::colorToNcurses(const std::shared_ptr& color) +{ + int bestColor = 1; + double minDistance = 1000000; + + std::map> colors = { + {1, {255, 255, 255, 255}}, + {2, {255, 0, 0, 255}}, + {3, {0, 255, 0, 255}}, + {4, {0, 0, 255, 255}}, + {5, {255, 255, 0, 255}}, + {6, {255, 0, 255, 255}}, + {7, {0, 255, 255, 255}}, + {8, {255, 255, 255, 255}} + + }; + + for (auto &colorPair : colors) { + double distance = sqrt(pow(std::get<0>(colorPair.second) - color->getR(), 2) + pow(std::get<1>(colorPair.second) - color->getG(), 2) + pow(std::get<2>(colorPair.second) - color->getB(), 2)); + if (distance < minDistance) { + minDistance = distance; + bestColor = colorPair.first; + } + } + return bestColor; +} + void Arcade::Ncurses::displayEntities(std::vector> entities) { for (auto &entity : entities) { - auto color = entity->getColor(); - start_color(); - init_pair(255,255,255); - attron(COLOR_PAIR(1)); - mvprintw(entity->getPos()[1] * 29 , entity->getPos()[0] *29, "%c", entity->getChar()); - attroff(COLOR_PAIR(1)); + int x = colorToNcurses(entity->getColor()); + wattron(stdscr, COLOR_PAIR(x)); + mvwaddch(stdscr, entity->getPos()[1], entity->getPos()[0], (char)entity->getChar()); + wattroff(stdscr, COLOR_PAIR(x)); } } void Arcade::Ncurses::displayText(std::vector> texts) { for (auto &text : texts) { - mvprintw(text->getPos()[1] *29 , text->getPos()[0] * 29, "%s", text->getText().c_str()); + int x = colorToNcurses(text->getColor()); + if (text->getFontPath().empty()) + continue; + wattron(stdscr, COLOR_PAIR(x)); + mvprintw(text->getPos()[1], text->getPos()[0], "%s", text->getText().c_str()); + wattroff(stdscr, COLOR_PAIR(x)); } } diff --git a/src/ncurses/Ncurses.hpp b/src/ncurses/Ncurses.hpp index 743a8f8..62dd6f5 100644 --- a/src/ncurses/Ncurses.hpp +++ b/src/ncurses/Ncurses.hpp @@ -15,7 +15,7 @@ namespace Arcade { class Ncurses : public IGraphic { public: Ncurses(); - ~Ncurses() = default; + ~Ncurses() override = default; bool isWindowOpen() const override; void closeWindow() override; void clearWindow() override; @@ -30,6 +30,7 @@ namespace Arcade { void displayText(std::vector> texts) override; void playSound(std::vector> sounds) override; private: + static int colorToNcurses(const std::shared_ptr& color); std::vector _entities; std::vector _texts; std::vector _sounds; From 32c6bd8f98c181ea4765aba897f3cf7fa7a0275b Mon Sep 17 00:00:00 2001 From: 6im0n Date: Sat, 6 Apr 2024 04:22:26 +0200 Subject: [PATCH 5/9] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20class=20met?= =?UTF-8?q?hods=20to=20use=20override=20keyword?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abstract/AGame.hpp | 18 +++++++++--------- classes/Color.hpp | 12 ++++++------ classes/Text.cpp | 2 +- classes/Text.hpp | 28 ++++++++++++++-------------- src/snake/Entities/Food.hpp | 30 +++++++++++++++--------------- src/snake/Entities/SnakeBody.hpp | 28 ++++++++++++++-------------- src/snake/Entities/Void.hpp | 28 ++++++++++++++-------------- src/snake/Entities/Wall.hpp | 28 ++++++++++++++-------------- src/snake/Score.hpp | 26 +++++++++++++------------- src/snake/SnakeGame.hpp | 20 ++++++++++---------- 10 files changed, 110 insertions(+), 110 deletions(-) diff --git a/abstract/AGame.hpp b/abstract/AGame.hpp index 85f1fcb..d341438 100644 --- a/abstract/AGame.hpp +++ b/abstract/AGame.hpp @@ -12,21 +12,21 @@ namespace Arcade { class AGame : public IGame { public: - virtual ~AGame() = default; + ~AGame() override = default; //Game - virtual int startGame() = 0; - virtual int stopGame() = 0; - int getScore(); - virtual int simulate() = 0; + int startGame() override = 0; + int stopGame() override = 0; + int getScore() override; + int simulate() override = 0; //Event - virtual void catchKeyEvent(int key) = 0; + void catchKeyEvent(int key) override = 0; //Display - std::vector> getEntities(); - std::vector> getTexts(); - std::vector> getSounds(); + std::vector> getEntities() override; + std::vector> getTexts() override; + std::vector> getSounds() override; protected: std::vector> _entities; diff --git a/classes/Color.hpp b/classes/Color.hpp index 14ecf07..7c4df50 100644 --- a/classes/Color.hpp +++ b/classes/Color.hpp @@ -13,14 +13,14 @@ namespace Arcade { class Color : public IColor { public: Color(short r, short g, short b, short a); - ~Color() = default; + ~Color() override = default; - void setColor(short r, short g, short b, short a); + void setColor(short r, short g, short b, short a) override; - short getR(); - short getG(); - short getB(); - short getA(); + short getR() override; + short getG() override; + short getB() override; + short getA() override; private: short _r; diff --git a/classes/Text.cpp b/classes/Text.cpp index fa8543e..d74fada 100644 --- a/classes/Text.cpp +++ b/classes/Text.cpp @@ -58,7 +58,7 @@ std::string Arcade::Text::getText() std::shared_ptr Arcade::Text::getColor() const { - return std::shared_ptr(_color.get()); + return _color; } std::vector Arcade::Text::getPos() const diff --git a/classes/Text.hpp b/classes/Text.hpp index 1ecd64e..1b1f0a8 100644 --- a/classes/Text.hpp +++ b/classes/Text.hpp @@ -14,27 +14,27 @@ namespace Arcade { class Text : public IText { public: Text(std::string text, std::vector pos, std::vector size, char c); - ~Text() = default; + ~Text() override = default; - void setFontPath(const std::string &fontPath); - void setText(const std::string &text); - void setColor(std::unique_ptr color); - void setPos(std::size_t x, std::size_t y); - void setSize(std::size_t x); - void setRotation(float rotation); + void setFontPath(const std::string &fontPath) override; + void setText(const std::string &text) override; + void setColor(std::unique_ptr color) override; + void setPos(std::size_t x, std::size_t y) override; + void setSize(std::size_t x) override; + void setRotation(float rotation) override; //getters - std::string getFontPath(); - std::string getText(); - std::shared_ptr getColor() const; - std::vector getPos() const; - std::size_t getSize() const; - float getRotation() const; + std::string getFontPath() override; + std::string getText() override; + std::shared_ptr getColor() const override; + std::vector getPos() const override; + std::size_t getSize() const override; + float getRotation() const override; private: std::string _text; std::vector _pos; std::vector _size; - std::unique_ptr _color; + std::shared_ptr _color; std::string _fontPath; float _rotation; char _c; diff --git a/src/snake/Entities/Food.hpp b/src/snake/Entities/Food.hpp index 67a78d6..f25fb33 100644 --- a/src/snake/Entities/Food.hpp +++ b/src/snake/Entities/Food.hpp @@ -13,24 +13,24 @@ namespace Arcade { class Food : public IEntity { public: - Food(Snake snake); - ~Food() = default; + explicit Food(Snake snake); + ~Food() override = default; //setters - void setPos(std::size_t x, std::size_t y); - void setSize(std::size_t x, std::size_t y); - void setChar(char c); - void setColor(std::unique_ptr color); - void setPath(const std::string &path); - void setRotation(float rotation); + void setPos(std::size_t x, std::size_t y) override; + void setSize(std::size_t x, std::size_t y) override; + void setChar(char c) override; + void setColor(std::unique_ptr color) override; + void setPath(const std::string &path) override; + void setRotation(float rotation) override; - //getters - std::vector getPos() const; - std::vector getSize() const; - int getChar() const; - std::shared_ptr getColor() const; - std::string getPath() const; - float getRotation() const; + //getter + std::vector getPos() const override; + std::vector getSize() const override; + int getChar() const override; + std::shared_ptr getColor() const override; + std::string getPath() const override; + float getRotation() const override; private: std::vector _pos; diff --git a/src/snake/Entities/SnakeBody.hpp b/src/snake/Entities/SnakeBody.hpp index 61a5e64..4732a9c 100644 --- a/src/snake/Entities/SnakeBody.hpp +++ b/src/snake/Entities/SnakeBody.hpp @@ -15,25 +15,25 @@ namespace Arcade { class SnakeBody : public IEntity { public: SnakeBody(std::size_t x, std::size_t y, std::string path, Direction dir); - ~SnakeBody() = default; + ~SnakeBody() override = default; //setters - void setPos(std::size_t x, std::size_t y); - void setSize(std::size_t x, std::size_t y); - void setChar(char c); - void setColor(std::unique_ptr color); - void setPath(const std::string &path); - void setRotation(float rotation); + void setPos(std::size_t x, std::size_t y) override; + void setSize(std::size_t x, std::size_t y) override; + void setChar(char c) override; + void setColor(std::unique_ptr color) override; + void setPath(const std::string &path) override; + void setRotation(float rotation) override; void setDirection(Direction dir); void updateRotation(); - //getters - std::vector getPos() const; - std::vector getSize() const; - int getChar() const; - std::shared_ptr getColor() const; - std::string getPath() const; - float getRotation() const; + //getter + std::vector getPos() const override; + std::vector getSize() const override; + int getChar() const override; + std::shared_ptr getColor() const override; + std::string getPath() const override; + float getRotation() const override; Direction getDirection() const; private: diff --git a/src/snake/Entities/Void.hpp b/src/snake/Entities/Void.hpp index b40c777..c5f194d 100644 --- a/src/snake/Entities/Void.hpp +++ b/src/snake/Entities/Void.hpp @@ -13,23 +13,23 @@ namespace Arcade { class Void : public IEntity { public: Void(std::size_t x, std::size_t y); - ~Void() = default; + ~Void() override = default; //setters - void setPos(std::size_t x, std::size_t y); - void setSize(std::size_t x, std::size_t y); - void setChar(char c); - void setColor(std::unique_ptr color); - void setPath(const std::string &path); - void setRotation(float rotation); + void setPos(std::size_t x, std::size_t y) override; + void setSize(std::size_t x, std::size_t y) override; + void setChar(char c) override; + void setColor(std::unique_ptr color) override; + void setPath(const std::string &path) override; + void setRotation(float rotation) override; - //getters - std::vector getPos() const; - std::vector getSize() const; - int getChar() const; - std::shared_ptr getColor() const; - std::string getPath() const; - float getRotation() const; + //getter overrides + std::vector getPos() const override; + std::vector getSize() const override; + int getChar() const override; + std::shared_ptr getColor() const override; + std::string getPath() const override; + float getRotation() const override; private: std::vector _pos; diff --git a/src/snake/Entities/Wall.hpp b/src/snake/Entities/Wall.hpp index d674e2a..af4d8e9 100644 --- a/src/snake/Entities/Wall.hpp +++ b/src/snake/Entities/Wall.hpp @@ -13,23 +13,23 @@ namespace Arcade { class Wall : public IEntity { public: Wall(std::size_t x, std::size_t y); - ~Wall() = default; + ~Wall() override = default; //setters - void setPos(std::size_t x, std::size_t y); - void setSize(std::size_t x, std::size_t y); - void setChar(char c); - void setColor(std::unique_ptr color); - void setPath(const std::string &path); - void setRotation(float rotation); + void setPos(std::size_t x, std::size_t y) override; + void setSize(std::size_t x, std::size_t y) override; + void setChar(char c) override; + void setColor(std::unique_ptr color) override; + void setPath(const std::string &path) override; + void setRotation(float rotation) override; - //getters - std::vector getPos() const; - std::vector getSize() const; - int getChar() const; - std::shared_ptr getColor() const; - std::string getPath() const; - float getRotation() const; + //getter + std::vector getPos() const override; + std::vector getSize() const override; + int getChar() const override; + std::shared_ptr getColor() const override; + std::string getPath() const override; + float getRotation() const override; private: std::vector _pos; diff --git a/src/snake/Score.hpp b/src/snake/Score.hpp index 5f7527b..f988614 100644 --- a/src/snake/Score.hpp +++ b/src/snake/Score.hpp @@ -15,23 +15,23 @@ namespace Arcade { class Score : public IText { public: Score(); - ~Score() = default; + ~Score() override = default; // setters - void setFontPath(const std::string &fontPath); - void setText(const std::string &text); - void setColor(std::unique_ptr color); - void setPos(std::size_t x, std::size_t y); - void setSize(std::size_t x); - void setRotation(float rotation); + void setFontPath(const std::string &fontPath) override; + void setText(const std::string &text) override; + void setColor(std::unique_ptr color) override; + void setPos(std::size_t x, std::size_t y) override; + void setSize(std::size_t x) override; + void setRotation(float rotation) override; // getters - std::string getFontPath(); - std::string getText(); - std::shared_ptr getColor() const; - std::vector getPos() const; - std::size_t getSize() const; - float getRotation() const; + std::string getFontPath() override; + std::string getText() override; + std::shared_ptr getColor() const override; + std::vector getPos() const override; + std::size_t getSize() const override; + float getRotation() const override; int getScore() const; void incrementScore(); diff --git a/src/snake/SnakeGame.hpp b/src/snake/SnakeGame.hpp index 410ca6b..7f99970 100644 --- a/src/snake/SnakeGame.hpp +++ b/src/snake/SnakeGame.hpp @@ -31,22 +31,22 @@ namespace Arcade { class SnakeGame : public IGame { public: SnakeGame(); - ~SnakeGame() = default; + ~SnakeGame() override = default; //Game - int startGame(); - int stopGame(); - int getScore(); - int simulate(); + int startGame() override; + int stopGame() override; + int getScore() override; + int simulate() override; //Event - void catchKeyEvent(int key); - void catchMousePosition(int x, int y); + void catchKeyEvent(int key) override; + void catchMousePosition(int x, int y) override; //Display - std::vector> getEntities(); - std::vector> getTexts(); - std::vector> getSounds(); + std::vector> getEntities() override; + std::vector> getTexts() override; + std::vector> getSounds() override; private: std::vector> _entities; From 559ce8298c69c1b5d9d7af5b00e18e1909beb347 Mon Sep 17 00:00:00 2001 From: 6im0n Date: Sat, 6 Apr 2024 04:23:25 +0200 Subject: [PATCH 6/9] =?UTF-8?q?=F0=9F=90=9B=20Fix=20color?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/snake/Entities/Food.cpp | 2 +- src/snake/Entities/SnakeBody.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/snake/Entities/Food.cpp b/src/snake/Entities/Food.cpp index fcee42d..ae61fa6 100644 --- a/src/snake/Entities/Food.cpp +++ b/src/snake/Entities/Food.cpp @@ -40,7 +40,7 @@ Arcade::Food::Food(Arcade::Snake snake) _path = FOOD_PATH; _rotation = 0; _char = 'O'; - _color = std::make_unique(40, 79, 42, 255); + _color = std::make_unique(175, 79, 42, 255); } void Arcade::Food::setPos(std::size_t x, std::size_t y) diff --git a/src/snake/Entities/SnakeBody.cpp b/src/snake/Entities/SnakeBody.cpp index d505b2b..8c02a28 100644 --- a/src/snake/Entities/SnakeBody.cpp +++ b/src/snake/Entities/SnakeBody.cpp @@ -16,7 +16,7 @@ Arcade::SnakeBody::SnakeBody(std::size_t x, std::size_t y, std::string path, Dir _size = {1, 1}; _path = path; _char = '='; - _color = std::make_unique(39, 122, 16, 255); + _color = std::make_unique(200, 200, 16, 255); _direction = dir; updateRotation(); } From 0f36c70b6a4fccf187c2b7903fda0f670b519217 Mon Sep 17 00:00:00 2001 From: Quentin Tennerel Date: Sat, 6 Apr 2024 14:19:38 +0200 Subject: [PATCH 7/9] =?UTF-8?q?=F0=9F=90=9B=20fix=20sdl=20file=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sdl/{sdl.cpp => Sdl.cpp} | 2 +- src/sdl/{sdl.hpp => Sdl.hpp} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/sdl/{sdl.cpp => Sdl.cpp} (98%) rename src/sdl/{sdl.hpp => Sdl.hpp} (100%) diff --git a/src/sdl/sdl.cpp b/src/sdl/Sdl.cpp similarity index 98% rename from src/sdl/sdl.cpp rename to src/sdl/Sdl.cpp index f49af08..ebb19eb 100644 --- a/src/sdl/sdl.cpp +++ b/src/sdl/Sdl.cpp @@ -5,7 +5,7 @@ ** sdl.cpp */ -#include "sdl.hpp" +#include "Sdl.hpp" Arcade::Sdl::Sdl() { diff --git a/src/sdl/sdl.hpp b/src/sdl/Sdl.hpp similarity index 100% rename from src/sdl/sdl.hpp rename to src/sdl/Sdl.hpp From 535efe0856e836326d4cf191835d108b04854a3d Mon Sep 17 00:00:00 2001 From: Quentin Tennerel Date: Sat, 6 Apr 2024 14:32:44 +0200 Subject: [PATCH 8/9] =?UTF-8?q?=F0=9F=90=9B=20fix=20tests=20that=20was=20o?= =?UTF-8?q?bsolete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pacman/pacman.cpp | 6 ++++++ src/pacman/pacman.hpp | 1 + src/sdl/Sdl.hpp | 6 ++++++ tests/snake/Entities/tests_food.cpp | 14 +++++++------- tests/snake/Entities/tests_snake_body.cpp | 8 ++++---- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/pacman/pacman.cpp b/src/pacman/pacman.cpp index efe42ed..9d26133 100644 --- a/src/pacman/pacman.cpp +++ b/src/pacman/pacman.cpp @@ -51,6 +51,12 @@ std::vector> Arcade::Pacman::getSounds() return std::vector>(); } +void Arcade::Pacman::catchMousePosition(int x, int y) +{ + (void)x; + (void)y; +} + extern "C" { __attribute__((constructor)) diff --git a/src/pacman/pacman.hpp b/src/pacman/pacman.hpp index 3b13c77..18367de 100644 --- a/src/pacman/pacman.hpp +++ b/src/pacman/pacman.hpp @@ -23,6 +23,7 @@ namespace Arcade { //Event void catchKeyEvent(int key); + void catchMousePosition(int x, int y); //Display std::vector> getEntities(); diff --git a/src/sdl/Sdl.hpp b/src/sdl/Sdl.hpp index 7353a96..388d10a 100644 --- a/src/sdl/Sdl.hpp +++ b/src/sdl/Sdl.hpp @@ -12,6 +12,12 @@ #include #include #include +#include +#include +#include "Interfaces/IGraphic.hpp" +#include "Interfaces/IEntity.hpp" +#include "Interfaces/IText.hpp" +#include "Interfaces/ISound.hpp" namespace Arcade { class Sdl : public IGraphic { diff --git a/tests/snake/Entities/tests_food.cpp b/tests/snake/Entities/tests_food.cpp index 8311455..0f7467c 100644 --- a/tests/snake/Entities/tests_food.cpp +++ b/tests/snake/Entities/tests_food.cpp @@ -23,7 +23,7 @@ Test(Food, DefaultConstructor) cr_assert_eq(food.getPath(), FOOD_PATH); cr_assert_eq(food.getRotation(), 0); cr_assert_eq(food.getChar(), 'O'); - cr_assert_eq(food.getColor()->getR(), 40); + cr_assert_eq(food.getColor()->getR(), 175); cr_assert_eq(food.getColor()->getG(), 79); cr_assert_eq(food.getColor()->getB(), 42); cr_assert_eq(food.getColor()->getA(), 255); @@ -41,7 +41,7 @@ Test(Food, SetSizeAndGetSize) cr_assert_eq(food.getPath(), FOOD_PATH); cr_assert_eq(food.getRotation(), 0); cr_assert_eq(food.getChar(), 'O'); - cr_assert_eq(food.getColor()->getR(), 40); + cr_assert_eq(food.getColor()->getR(), 175); cr_assert_eq(food.getColor()->getG(), 79); cr_assert_eq(food.getColor()->getB(), 42); cr_assert_eq(food.getColor()->getA(), 255); @@ -63,7 +63,7 @@ Test(Food, SetPosAndGetPos) cr_assert_eq(food.getPath(), FOOD_PATH); cr_assert_eq(food.getRotation(), 0); cr_assert_eq(food.getChar(), 'O'); - cr_assert_eq(food.getColor()->getR(), 40); + cr_assert_eq(food.getColor()->getR(), 175); cr_assert_eq(food.getColor()->getG(), 79); cr_assert_eq(food.getColor()->getB(), 42); cr_assert_eq(food.getColor()->getA(), 255); @@ -85,7 +85,7 @@ Test(Food, SetCharAndGetChar) cr_assert_eq(food.getPath(), FOOD_PATH); cr_assert_eq(food.getRotation(), 0); cr_assert_eq(food.getChar(), 'O'); - cr_assert_eq(food.getColor()->getR(), 40); + cr_assert_eq(food.getColor()->getR(), 175); cr_assert_eq(food.getColor()->getG(), 79); cr_assert_eq(food.getColor()->getB(), 42); cr_assert_eq(food.getColor()->getA(), 255); @@ -106,7 +106,7 @@ Test(Food, SetColorAndGetColor) cr_assert_eq(food.getPath(), FOOD_PATH); cr_assert_eq(food.getRotation(), 0); cr_assert_eq(food.getChar(), 'O'); - cr_assert_eq(food.getColor()->getR(), 40); + cr_assert_eq(food.getColor()->getR(), 175); cr_assert_eq(food.getColor()->getG(), 79); cr_assert_eq(food.getColor()->getB(), 42); cr_assert_eq(food.getColor()->getA(), 255); @@ -130,7 +130,7 @@ Test(Food, SetPathAndGetPath) cr_assert_eq(food.getPath(), FOOD_PATH); cr_assert_eq(food.getRotation(), 0); cr_assert_eq(food.getChar(), 'O'); - cr_assert_eq(food.getColor()->getR(), 40); + cr_assert_eq(food.getColor()->getR(), 175); cr_assert_eq(food.getColor()->getG(), 79); cr_assert_eq(food.getColor()->getB(), 42); cr_assert_eq(food.getColor()->getA(), 255); @@ -151,7 +151,7 @@ Test(Food, SetRotationAndGetRotation) cr_assert_eq(food.getPath(), FOOD_PATH); cr_assert_eq(food.getRotation(), 0); cr_assert_eq(food.getChar(), 'O'); - cr_assert_eq(food.getColor()->getR(), 40); + cr_assert_eq(food.getColor()->getR(), 175); cr_assert_eq(food.getColor()->getG(), 79); cr_assert_eq(food.getColor()->getB(), 42); cr_assert_eq(food.getColor()->getA(), 255); diff --git a/tests/snake/Entities/tests_snake_body.cpp b/tests/snake/Entities/tests_snake_body.cpp index 73902af..ed789e2 100644 --- a/tests/snake/Entities/tests_snake_body.cpp +++ b/tests/snake/Entities/tests_snake_body.cpp @@ -22,8 +22,8 @@ Test(Snake, snake_constructor) cr_assert_eq(snake.getSize()[0], 1); cr_assert_eq(snake.getSize()[1], 1); cr_assert_eq(snake.getChar(), '='); - cr_assert_eq(snake.getColor()->getR(), 39); - cr_assert_eq(snake.getColor()->getG(), 122); + cr_assert_eq(snake.getColor()->getR(), 200); + cr_assert_eq(snake.getColor()->getG(), 200); cr_assert_eq(snake.getColor()->getB(), 16); cr_assert_eq(snake.getColor()->getA(), 255); } @@ -67,8 +67,8 @@ Test(Snake, setColor) { Arcade::SnakeBody snake = Arcade::SnakeBody(10, 10, "assets/body", Arcade::Direction::D_RIGHT); - cr_assert_eq(snake.getColor()->getR(), 39); - cr_assert_eq(snake.getColor()->getG(), 122); + cr_assert_eq(snake.getColor()->getR(), 200); + cr_assert_eq(snake.getColor()->getG(), 200); cr_assert_eq(snake.getColor()->getB(), 16); cr_assert_eq(snake.getColor()->getA(), 255); snake.setColor(std::make_unique(10, 20, 30, 40)); From 80fc002a63ecf125a244ca70095ded9a697cb548 Mon Sep 17 00:00:00 2001 From: 6im0n Date: Sat, 6 Apr 2024 18:28:48 +0200 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=9A=A8=20Add=20catchMousePosition=20m?= =?UTF-8?q?ethod=20to=20Pacman=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pacman/pacman.cpp | 5 ----- src/sdl/Sdl.hpp | 1 - 2 files changed, 6 deletions(-) diff --git a/src/pacman/pacman.cpp b/src/pacman/pacman.cpp index 83204f9..56eb3c4 100644 --- a/src/pacman/pacman.cpp +++ b/src/pacman/pacman.cpp @@ -36,11 +36,6 @@ void Arcade::Pacman::catchKeyEvent(int key) (void)key; } -void Arcade::Pacman::catchMousePosition(int x, int y) -{ - (void)x; - (void)y; -} std::vector> Arcade::Pacman::getEntities() { diff --git a/src/sdl/Sdl.hpp b/src/sdl/Sdl.hpp index 388d10a..d9bc320 100644 --- a/src/sdl/Sdl.hpp +++ b/src/sdl/Sdl.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include