So basically I'm trying to find both last positions of X and Y of my player in a .NET Core console application.
Every time I press W, A, S or D, it randomly generates positions (A and D for X values, W and S for Y values) in a map 1000px by 1000px. The problem is when every time it says the last values, only Y value is correct and X is still random.
So the question really is: How do I find the last value of a randomly generated int (for both X and Y values) in c#?
Edit1: Edited the language from portuguese to English
do
{
targetPos = Console.ReadKey(true);
if (targetPos.Key != ConsoleKey.Q)
{
playerX = r.Next(0, 1000);
playerY = r.Next(0, 1000);
}
Console.WriteLine(" ");
switch (targetPos.Key)
{
case ConsoleKey.D:
playerX++;
Console.WriteLine("Right - Position X: {0} ", playerX);
Console.WriteLine();
break;
case ConsoleKey.A:
playerX--;
Console.WriteLine("Left - Position X: {0} ", playerX);
Console.WriteLine();
break;
case ConsoleKey.S:
playerY--;
Console.WriteLine("Down - Position Y: {0} ", playerY);
Console.WriteLine();
break;
case ConsoleKey.W:
playerY++;
Console.WriteLine("Up - Position Y: {0} ", playerY);
Console.WriteLine();
break;
case ConsoleKey.Q:
Console.WriteLine("\nLast Position X: {0}", playerX);
Console.WriteLine("\nLast Position Y: {0}", playerY);
Environment.Exit(0);
break;
}
Console.WriteLine(targetPos.Key.ToString());
} while (targetPos.Key != ConsoleKey.Escape);
Aucun commentaire:
Enregistrer un commentaire