This commit is contained in:
DarthMooMancer
2025-09-27 19:10:16 -04:00
parent 99bcdbaf46
commit 959e539d4b
5 changed files with 7 additions and 12 deletions
+4 -4
View File
@@ -11,16 +11,16 @@ void Input::get_input(enum Direction &dir, bool &running) {
endwin();
switch (m_getch) {
case 65: // Up arrow
if(m_current_key != DOWN) dir = m_current_key = UP;
if(dir != DOWN) dir = UP;
break;
case 66: // Down arrow
if(m_current_key != UP) dir = m_current_key = DOWN;
if(dir != UP) dir = DOWN;
break;
case 67: // Right arrow
if(m_current_key != LEFT) dir = m_current_key = RIGHT;
if(dir != LEFT) dir = RIGHT;
break;
case 68: // Left arrow
if(m_current_key != RIGHT) dir = m_current_key = LEFT;
if(dir != RIGHT) dir = LEFT;
break;
case 113:
running = false;
+2 -5
View File
@@ -12,13 +12,10 @@ int main () {
bool running = true;
Point* segments[(ROW * COL) + 3] = {}; // 2 for head, 1 for fruit, rest for tail
segments[0] = new Point { 5, 5, '*' }; // Head
segments[0] = new Point { ROW / 2, COL / 2, '*' }; // Head
segments[2] = new Point { (rand() % ROW), (rand() % COL), 'o' }; // Fruit
std::thread input_thread(
&Input::get_input, &input,
std::ref(segments[0]->m_dir),
std::ref(running));
std::thread input_thread([&] { input.get_input(segments[0]->m_dir, running); } );
while (running) {
on_fruit_eaten(window.m_board, segments);
-1
View File
@@ -28,7 +28,6 @@ void Window::update_display(Point* segments[]) {
m_board[segments[2]->m_row][segments[2]->m_col] = segments[2];
for(int i = 3; i < ROW * COL; i++) {
if(segments[i] != nullptr) {
if(segments[i]->m_row < 0 || segments[i]->m_col < 0) continue;
m_board[segments[i]->m_row][segments[i]->m_col] = segments[i];
}
}