In my menu, I have a "#" symbol which moves absolute to the CursorPosition(xcoord, ycoord). Depending on the case switch ( e.g uparrow or downarrow key ) the xcoord will move. The ycoord is a constant, since this is a menu and not a player moving on a map within a game for instance it is not necessary. Now, xcoord decrements by 10 when the uparrow is activated and increments by 10 units when the down arrow is activated. However, I have to make a system that detects when the xcoord is at a certain position since I don't want the user to be able to infinitely go down or up on the buffer screen. I just want them to be able to go a certain amount based on the amount of menu items. Which may be easy to do, what I did was devised a little while loop each time the xcoord is at the top most value of the menu items displayed on the screen or the bottom most. The uparrow is working fine, however the downarrow isn't and I have no idea. I literally just copied and pasted the uparrow while loop to the downarrow case with a few adjustments. I've been trying to fix the problem for ages, pulling out my hair. I am completely lost! I don't even know what to even began to try what to do. I've already googled for a solution to no avail. And I don't want to copy and paste someone elses menu since I would be learning nothing.
bool debugmode = false;
bool f4 = false; // f4 enables or disables debug mode, by default it is false, when true consquently debug mode is ac-
int redo = 0; // filler for the do while loop
int ycoord = 30; // x coordinate on the plane coordinate
int xcoord = 35; // y coordinate on the plane coordinate
ConsoleKeyInfo userinput = new ConsoleKeyInfo();
do
{
userinput = Console.ReadKey(true);
Console.SetCursorPosition(ycoord, xcoord);
Console.Write("#");
Console.Clear();
switch (userinput.Key)
{
case ConsoleKey.UpArrow:
xcoord = xcoord - 10;
while (xcoord < 20)
{
if (xcoord == 10)
{
xcoord = 20;
}
else
{
xcoord = 20 - 10;
}
}
Console.SetCursorPosition(ycoord, xcoord);
if (f4 == true || debugmode == true )
{
Console.Write("X: " + xcoord + " Y: " + ycoord);
Console.Write(Environment.NewLine);
}
Console.SetCursorPosition(ycoord, xcoord);
Console.Write("#");
break;
case ConsoleKey.DownArrow:
xcoord = xcoord + 10;
while (xcoord > 60)
{
if (xcoord == 70)
{
GoBackTenU(xcoord);
}
else
{
xcoord = 60 + 10;
}
}
Console.SetCursorPosition(ycoord, xcoord);
if (f4 == true || debugmode == true)
{
Console.SetCursorPosition(ycoord, xcoord);
Console.WriteLine("X: " + xcoord + " Y: " + ycoord);
}
Console.SetCursorPosition(ycoord, xcoord);
Console.Write("#");
break;
case ConsoleKey.F4:
if (f4 == false) { f4 = true; } else
{
f4 = false;
}
Console.SetCursorPosition(ycoord, xcoord);
Console.Write("#");
break;
}
} while (redo == 0);
}
static int GoBackTenU(int xcoord)
{
xcoord = 60;
return xcoord;
}
edit: this code was just a giant clusterfuck edited up fixing it myself by rewriting it