diff --git a/NERODevelopment/src/controllers/snakecontroller.cpp b/NERODevelopment/src/controllers/snakecontroller.cpp index 61da50c..951e078 100644 --- a/NERODevelopment/src/controllers/snakecontroller.cpp +++ b/NERODevelopment/src/controllers/snakecontroller.cpp @@ -1,9 +1,7 @@ #include "snakecontroller.h" SnakeController::SnakeController(Model *model, QObject *parent) - : ButtonController{model, 6, parent} { - // this->m_debounceOffset = 150; -} + : ButtonController{model, 7, parent} {} void SnakeController::handleKeyPress(int key) { int newDirection = m_currentDirection; @@ -29,14 +27,15 @@ void SnakeController::handleKeyPress(int key) { return; } - if (!isOppositeDirection(newDirection)) { + if (!isSameOrOppositeDirection(newDirection)) { m_currentDirection = newDirection; emit directionChanged(m_currentDirection); } } -bool SnakeController::isOppositeDirection(int newDirection) { - return (m_currentDirection + 2) % 4 == newDirection; +bool SnakeController::isSameOrOppositeDirection(int newDirection) { + return (m_currentDirection + 2) % 4 == newDirection || + m_currentDirection == newDirection; } void SnakeController::saveScore(int score) { diff --git a/NERODevelopment/src/controllers/snakecontroller.h b/NERODevelopment/src/controllers/snakecontroller.h index 675c10b..3dbb33f 100644 --- a/NERODevelopment/src/controllers/snakecontroller.h +++ b/NERODevelopment/src/controllers/snakecontroller.h @@ -19,7 +19,7 @@ public slots: private: int m_currentDirection; - bool isOppositeDirection(int newDirection); + bool isSameOrOppositeDirection(int newDirection); }; #endif // SNAKECONTROLLER_H