Skip to content

Commit

Permalink
Merge pull request #5 from martin-ramos/revert-4-fix_issue
Browse files Browse the repository at this point in the history
Revert "Fix issue Snake freezes after eating last fruit"
  • Loading branch information
martin-ramos committed Jul 4, 2018
2 parents 5066ed0 + e6f4537 commit e1eee3e
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 23 deletions.
Binary file modified lang/es_AR/LC_MESSAGES/nsnake.mo
Binary file not shown.
3 changes: 1 addition & 2 deletions lang/es_AR/LC_MESSAGES/po/nsnake.po
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ msgid "(Help)"
msgstr "(Ayuda)"
msgid " Help "
msgstr " Ayuda "

msgid "Menu controls:\n"
msgstr "Controles del menu\n"
msgid "You win"
msgstr "Has ganado"
5 changes: 1 addition & 4 deletions src/Entities/Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,4 @@ void Board::scrollDown()
this->board->set(j, 1, tmp);
}
}
int Board::getSize()
{
return this->getW() * this->getH();
}

4 changes: 1 addition & 3 deletions src/Entities/Board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ class Board
void scrollUp();
void scrollDown();

// Returns size of board
int getSize();

private:
/// The actual level on the screen.
/// `true` means there's a wall here.
Expand All @@ -132,3 +129,4 @@ class Board
};

#endif //BOARD_H_DEFINED

11 changes: 1 addition & 10 deletions src/Entities/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <Display/Layouts/LayoutGame.hpp>
#include <Engine/InputManager.hpp>
#include <Entities/BoardParser.hpp>
#include <Engine/Graphics/Widgets/Dialog.hpp>
#include <unistd.h>

#include <stdlib.h>

Expand Down Expand Up @@ -225,16 +223,9 @@ void Game::handleInput()
}
void Game::update()
{
//Fix bug game freezes when snake eats last fruit
if((this->player->getSizeMinus(1)) >= this->board->getSize())
{
Dialog::show(_("You win"));
//Thread sleeps 2 seconds for dialog "You win"
usleep(2000000);
this->gameOver = true;
}
if (this->gameOver)
return;

// If we're paused, only handle the menu.
if (this->isPaused)
{
Expand Down
4 changes: 1 addition & 3 deletions src/Entities/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,4 @@ void Player::increase()

this->body.push_back(Body(lastx, lasty));
}
int Player::getSizeMinus(int count) {
return this->getSize() - count;
}

2 changes: 1 addition & 1 deletion src/Entities/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class Player
bool bodyHit(int x, int y, bool isCheckingHead=false);

void increase();
int getSizeMinus(int count);

private:
std::vector<Body> body;
Expand All @@ -68,3 +67,4 @@ class Player
};

#endif //PLAYER_H_DEFINED

0 comments on commit e1eee3e

Please sign in to comment.