refactor: first step to final product by removing redundant code

This commit is contained in:
DarthMooMancer
2025-08-29 23:03:08 -04:00
parent 684041b3c1
commit d488f6464a
8 changed files with 30 additions and 41 deletions
+3 -12
View File
@@ -33,17 +33,8 @@ void Window::draw_window() {
std::cout << std::flush;
}
void Window::clear_window() {
std::cout<<"\033[H" << std::flush;
}
void Window::tick(double frames_per_second) {
std::this_thread::sleep_for(std::chrono::milliseconds((int) (1000 / frames_per_second)));
}
void Window::update_score(Fruit &fruit, Body &body) {
if(m_score % 1 == 0 && m_score >= 1) {
fruit.m_total_eaten++;
if(m_score >= 1) {
m_score = 0;
body.m_body.push_back(Tail{2, 0, 0});
}
@@ -54,7 +45,7 @@ void Window::kill(bool &running) {
}
void Window::update_display(int fps) {
clear_window();
std::cout<<"\033[H" << std::flush;
draw_window();
tick(fps);
std::this_thread::sleep_for(std::chrono::milliseconds((int) (200))); // 1000 / fps; 200ms = 5fps
}