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