Fixed code consistency issues
This commit is contained in:
		
							parent
							
								
									c57fbc714c
								
							
						
					
					
						commit
						709cf26f99
					
				@ -26,6 +26,7 @@ namespace snakeplusplus
 | 
				
			|||||||
        player.Reset();
 | 
					        player.Reset();
 | 
				
			||||||
        PrepareGameBoard();
 | 
					        PrepareGameBoard();
 | 
				
			||||||
        isGameOver = 0;
 | 
					        isGameOver = 0;
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void GameEngine::Loop(void)
 | 
					    void GameEngine::Loop(void)
 | 
				
			||||||
@ -60,7 +61,7 @@ namespace snakeplusplus
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            char* locationState;
 | 
					            char* locationState;
 | 
				
			||||||
            locationState = &gameBoard.at(location.y).at(location.x);
 | 
					            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)
 | 
					                isGameOver = true; // Game should end (Snake touching snake)
 | 
				
			||||||
            *locationState = 'O';
 | 
					            *locationState = 'O';
 | 
				
			||||||
            player.body.push(locationState);
 | 
					            player.body.push(locationState);
 | 
				
			||||||
@ -70,6 +71,7 @@ namespace snakeplusplus
 | 
				
			|||||||
        } catch (const std::out_of_range& error) {
 | 
					        } catch (const std::out_of_range& error) {
 | 
				
			||||||
            isGameOver = true; // Snake ran into edge
 | 
					            isGameOver = true; // Snake ran into edge
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Generates new food until not colliding with player
 | 
					    // Generates new food until not colliding with player
 | 
				
			||||||
@ -77,7 +79,6 @@ namespace snakeplusplus
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        sf::Vector2f newLocation = playerFood.location;
 | 
					        sf::Vector2f newLocation = playerFood.location;
 | 
				
			||||||
        bool isUpdated = false;
 | 
					        bool isUpdated = false;
 | 
				
			||||||
        // Keep making new food until generating a valid spot
 | 
					 | 
				
			||||||
        while (gameBoard.at(newLocation.y).at(newLocation.x) == 'O')
 | 
					        while (gameBoard.at(newLocation.y).at(newLocation.x) == 'O')
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            isUpdated = true;
 | 
					            isUpdated = true;
 | 
				
			||||||
@ -128,5 +129,6 @@ namespace snakeplusplus
 | 
				
			|||||||
            default:
 | 
					            default:
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -4,4 +4,5 @@ int main(void)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    snakeplusplus::GameEngine game;
 | 
					    snakeplusplus::GameEngine game;
 | 
				
			||||||
    game.Start();
 | 
					    game.Start();
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -45,8 +45,8 @@ namespace snakeplusplus
 | 
				
			|||||||
        while (true)
 | 
					        while (true)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            gameWindow.pollEvent(event);
 | 
					            gameWindow.pollEvent(event);
 | 
				
			||||||
            if ((event.type == sf::Event::Closed) || 
 | 
					            if ((event.type == sf::Event::Closed)
 | 
				
			||||||
                (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
 | 
					                    || (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                gameWindow.close();
 | 
					                gameWindow.close();
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
@ -114,8 +114,8 @@ namespace snakeplusplus
 | 
				
			|||||||
        sf::Event event;
 | 
					        sf::Event event;
 | 
				
			||||||
        while (gameWindow.pollEvent(event))
 | 
					        while (gameWindow.pollEvent(event))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if ((event.type == sf::Event::Closed) || 
 | 
					            if ((event.type == sf::Event::Closed)
 | 
				
			||||||
                (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
 | 
					                    || (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
 | 
				
			||||||
                gameWindow.close();
 | 
					                gameWindow.close();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -10,6 +10,7 @@ namespace snakeplusplus
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        *(body.front()) = ' ';
 | 
					        *(body.front()) = ' ';
 | 
				
			||||||
        body.pop();
 | 
					        body.pop();
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void Snake::Reset(void)
 | 
					    void Snake::Reset(void)
 | 
				
			||||||
@ -17,11 +18,13 @@ namespace snakeplusplus
 | 
				
			|||||||
        while (!body.empty()) Pop();
 | 
					        while (!body.empty()) Pop();
 | 
				
			||||||
        speed.x = 0;
 | 
					        speed.x = 0;
 | 
				
			||||||
        speed.y = 0;
 | 
					        speed.y = 0;
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Food::Food(void)
 | 
					    Food::Food(void)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        generator.seed(std::random_device{}());
 | 
					        generator.seed(std::random_device{}());
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Returns a new food object for the snakeFood
 | 
					    // Returns a new food object for the snakeFood
 | 
				
			||||||
@ -29,6 +32,7 @@ namespace snakeplusplus
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        location.x = GenerateRandomNumber(boundaries.x);
 | 
					        location.x = GenerateRandomNumber(boundaries.x);
 | 
				
			||||||
        location.y = GenerateRandomNumber(boundaries.y);
 | 
					        location.y = GenerateRandomNumber(boundaries.y);
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Returns a newly generated number
 | 
					    // Returns a newly generated number
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user