Below code is to generate the random positions for the obstacles. Obstacles are moving from right to left,so i am using its x coordinate to move it in left direction. When obstacles reaches left side of screen it again placed at some random position. But here problem is that sometimes the obstacles are placed at same position or they are too close.
public void Randomize()
{
int random = rand.Next(1,200);
switch (random)
{
case 200:
if (Texture.crabrect.X < 0)
Texture.crabrect.X = rand.Next(1000,1500);
break;
case 12:
if (Texture.samosarect.X < 0)
Texture.samosarect.X = rand.Next(1000, 2000);
break;
case 10:
if (Texture.mirchirect.X < 0)
Texture.mirchirect.X = rand.Next(1800,3000);
break;
case 80:
if (Texture.mushroomrect.X < 0)
Texture.mushroomrect.X = rand.Next(1000, 2000);
break;
case 195:
if (Texture.laddoorect.X < 0)
Texture.laddoorect.X = rand.Next(1000, 2000);
break;
case 56:
if (Texture.stonerect.X < 0)
Texture.stonerect.X = rand.Next(1000, 2000);
break;
case 177:
if (Texture.cactusrect.X < 0)
Texture.cactusrect.X = rand.Next(1000, 2000);
break;
}
}