fix: properly skips block if deleted and doesnt print the old symbol. removed old helper functions that are redundant
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user