diff --git a/SnakeController/SnakeController.cpp b/SnakeController/SnakeController.cpp index 6c2aa9f..20255b5 100644 --- a/SnakeController/SnakeController.cpp +++ b/SnakeController/SnakeController.cpp @@ -65,6 +65,8 @@ Controller::Controller(IPort& p_displayPort, IPort& p_foodPort, IPort& p_scorePo void Controller::handleTimePassed(const TimeoutInd&) { + if (bGamePause == true) {return;} + Segment newHead = getNewHead(); if(doesCollideWithSnake(newHead)) @@ -97,8 +99,12 @@ void Controller::handleTimePassed(const TimeoutInd&) cleanNotExistingSnakeSegments(); } +void Controller::handlePauseI(const PauseInd& pause) { bGamePause = !bGamePause; } + void Controller::handleDirectionChange(const DirectionInd& directionInd) { + if(bGamePause==true) {return;}; + auto direction = directionInd.direction; if ((m_currentDirection & 0b01) != (direction & 0b01)) { @@ -221,6 +227,8 @@ void Controller::receive(std::unique_ptr e) case DirectionInd::MESSAGE_ID: return handleDirectionChange(*static_cast const&>(*e)); case FoodInd::MESSAGE_ID: return handleFoodPositionChange(*static_cast const&>(*e)); case FoodResp::MESSAGE_ID: return handleNewFood(*static_cast const&>(*e)); + case PauseInd::MESSAGE_ID: return handlePauseI(*static_cast const&>(*e)); + default: throw UnexpectedEventException(); }; } diff --git a/SnakeController/SnakeController.hpp b/SnakeController/SnakeController.hpp index 513b950..ae4c7e1 100644 --- a/SnakeController/SnakeController.hpp +++ b/SnakeController/SnakeController.hpp @@ -37,13 +37,14 @@ class Controller : public IEventHandler void handleDirectionChange(const DirectionInd&); void handleFoodPositionChange(const FoodInd& receivedFood); void handleNewFood(const FoodResp& requestedFood); - + void handlePauseI(const PauseInd& pause); struct Segment { int x; int y; int ttl; }; + bool bGamePause = false; Segment getNewHead() const; bool doesCollideWithSnake(const Segment& newSegment) const;