diff --git a/include/elements.hpp b/include/elements.hpp index cd79ab5..660259b 100644 --- a/include/elements.hpp +++ b/include/elements.hpp @@ -11,6 +11,7 @@ struct Point { int m_row; int m_col; int m_symbol; + void assign(); void assign(int row, int col); }; @@ -18,6 +19,7 @@ struct PointCollection { std::vector m_point_list; void move(); void set_direction(char direction); + void check_collision(); }; #endif diff --git a/src/elements.cpp b/src/elements.cpp index c07b5a1..29a0fe0 100644 --- a/src/elements.cpp +++ b/src/elements.cpp @@ -1,4 +1,12 @@ #include "elements.hpp" +#include +#include + +void Point::assign() { + std::srand(std::time(0)); + m_row = (rand() % (ROW)); + m_col = (rand() % (ROW)); +} void Point::assign(int row, int col) { m_row = row; @@ -28,3 +36,16 @@ void PointCollection::move() { } } } + +void PointCollection::check_collision() { + for(int i = m_point_list.size() - 1; i >= 0; i--) { + if(m_point_list[i].m_direction == 'u') { + } + if(m_point_list[i].m_direction == 'd') { + } + if(m_point_list[i].m_direction == 'l') { + } + if(m_point_list[i].m_direction == 'r') { + } + } +} diff --git a/src/input.cpp b/src/input.cpp index d6ea198..8e45df5 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -13,18 +13,26 @@ void Input::get_input(bool &running, PointCollection &collection) { if(_getch == 65) { _getch = 0; collection.set_direction('u'); + collection.m_point_list.push_back(Point()); + collection.m_point_list.back().assign(); } else if(_getch == 66) { _getch = 0; collection.set_direction('d'); + collection.m_point_list.push_back(Point()); + collection.m_point_list.back().assign(); } else if(_getch == 67) { _getch = 0; collection.set_direction('r'); + collection.m_point_list.push_back(Point()); + collection.m_point_list.back().assign(); } else if(_getch == 68) { _getch = 0; collection.set_direction('l'); + collection.m_point_list.push_back(Point()); + collection.m_point_list.back().assign(); } else if(_getch == 113) running = false; } diff --git a/src/main.cpp b/src/main.cpp index dfdc87d..c04eb33 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,7 @@ int main() { std::thread input_thread(&Input::get_input, &input, std::ref(running), std::ref(collection)); collection.m_point_list.push_back(Point()); + collection.m_point_list.back().assign(); while (running) { collection.move(); diff --git a/src/window.cpp b/src/window.cpp index e64f382..f118f74 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -17,5 +17,5 @@ void Window::draw_window(PointCollection &collection) { } std::cout << "\r\n"; } - std::this_thread::sleep_for(std::chrono::milliseconds(33)); + std::this_thread::sleep_for(std::chrono::milliseconds(16)); }