diff --git a/CMakeLists.txt b/CMakeLists.txt index cd5f96e..3b83e20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) project(snake) -include_directories(include) - set(SOURCES src/main.cpp src/element.cpp @@ -13,6 +11,6 @@ set(SOURCES ) add_executable(snake ${SOURCES}) +target_include_directories(snake PRIVATE include) find_package(Curses REQUIRED) -include_directories(${CURSES_INCLUDE_DIR}) -target_link_libraries(snake ${CURSES_LIBRARIES}) +target_link_libraries(snake PRIVATE ${CURSES_LIBRARIES}) diff --git a/include/element.hpp b/include/element.hpp index 29ca748..1066831 100644 --- a/include/element.hpp +++ b/include/element.hpp @@ -1,6 +1,7 @@ #ifndef ELEMENT_HPP #define ELEMENT_HPP +#include #include #include "globals.hpp" @@ -25,11 +26,11 @@ public: void run(); private: + Window* win; std::vector buf; bool running = true; enum Direction m_dir; - int m_score = 0; - Window* win; + uint8_t m_score = 0; void process_input(); void determine_index_zero_pos(); void move_tail_indicies(); diff --git a/include/globals.hpp b/include/globals.hpp index 8ba42fc..90a0ed6 100644 --- a/include/globals.hpp +++ b/include/globals.hpp @@ -1,9 +1,9 @@ #ifndef GLOBALS_HPP #define GLOBALS_HPP -#define ROW 11 -#define COL 11 -#define MAX_LEN (ROW * COL) + 3 -#define HEAD 0 -#define PREVIOUS_HEAD 1 -#define FRUIT 2 +constexpr int ROW = 11; +constexpr int COL = 11; +constexpr int MAX_LEN = (ROW * COL) + 3; +constexpr int HEAD = 0; +constexpr int PREVIOUS_HEAD = 1; +constexpr int FRUIT = 2; #endif // GLOBALS_HPP diff --git a/src/element.cpp b/src/element.cpp index 68c3060..0abc416 100644 --- a/src/element.cpp +++ b/src/element.cpp @@ -99,15 +99,13 @@ void SnakeGame::on_fruit_eaten(Vector2i (*board)[COL]) { col = (rand() % COL); } while (board[row][col].id != '.'); buf[FRUIT].set(row, col); - buf.insert(buf.begin() + 3, Vector2i { ROW, COL, '@' }); + buf.insert(buf.begin() + 3, Vector2i { ROW, COL, '~' }); m_score++; } bool SnakeGame::segment_overlap() { for(int i : std::ranges::views::iota(3, (int)buf.size())) { - if( buf[i].y == buf[HEAD].y && - buf[i].x == buf[HEAD].x) - { + if( buf[i].y == buf[HEAD].y && buf[i].x == buf[HEAD].x) { return true; } } diff --git a/src/window.cpp b/src/window.cpp index b580d98..cc4cbc6 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -25,7 +25,6 @@ void Window::draw_display() { void Window::update_display(std::vector &buf) { for(int i : std::ranges::views::iota(0, (int)buf.size())) { - // if(i == 1 || buf[i]->y > ROW - 1 || buf[i]->x > COL - 1) continue; if(i == 1) continue; board[buf[i].y][buf[i].x].id = buf[i].id; }