Added ability to play again
This commit is contained in:
parent
b7b42fa038
commit
c71b1d6982
@ -31,6 +31,8 @@ namespace snakeplusplus
|
||||
if (isGameOver)
|
||||
{
|
||||
graphics.CheckContinue();
|
||||
player.Reset();
|
||||
PrepareGameBoard();
|
||||
isGameOver = 0;
|
||||
}
|
||||
UpdatePlayerSpeed();
|
||||
@ -69,7 +71,6 @@ namespace snakeplusplus
|
||||
player.Pop();
|
||||
} catch (const std::out_of_range& error) {
|
||||
isGameOver = true; // Snake ran into edge
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ namespace snakeplusplus
|
||||
textPosition.y = textPosition.y / 2;
|
||||
sf::Font font;
|
||||
font.loadFromFile("Arial.ttf");
|
||||
sf::Text gameOverText("Game Over", font);
|
||||
sf::Text gameOverText("Game Over\nPress 'Enter' to play again", font);
|
||||
gameOverText.setPosition(textPosition);
|
||||
gameWindow.draw(gameOverText);
|
||||
gameWindow.display();
|
||||
|
@ -14,6 +14,11 @@ namespace snakeplusplus
|
||||
body.pop();
|
||||
}
|
||||
|
||||
void Snake::Reset(void)
|
||||
{
|
||||
while (!body.empty()) Pop();
|
||||
}
|
||||
|
||||
Food::Food(void)
|
||||
{
|
||||
generator.seed(std::random_device{}());
|
||||
|
@ -17,6 +17,7 @@ namespace snakeplusplus
|
||||
sf::Vector2f speed;
|
||||
std::queue<char*> body;
|
||||
void Pop(void);
|
||||
void Reset(void);
|
||||
};
|
||||
|
||||
struct Food
|
||||
|
Loading…
Reference in New Issue
Block a user