This commit is contained in:
DarthMooMancer
2025-05-11 07:16:41 -04:00
parent 9a42f9b5cd
commit 1444c173ae
27 changed files with 483 additions and 2691 deletions
+24 -24
View File
@@ -19,30 +19,30 @@ int main() {
// int randomNum = random() % 101;
//
// std::cout << randomNum;
fruit.create_point();
std::cout << fruit.m_point.get_point() << std::endl;
// std::array<std::array<char, COL>, ROW> &board = window.m_board;
// bool update = true;
// int row = 0, col = 0;
//
// Point previous {row,col};
// std::thread input_thread(&Input::get_input, &input);
// while(update) {
// if (input.m_current_key == 's') snake.set_direction(1);
// if (input.m_current_key == 'w') snake.set_direction(2);
// if (input.m_current_key == 'a') snake.set_direction(3);
// if (input.m_current_key == 'd') snake.set_direction(4);
// if (input.m_current_key == 'q') break;
//
// std::tie(row, col) = previous.get_point(snake.get_direction(), row, col);
//
// board[row][col] = '*';
// previous.clear(board); // Clear old point
// previous = Point {row, col}; // Set new previous
// window.update_loop(5); // Update loop to clear board, tick and redisplay board
// }
//
// input_thread.join();
// fruit.create_point();
// std::cout << fruit.m_point.get_point() << std::endl;
std::array<std::array<char, COL>, ROW> &board = window.m_board;
bool update = true;
int row = 0, col = 0;
Point previous {row,col};
std::thread input_thread(&Input::get_input, &input);
while(update) {
if (input.m_current_key == 's') snake.set_direction(1);
if (input.m_current_key == 'w') snake.set_direction(2);
if (input.m_current_key == 'a') snake.set_direction(3);
if (input.m_current_key == 'd') snake.set_direction(4);
if (input.m_current_key == 'q') break;
std::tie(row, col) = previous.get_point(snake.get_direction(), row, col);
board[row][col] = '*';
previous.clear(board); // Clear old point
previous = Point {row, col}; // Set new previous
window.update_loop(5); // Update loop to clear board, tick and redisplay board
}
input_thread.join();
/* First
* Learn how to make threads,
* for the input thread call the thread then use a while loop within the thread, DO NOT use a while loop to call the thread