Jump to content

C# menu not working...

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

My current code projects

--------------------------------

  • C#/OpenGL ( using OpenTK graphics library API ) KnightsRealm ( unfinished, WIP plan on releasing on steam maybe a mobile port idk ) 2d topdown pixel art based game with medieval themes, sorcery, dragons, open world
  • C++ crypter ( if your into cryptography, I plan on releasing this on my website later :P
  • C#/OpenGL ( OpenGL for UI ) fan/light controller for my room w/ raspberry pi and some mechanical motors and stuff :D


Current repair projects

------------------------------

  • My dreadful receiver ( a capacitor blew ) 
  • working on a PC from a client, CPU died within the system, seems like a short, replaced CPU and awaiting payment before I ship it back 
  • my old 1tb sas drive for my NAS, some blemishes or something on the PCB need to clear that back out, if it doesn't work i'll need to scrap it ( already backed up all my stuff thankfully )

    If you want any software made, or stuff to be repaired give me an email! 
    mike.fernandez5138699@gmail.com
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×