refactor: first step to final product by removing redundant code
This commit is contained in:
+3
-12
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user