I'm having an issue with some random movement of an object on the screen. It kind of ticks back and forth so it's movement isn't random at all. This is just a small C# console program.
namespace MorgSimulator
{
class Program
{
static void Main(string[] args)
{
Morg A = new MorgA();
A.MovingTime();
Console.ReadKey();
}
}
class Morg
{
public Morg()
{}
protected MoveBehavior moveBehavior;
public void MovingTime()
{
moveBehavior.move();
}
class MorgA : Morg
{
public MorgA()
{
moveBehavior = new Ooze();
}
interface MoveBehavior
{
void move();
}
class Ooze : MoveBehavior
{
public void move()
{
int row = 40, col = 25;
Console.CursorVisible = false;
Console.SetCursorPosition(col, row);
int direction = 0;
Random r = new Random();
for (int i = 0; i < 25; i++) // count of movement
{
Console.Write("<(._.)>");
System.Threading.Thread.Sleep(100);
Console.Clear();
direction = r.Next(5);
while (direction == 0)
direction = r.Next(5);
switch (direction)
{
case 1:
if (row + 1 >= 80)
row = 0;
Console.SetCursorPosition(col, row++);
break;
case 2:
if (row - 1 <= 0)
row = 79;
Console.SetCursorPosition(col, row--);
break;
case 3:
if (col + 1 >= 50)
col = 0;
Console.SetCursorPosition(col++, row);
break;
case 4:
if (col - 1 <= 0)
col = 49;
Console.SetCursorPosition(col--, row);
break;
}
}
}
}
Basically, I want some obvious and more random movement within the bounds instead of shifting back and forth at the bottom of the console. Can someone point me in the right direction?