I am currently working a 16 tile puzzle game in Monogame, I am trying to get my game pieces to shuffle properly when I press a button. In the current iteration what I have the program do is generate a random number and then use that random number to determine which case a switch statement uses. Depending on the number the tile should move a certain direction. The problem that I am running into is even though I have declared a new Random variable outside of the loop and made it static, the tile only ever moves one space. I have read through so many different posts about the random function but I still have no idea what I'm doing wrong or how to get my code to work properly. Any help would be great.
Below are the relevant code chunks :
private static Random rnd = new Random();
private int currentRnd;
...
for(int i = 0; i < 25; i++)
{
currentRnd = rnd.Next(1, 5);
switch (currentRnd)
{
case 1:
if (tile16.Y < (gridY3 + imageStartY + 30)) tile16.Y += 11;
break;
case 2:
if (tile16.Y > gridYCoords[0]) tile16.Y -= 11;
break;
case 3:
if (tile16.X < (gridX3 + imageStartX + 30)) tile16.X -= 31;
break;
case 4:
if (tile16.X > gridXCoords[0]) tile16.X += 31;
break;
}
}
The if statements are just to insure the movable tile doesn't go outside the bounds of the "board".