Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pasue implementation #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions SnakeController/SnakeController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the semicolon in the end ;)


auto direction = directionInd.direction;

if ((m_currentDirection & 0b01) != (direction & 0b01)) {
Expand Down Expand Up @@ -221,6 +227,8 @@ void Controller::receive(std::unique_ptr<Event> e)
case DirectionInd::MESSAGE_ID: return handleDirectionChange(*static_cast<EventT<DirectionInd> const&>(*e));
case FoodInd::MESSAGE_ID: return handleFoodPositionChange(*static_cast<EventT<FoodInd> const&>(*e));
case FoodResp::MESSAGE_ID: return handleNewFood(*static_cast<EventT<FoodResp> const&>(*e));
case PauseInd::MESSAGE_ID: return handlePauseI(*static_cast<EventT<PauseInd> const&>(*e));

default: throw UnexpectedEventException();
};
}
Expand Down
3 changes: 2 additions & 1 deletion SnakeController/SnakeController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't you mean handlePauseId? :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yea it would be better :D

struct Segment
{
int x;
int y;
int ttl;
};
bool bGamePause = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would go with a bool name showing condition like isGamePaused here.


Segment getNewHead() const;
bool doesCollideWithSnake(const Segment& newSegment) const;
Expand Down