Snake now randomly starts as well

This commit is contained in:
Trimutex 2023-08-18 19:51:15 -05:00
parent d7982b200f
commit 49182ce07d
2 changed files with 14 additions and 9 deletions

View File

@ -96,14 +96,20 @@ namespace snakeplusplus
gameBoard.clear();
sf::Vector2f boardDimensions = GetGameBoundaries();
gameBoard.resize(boardDimensions.y, std::vector<char> (boardDimensions.x, ' '));
player.headLocation.x = 4;
player.headLocation.y = 5;
char* locationState = &gameBoard.at(player.headLocation.y).at(player.headLocation.x);
player.body.push(locationState);
*player.body.front() = 'O';
playerFood.GenerateNewFood(GetGameBoundaries());
sf::Vector2f newLocation = playerFood.location;
gameBoard.at(newLocation.y).at(newLocation.x) = 'X';
// Snake setup
{
player.headLocation.x = GenerateRandomNumber(boardDimensions.x);
player.headLocation.y = GenerateRandomNumber(boardDimensions.y);
char* locationState = &gameBoard.at(player.headLocation.y).at(player.headLocation.x);
player.body.push(locationState);
*locationState = 'O';
}
// Food setup
{
playerFood.GenerateNewFood(boardDimensions);
sf::Vector2f newLocation = playerFood.location;
gameBoard.at(newLocation.y).at(newLocation.x) = 'X';
}
return;
}

View File

@ -6,7 +6,6 @@
namespace snakeplusplus
{
void Snake::Pop(void)
{
*(body.front()) = ' ';