Added ability to play again

This commit is contained in:
2023-08-10 18:47:40 -05:00
parent b7b42fa038
commit c71b1d6982
4 changed files with 9 additions and 2 deletions
+2 -1
View File
@@ -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);
}
}
+1 -1
View File
@@ -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();
+5
View File
@@ -14,6 +14,11 @@ namespace snakeplusplus
body.pop();
}
void Snake::Reset(void)
{
while (!body.empty()) Pop();
}
Food::Food(void)
{
generator.seed(std::random_device{}());
+1
View File
@@ -17,6 +17,7 @@ namespace snakeplusplus
sf::Vector2f speed;
std::queue<char*> body;
void Pop(void);
void Reset(void);
};
struct Food