From 09c087177c533c06f3726c63b749cb291db3f542 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 20 Apr 2019 03:47:35 +0200 Subject: [PATCH] Snake: Clear the movement queue on game reset. --- AK/CircularQueue.h | 6 ++++++ Games/Snake/SnakeGame.cpp | 1 + 2 files changed, 7 insertions(+) diff --git a/AK/CircularQueue.h b/AK/CircularQueue.h index e19a58f4fa..605402e0c1 100644 --- a/AK/CircularQueue.h +++ b/AK/CircularQueue.h @@ -14,6 +14,12 @@ public: m_elements[i] = T(); } + void clear() + { + m_head = 0; + m_size = 0; + } + bool is_empty() const { return !m_size; } int size() const { return m_size; } diff --git a/Games/Snake/SnakeGame.cpp b/Games/Snake/SnakeGame.cpp index d3a1b139a9..5f5541ef08 100644 --- a/Games/Snake/SnakeGame.cpp +++ b/Games/Snake/SnakeGame.cpp @@ -19,6 +19,7 @@ void SnakeGame::reset() m_head = { m_rows / 2, m_columns / 2 }; m_tail.clear_with_capacity(); m_length = 2; + m_velocity_queue.clear(); stop_timer(); start_timer(120); spawn_fruit();