// Moves the snake for each iteration void snake_move_player(pos head) { attrset(COLOR_PAIR(1)) ; int idx = snake_cooridinate_to_index(head); if (spaces[idx]) snake_game_over(); spaces[idx] = true; enqueue(head); g_score += 10; if (head.x == fruit.x && head.y == fruit.y) { snake_draw_fruit(); g_score += 1000; } else { pos* tail = dequeue(); spaces[snake_cooridinate_to_index(*tail)] = false; snake_write_text(tail->y, tail->x, " "); } snake_write_text(head.y, head.x, "S"); char buffer[25]; sprintf(buffer, "%d", g_score); attrset(COLOR_PAIR(2)); snake_write_text(g_height + 1, 9, buffer); }
// Handles moving the snake for each iteration bool snake_move_player( pos head ) { attrset( COLOR_PAIR( 1 ) ) ; // Check if we ran into ourself int idx = snake_cooridinate_to_index( head ); if( spaces[idx] ) snake_game_over( ); spaces[idx] = true; // Mark the space as occupied enqueue( head ); g_score += 10; // Check if we're eating the fruit if( head.x == fruit.x && head.y == fruit.y ) { snake_draw_fruit( ); g_score += 1000; } else { // Handle the tail pos *tail = dequeue( ); spaces[snake_cooridinate_to_index( *tail )] = false; snake_write_text( tail->y, tail->x, " " ); } // Draw the new head snake_write_text( head.y, head.x, "S" ); // Update scoreboard char buffer[25]; sprintf( buffer, "%d", g_score ); attrset( COLOR_PAIR( 2 ) ); snake_write_text( g_height+1, 9, buffer ); }