diff --git a/Arial.ttf b/Arial.ttf new file mode 100644 index 0000000..7ff88f2 Binary files /dev/null and b/Arial.ttf differ diff --git a/src/gamestate.cpp b/src/gamestate.cpp index 3e1354c..51a5470 100755 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp @@ -26,9 +26,13 @@ namespace snakeplusplus void GameEngine::GameLoop(void) { - sf::Vector2f newHeadPosition; while (graphics.IsOpen()) { + if (isGameOver) + { + graphics.CheckContinue(); + isGameOver = 0; + } UpdatePlayerSpeed(); PlaceNewSnakePart(MovePlayer()); RegenerateFood(); @@ -36,6 +40,7 @@ namespace snakeplusplus } return; } + sf::Vector2f GameEngine::MovePlayer(void) { sf::Vector2f newHeadPosition; diff --git a/src/playerinterface.cpp b/src/playerinterface.cpp index 903e059..8e297d4 100755 --- a/src/playerinterface.cpp +++ b/src/playerinterface.cpp @@ -1,5 +1,6 @@ #include "playerinterface.hpp" #include +#include #include namespace snakeplusplus @@ -42,17 +43,17 @@ namespace snakeplusplus void PlayerOutput::CheckContinue(void) { sf::Event event; + DisplayEndScreen(); while (true) { - while (gameWindow.pollEvent(event)) + gameWindow.pollEvent(event); + if ((event.type == sf::Event::Closed) || + (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))) { - if ((event.type == sf::Event::Closed) || - (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))) - gameWindow.close(); + gameWindow.close(); return; } - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Enter)) - return; + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Enter)) { return; } sf::sleep(delay); } } @@ -63,17 +64,12 @@ namespace snakeplusplus sf::Vector2f textPosition(gameBoundaries); textPosition.x = textPosition.x / 2; textPosition.y = textPosition.y / 2; - sf::Text gameOverText; - gameOverText.setString("Game Over"); - gameOverText.setCharacterSize(30); + sf::Font font; + font.loadFromFile("Arial.ttf"); + sf::Text gameOverText("Game Over", font); gameOverText.setPosition(textPosition); gameWindow.draw(gameOverText); gameWindow.display(); - // if (!PlayerWantsToContinue()) - // return; - // player = Snake(); - // playerFood.GenerateNewFood(GetGameBoundaries()); - // gameWindow.clear(); return; } diff --git a/src/snake.cpp b/src/snake.cpp index f239e6e..8de60c0 100755 --- a/src/snake.cpp +++ b/src/snake.cpp @@ -30,7 +30,7 @@ namespace snakeplusplus int Food::GenerateRandomNumber(int generationLimit) { int generatedNumber; - std::uniform_int_distribution<> distribution(0, generationLimit); + std::uniform_int_distribution<> distribution(0, generationLimit - 1); generatedNumber = distribution(generator); return generatedNumber; }