#ifndef ELEMENT_HPP #define ELEMENT_HPP #include #include #include #include class Window; enum class Direction { UP, DOWN, LEFT, RIGHT }; struct vec2 { int x, y; vec2() : x(0), y(0) {} vec2(int x, int y) : x(x), y(y) {} void set(int _x, int _y) { x = _x; y = _y; } auto operator <=> (const vec2&) const = default; }; class SnakeGame { public: SnakeGame(); ~SnakeGame(); void run(); private: std::unique_ptr win; std::vector buf; vec2 head { COL / 2, ROW / 2 }; vec2 fruit { rand() % COL, rand() % ROW }; vec2 prev_head { head.x, head.y }; struct { Direction dir = Direction::RIGHT; uint8_t m_score = 0; } state; bool process_input(); void determine_index_zero_pos(); void move_tail_indicies(); void add_tail_and_respawn_fruit(std::array, ROW> view); bool exit_summary(); }; #endif // ELEMENT_HPP