Skip to content

Commit

Permalink
Fix bug alexdantas#23 nSnake hangs when eating the last fruit
Browse files Browse the repository at this point in the history
  • Loading branch information
lrrinaudo committed Jun 28, 2018
1 parent e012afb commit 2205e11
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
7 changes: 2 additions & 5 deletions src/Entities/Board.cpp
Expand Up @@ -3,11 +3,8 @@
#include <Engine/EngineGlobals.hpp>
#include <Engine/Helpers/Utils.hpp>

// int Board::small_width = 40;
// int Board::small_height = 10;

int Board::small_width = 5;
int Board::small_height = 5;
int Board::small_width = 40;
int Board::small_height = 10;

int Board::medium_width = 55;
int Board::medium_height = 14;
Expand Down
19 changes: 8 additions & 11 deletions src/Entities/Game.cpp
Expand Up @@ -5,6 +5,7 @@
#include <Engine/InputManager.hpp>
#include <Entities/BoardParser.hpp>
#include <Engine/Graphics/Widgets/Dialog.hpp>
#include <unistd.h>

#include <stdlib.h>

Expand Down Expand Up @@ -224,20 +225,16 @@ void Game::handleInput()
}
void Game::update()
{
// std::cout << (this->board->getW()) * (this->board->getH());
// if (Dialog::askBool(_("Retry?"), _("Game Over"), true)){
// return;
// }
if((this->player->getSize() + 30) == ((this->board->getW()) * (this->board->getH()))) {
if (Dialog::askBool(_("Retry?"), _("Game Over"), true)){
return;
}
//Fix bug game freezes when snake eats last fruit
if((this->player->getSize() - 1) >= ((this->board->getW()) * (this->board->getH())))
{
Dialog::show(_("You win"));
//Thread sleeps 2 seconds for dialog "You win"
usleep(2000000);
this->gameOver = true;
}
// std::cout << this->player->getSize();

if (this->gameOver)
return;

// If we're paused, only handle the menu.
if (this->isPaused)
{
Expand Down

0 comments on commit 2205e11

Please sign in to comment.