fix: properly skips block if deleted and doesnt print the old symbol. removed old helper functions that are redundant

This commit is contained in:
DarthMooMancer
2025-09-01 17:51:36 -04:00
parent f1e32089ae
commit 6529353f2f
5 changed files with 31 additions and 25 deletions
+16
View File
@@ -3,6 +3,9 @@
#include <chrono>
#include <thread>
Window::Window() {
m_lives = 3;
}
void Window::tick(int fps) {
std::this_thread::sleep_for(std::chrono::milliseconds(fps)); // 1000 / fps; 200ms = 5fps
}
@@ -11,6 +14,18 @@ void Window::clear() {
std::cout << "\033[H" << std::flush;
}
void Window::terminate(Ball &ball, bool &running) {
if(m_lives <= 0) {
clear();
std::cout << "You lose!" << std::endl;
running = false;
} if(ball.m_blocks_left <= 0) {
clear();
std::cout << "You win!" << std::endl;
running = false;
}
}
void Window::update_display(Paddle &paddle, Ball &ball, Block (&block_list)[15]) {
for(std::array<char, COL> &row : m_board) { row.fill('.'); }
for(int i = 0; i < paddle._size; i++) {
@@ -29,5 +44,6 @@ void Window::update_display(Paddle &paddle, Ball &ball, Block (&block_list)[15])
}
std::cout << "\r\n";
}
std::cout << "Lives left: " << m_lives << std::endl;
tick(150);
}