0

I'm trying to create a menu for the console. Using Visual Studio 2019, C#, Console

It is currently working well, I use the Consolen.Helper for this. I have oriented myself towards this [Consolen.Helper Menu](https://stackoverflow.com/questions/46908148/controlling-menu-with-the-arrow-keys-and-enter"First Top Answer") If I use plain text, everything works fine. Example: But I would like to design it a little more.

So I have the options via String @ ""; deposited as Ascii But it doesn't really work when I display the options side by side. on top of each other works well. Example: enter image description here

So that the ASCII texts are displayed well, I have oriented myself to this [Ascii NewLine](https://stackoverflow.com/questions/65076780/paste-ascii-art-in-center-of-console"Ascii Format") Example:

string start = @" 
                 ___ _            _   
                / __| |_ __ _ _ _| |_ 
                \__ \  _/ _` | '_|  _|
                |___/\__\__,_|_|  \__|";

            var linesstart = start.Split(new[] { Environment.NewLine }, 
            StringSplitOptions.None);
            var longestLengthstart = linesstart.Max(line => line.Length);
            var leadingSpacesstart = new string(' ',longestLengthstart);
            var startblock = string.Join(Environment.NewLine,
                linesstart.Select(line => leadingSpacesstart + line));

But when I show the options side by side it overwrites everything, and i dont know why. enter image description here

I'm just doing it as a hobby, so I don't know exactly what information is important so that someone could help me V_V. i am sorry

How it should look maybe: enter image description here

So here is all of the code:

using System;
using System.Drawing;
using System.Linq;
using System.Text;
using ConsoleHelper;

namespace project
{
    public class ConsoleHelper
    {
        public static void menu()
        {
            string start = @" 
                     ___ _            _   
                    / __| |_ __ _ _ _| |_ 
                    \__ \  _/ _` | '_|  _|
                    |___/\__\__,_|_|  \__|";

                var linesstart = start.Split(new[] { Environment.NewLine }, 
                StringSplitOptions.None);
                var longestLengthstart = linesstart.Max(line => line.Length);
                var leadingSpacesstart = new string(' ',longestLengthstart);
                var startblock = string.Join(Environment.NewLine,
                    linesstart.Select(line => leadingSpacesstart + line));

            string save = @" 
                     ___               
                    / __| __ ___ _____ 
                    \__ \/ _` \ V / -_)
                    |___/\__,_|\_/\___|";

                var linessave = save.Split(new[] { Environment.NewLine }, 
                StringSplitOptions.None);
                var longestLengthsave = linessave.Max(line => line.Length);
                var leadingSpacessave = new string(' ',longestLengthsave);
                var saveblock = string.Join(Environment.NewLine,
                    linessave.Select(line => leadingSpacessave + line));

            string load = @" 
                      _                 _ 
                     | |   ___  __ _ __| |
                     | |__/ _ \/ _` / _` |
                     |____\___/\__,_\__,_|";

                var linesload = load.Split(new[] { Environment.NewLine }, 
                StringSplitOptions.None);
                var longestLengthload = linesload.Max(line => line.Length);
                var leadingSpacesload = new string(' ',longestLengthload);
                var loadblock = string.Join(Environment.NewLine,
                    linesload.Select(line => leadingSpacesload + line));

            string extra = @"
                              _            
                      _____ _| |_ _ _ __ _ 
                     / -_) \ /  _| '_/ _` |
                     \___/_\_\\__|_| \__,_|";

                var linesextra = extra.Split(new[] { Environment.NewLine }, 
                StringSplitOptions.None);
                var longestLengthextra = linesextra.Max(line => line.Length);
                var leadingSpacesextra = new string(' ',longestLengthextra);
                var extrablock = string.Join(Environment.NewLine,
                    linesextra.Select(line => leadingSpacesextra + line));

            string credits = @" 
                                    _ _ _      
                      __ _ _ ___ __| (_) |_ ___
                     / _| '_/ -_) _` | |  _(_-<
                     \__|_| \___\__,_|_|\__/__/";

                var linescredits = credits.Split(new[] { Environment.NewLine }, 
                StringSplitOptions.None);
                var longestLengthcredits = linescredits.Max(line => line.Length);
                var leadingSpacescredits = new string(' ',longestLengthcredits);
                var creditsblock = string.Join(Environment.NewLine,
                    linescredits.Select(line => leadingSpacescredits + line));

            int selectedClass = ConsoleHelper.MultipleChoice(true, startblock, saveblock, loadblock, extrablock, creditsblock);

            switch (selectedClass)
            {
                case 0:
                    Console.Clear();
                    Console.WriteLine("0");
                    break;
                case 1:
                    Console.Clear();
                    Console.WriteLine("1");
                    break;
                case 2:
                    Console.Clear();
                    Console.WriteLine("2");
                    break;
                case 3:
                    Console.Clear();
                    Console.WriteLine("3");
                    break;
                case 4:
                    Console.Clear();
                    Console.WriteLine("4");
                    break;
            }
        }
        public static int MultipleChoice (bool canCancel, params string[] options)
        {
            const int startX = 20;
            const int startY = 0;
            const int optionsPerLine = 2;
            const int spacingPerLine = 5;

            int currentSelection = 0;

            ConsoleKey key;

            Console.CursorVisible = false;

            do
            {
                Console.Clear();

                for (int i = 0; i < options.Length; i++)
                {
                    Console.SetCursorPosition(startX + (i % optionsPerLine) * spacingPerLine, 
                    startY + i / optionsPerLine);
                    if (i == currentSelection)

                    Console.ForegroundColor = Color.Red;
                    Console.Write(options[i]);

                    Console.ResetColor();
                }

                key = Console.ReadKey(true).Key;

                switch (key)
                {
                    case ConsoleKey.LeftArrow:
                        {
                            if (currentSelection % optionsPerLine > 0)
                                currentSelection--;
                            break;
                        }
                    case ConsoleKey.RightArrow:
                        {
                            if (currentSelection % optionsPerLine < optionsPerLine - 1)
                                currentSelection++;
                            break;
                        }
                    case ConsoleKey.UpArrow:
                        {
                            if (currentSelection >= optionsPerLine)
                                currentSelection -= optionsPerLine;
                            break;
                        }
                    case ConsoleKey.DownArrow:
                        {
                            if (currentSelection + optionsPerLine < options.Length)
                                currentSelection += optionsPerLine;
                            break;
                        }
                    case ConsoleKey.Escape:
                        {
                            if (canCancel)
                                return -1;
                            break;
                        }
                }
            } while (key != ConsoleKey.Enter);

            Console.CursorVisible = true;

            return currentSelection;
        }
    }
Fletcher
  • 9
  • 2
  • 4
    Is there a question in there somewhere? – Neil Jul 29 '21 at 22:22
  • 1
    have revised the post again. But here again. I can't get the Ascii options to appear next to each other. You then always overwrite yourself. So overlap. – Fletcher Jul 29 '21 at 22:31
  • 1
    Welcome to SO. Could you edit your posts _title_ to be a an actual question rather than _a series of tags_. Thanks. Good luck! –  Jul 29 '21 at 23:29
  • If you can't show us the actual code, we can't help you much. I'll give you one hint though: think about all those spaces in your strings, and how they look on the console. – Corey Jul 30 '21 at 00:41

1 Answers1

1

Try this:

A console is a map of 80 columns (x) by 25 rows (y). Each position on this map contains 1 character.

Your characters are roughly 5 console positions wide and 6 positions high. Therefore when you want to place a 'character' on a console screen, you need to start drawing at (x * 5), (y * 6).

You can draw each 'line' (n) of your 'character' by setting the cursor position to the starting point, but you need to reset the cursor position to the start of the next line (x5),(y6)+n.

Neil
  • 11,059
  • 3
  • 31
  • 56
  • Thank you for your support. I've been looking at it a little longer and I think I've got it now. Your answer showed me the direction. thank you very much – Fletcher Aug 07 '21 at 09:13