diff --git a/include/elements.hpp b/include/elements.hpp index ebe15a9..d02fed0 100644 --- a/include/elements.hpp +++ b/include/elements.hpp @@ -4,13 +4,13 @@ #include struct Point { - Point() : m_row(0), m_col(0), m_id(0), m_active(true) {} - Point(int row, int col, int id) : m_row(row), m_col(col), m_id(id), m_active(true) {} + Point() : m_row(0), m_col(0), m_id(0) {} + Point(int row, int col, int id) : m_row(row), m_col(col), m_id(id) {} int m_row; int m_col; int m_id; - bool m_active; char m_symbol; + void to_string(); void assign(int row, int col); void move(); void check_collision(std::vector &points_list); @@ -20,7 +20,6 @@ struct Player { Player(char symbol, bool turn) : m_symbol(symbol), m_turn(turn) {} char m_symbol; bool m_turn; - std::vector m_points; void input_tile(int col, std::vector &points); }; diff --git a/include/window.hpp b/include/window.hpp index b3b1a7b..7d90181 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -9,6 +9,7 @@ struct Window { std::array, ROW> m_board = {}; void update_display(std::vector &points_list); + bool check_chain(); }; #endif diff --git a/src/elements.cpp b/src/elements.cpp index b3fb80d..9fd3bb0 100644 --- a/src/elements.cpp +++ b/src/elements.cpp @@ -1,6 +1,7 @@ #include "elements.hpp" #include "globals.hpp" #include +#include void Point::assign(int row, int col) { m_row = row; @@ -13,13 +14,16 @@ void Point::move() { } } +void Point::to_string() { + std::cout << "(" << m_row << ", " << m_col << ")"; +} + void Point::check_collision(std::vector &points_list) {; for(int i = 0; i < points_list.size(); i++) { if(points_list[i].m_id == m_id) continue; if(points_list[i].m_row != m_row) continue; if(points_list[i].m_col != m_col) continue; m_row = points_list[i].m_row - 1; - m_active = false; } } diff --git a/src/main.cpp b/src/main.cpp index 33d8874..59bacbe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,14 +14,34 @@ int main() { bool running = true; std::thread input_thread(&Input::get_input, &input, std::ref(running), std::ref(one), std::ref(two), std::ref(points_list)); + char symbol = ' '; + bool d = true; + bool result = false; while(running) { window.update_display(points_list); for(int i = 0; i < points_list.size(); i++) { - if(!points_list[i].m_active) continue; points_list[i].move(); points_list[i].check_collision(points_list); } - std::cout << points_list.size() << std::endl; + for(int i = 0; i < ROW - 1; i++) { + for(int j = 0; j < COL - 1; j++) { + if(window.m_board[i][j] == ' ') continue; + symbol = window.m_board[i][j]; + d = true; + if(d) { + for(int k = 1; k <= 3; k++) { + if(window.m_board[i][j + k] != symbol) d = false; + } + if(d) { + result = true; + } + } + } + } + // if(window.check_chain()) { + // std::cout << "Chain is active" << std::endl; + // } + std::cout << result << std::endl; } input_thread.join(); diff --git a/src/window.cpp b/src/window.cpp index bc17ce8..a244dc5 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -3,6 +3,7 @@ #include #include + void Window::update_display(std::vector &points_list) { for(std::array &row : m_board) { row.fill('.'); } for(int i = 0; i < points_list.size(); i++) { @@ -18,3 +19,25 @@ void Window::update_display(std::vector &points_list) { } std::this_thread::sleep_for(std::chrono::milliseconds(200)); // 1000 / fps; 200ms = 5fps } + +bool Window::check_chain() { + char symbol = ' '; + bool d = true; + bool result = false; + for(int i = 0; i < ROW - 1; i++) { + for(int j = 0; j < COL - 1; j++) { + if(m_board[i][j] == ' ') continue; + symbol = m_board[i][j]; + d = true; + if(d) { + for(int k = 1; k <= 3; k++) { + if(m_board[i][j + k] != symbol) d = false; + } + if(d) { + result = true; + } + } + } + } + return result; +}