diff --git a/src/gamestate.cpp b/src/gamestate.cpp index e53b81c..c79cb77 100755 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp @@ -26,6 +26,7 @@ namespace snakeplusplus player.Reset(); PrepareGameBoard(); isGameOver = 0; + return; } void GameEngine::Loop(void) @@ -60,7 +61,7 @@ namespace snakeplusplus { char* locationState; locationState = &gameBoard.at(location.y).at(location.x); - if (*locationState == 'O' && player.body.size() > 1) + if (*locationState == 'O' && (player.body.size() > 1)) isGameOver = true; // Game should end (Snake touching snake) *locationState = 'O'; player.body.push(locationState); @@ -70,6 +71,7 @@ namespace snakeplusplus } catch (const std::out_of_range& error) { isGameOver = true; // Snake ran into edge } + return; } // Generates new food until not colliding with player @@ -77,7 +79,6 @@ namespace snakeplusplus { sf::Vector2f newLocation = playerFood.location; bool isUpdated = false; - // Keep making new food until generating a valid spot while (gameBoard.at(newLocation.y).at(newLocation.x) == 'O') { isUpdated = true; @@ -128,5 +129,6 @@ namespace snakeplusplus default: break; } + return; } } diff --git a/src/main.cpp b/src/main.cpp index 0bf1900..2d529fb 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,4 +4,5 @@ int main(void) { snakeplusplus::GameEngine game; game.Start(); + return 0; } diff --git a/src/playerinterface.cpp b/src/playerinterface.cpp index d981553..2978179 100755 --- a/src/playerinterface.cpp +++ b/src/playerinterface.cpp @@ -45,8 +45,8 @@ namespace snakeplusplus while (true) { 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(); return; @@ -114,8 +114,8 @@ namespace snakeplusplus sf::Event event; while (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(); } } diff --git a/src/snake.cpp b/src/snake.cpp index 5586724..d1908e4 100755 --- a/src/snake.cpp +++ b/src/snake.cpp @@ -10,6 +10,7 @@ namespace snakeplusplus { *(body.front()) = ' '; body.pop(); + return; } void Snake::Reset(void) @@ -17,11 +18,13 @@ namespace snakeplusplus while (!body.empty()) Pop(); speed.x = 0; speed.y = 0; + return; } Food::Food(void) { generator.seed(std::random_device{}()); + return; } // Returns a new food object for the snakeFood @@ -29,6 +32,7 @@ namespace snakeplusplus { location.x = GenerateRandomNumber(boundaries.x); location.y = GenerateRandomNumber(boundaries.y); + return; } // Returns a newly generated number