#include <Player.h>
#include <Fruit.h>
#include <Random.h>

Fruit::Fruit(sf::Vector2i gridPos_in, const sf::Color& color_in)
	: gridPos(gridPos_in)
	, color(color_in)
{ }

sf::Vector2f Fruit::windowPos(float gridSize_in)
{
	return {gridPos.x * gridSize_in, gridPos.y * gridSize_in};
}

void Fruit::respawn(const std::vector<SnakeNode>& body_in, sf::Vector2u gridCount_in)
{
    unsigned int tempX;
    unsigned int tempY;
    bool valid = false;
    do
    {
        tempX = Random::get(0, gridCount_in.x - 1);
        tempY = Random::get(0, gridCount_in.y - 1);
        for (const auto& node : body_in)
        {
            if (node.gridPos.x != tempX and node.gridPos.y != tempY)
            {
                valid = true;
            }
        }
    } while (!valid);
        
    this->gridPos = {tempX, tempY};

}