I'm trying to place different objects in the game area like a grid, but I have some problem with my method that creates this objects and there positions. I'm trying to store each new positions in a List and then compare each new positions with the ones in the List before it's OK to use it as a new position in the grid of the game area. I only want to use each random position once. Help is preciated! Thanks!
Perhaps ther is a better way to do this?
public void AddItemsToGameArea(ContentManager content)
{
foreach (string buildingPart in contentHouseOne)
{
Vector2 newPosition = NewRandomPosition;
if (!checkPreviousPositions)
{
listHouseParts.Add(new HousePart(content, buildingPart, newPosition));
listUsedPosition.Add(newPosition);
checkPreviousPositions = true;
}
else
{
for (int i = 0; i < listUsedPosition.Count(); i++)
{
// Check??
}
}
}
}
public Vector2 NewRandomPosition
{
get
{
return new Vector2(gridPixels * Game1.random.Next(1, 8), gridPixels * Game1.random.Next(1, 8));
}
}