Making a map for restaurant

Is it possible to move in the Console with a map like this.
text += "------------------------------------------------------\n";
text += $"| ¤ ¤ ¤ ¤ |\n";
text += $"| |\n";
text += $"| _____ _____ _____ _____ _____ _____ |\n";
text += $"| | {Tableids[0][0]} | | {Tableids[0][1]} | | {Tableids[0][2]} | | {Tableids[0][3]} | | {Tableids[0][4]} | | {Tableids[0][5]} | |\n";
text += $"| ‾‾‾‾‾ ‾‾‾‾‾ ‾‾‾‾‾ ‾‾‾‾‾ ‾‾‾‾‾ ‾‾‾‾‾ |\n";
text += $"| ¤ ¤ ¤ ¤ |\n";
text += $"| _____ _____ _____ _____ |\n";
text += $"| | {Tableids[1][0]} | | {Tableids[1][1]} | | {Tableids[1][2]} | | {Tableids[1][3]} | |\n";
text += $"| ‾‾‾‾‾ ‾‾‾‾‾ ‾‾‾‾‾ ‾‾‾‾‾ |\n";
text += $"| ¤ ¤ ¤ ¤ _______ |\n";
text += $"| | K | |\n";
text += $"| ¤ ¤ ¤ ¤ ¤ ¤ | A | ¤ |\n";
text += $"| ______ ______ | S | |\n";
text += $"| | {Tableids[2][0]} | | {Tableids[2][1]} | | S | ¤ |\n";
text += $"| ‾‾‾‾‾‾ ‾‾‾‾‾‾ | A | |\n";
text += $"| ¤ ¤ ¤ ¤ ¤ ¤ ‾‾‾‾‾‾‾ |\n";
text += $"| _____ _______ |\n";
text += $"| | 607 | | KASSA | |\n";
text += $"| ‾‾‾‾‾ ‾‾‾‾‾‾‾ |\n";
text += "------------------------------------------------------\n";

return text;
text += "------------------------------------------------------\n";
text += $"| ¤ ¤ ¤ ¤ |\n";
text += $"| |\n";
text += $"| _____ _____ _____ _____ _____ _____ |\n";
text += $"| | {Tableids[0][0]} | | {Tableids[0][1]} | | {Tableids[0][2]} | | {Tableids[0][3]} | | {Tableids[0][4]} | | {Tableids[0][5]} | |\n";
text += $"| ‾‾‾‾‾ ‾‾‾‾‾ ‾‾‾‾‾ ‾‾‾‾‾ ‾‾‾‾‾ ‾‾‾‾‾ |\n";
text += $"| ¤ ¤ ¤ ¤ |\n";
text += $"| _____ _____ _____ _____ |\n";
text += $"| | {Tableids[1][0]} | | {Tableids[1][1]} | | {Tableids[1][2]} | | {Tableids[1][3]} | |\n";
text += $"| ‾‾‾‾‾ ‾‾‾‾‾ ‾‾‾‾‾ ‾‾‾‾‾ |\n";
text += $"| ¤ ¤ ¤ ¤ _______ |\n";
text += $"| | K | |\n";
text += $"| ¤ ¤ ¤ ¤ ¤ ¤ | A | ¤ |\n";
text += $"| ______ ______ | S | |\n";
text += $"| | {Tableids[2][0]} | | {Tableids[2][1]} | | S | ¤ |\n";
text += $"| ‾‾‾‾‾‾ ‾‾‾‾‾‾ | A | |\n";
text += $"| ¤ ¤ ¤ ¤ ¤ ¤ ‾‾‾‾‾‾‾ |\n";
text += $"| _____ _______ |\n";
text += $"| | 607 | | KASSA | |\n";
text += $"| ‾‾‾‾‾ ‾‾‾‾‾‾‾ |\n";
text += "------------------------------------------------------\n";

return text;
10 Replies
CarlJohnson
CarlJohnsonOP3w ago
Oh the code format broke So what i want to do is to move from tables with arrow keys. When the cursor is on a table i want to see this character >. I dont know if this is even possible
Pobiega
Pobiega3w ago
it sure is you'll need to listen for keypresses, specifically the arrow keys, and then keep track of what table "is selected"
CarlJohnson
CarlJohnsonOP3w ago
I try to find some examples on internet but cant find anything I know how to do it like without a map only a normal lost but with this its a little difficult to think of a solution
Pobiega
Pobiega3w ago
what have you tried?
CarlJohnson
CarlJohnsonOP3w ago
Moving with arrows over a list. So if your key input was right index would be +1 and you see than > value And the tableids where printed undereachother
Pobiega
Pobiega3w ago
List<Table> tables =
[
new() { Id = 1, Position = (1, 1) },
new() { Id = 2, Position = (1, 2) },
new() { Id = 3, Position = (2, 1) },
new() { Id = 4, Position = (2, 2) },
];

Table selectedTable = tables[0];

while (true)
{
Console.Clear();
foreach (var table in tables)
{
var x = table.Position.Item1 * 10;
var y = table.Position.Item2 * 10;
Console.SetCursorPosition(x, y);
Console.WriteLine(table.Id);

if (selectedTable == table)
{
Console.SetCursorPosition(x - 1, y);
Console.WriteLine(">");
}
}

var key = Console.ReadKey();
var nextPos = key.Key switch
{
ConsoleKey.UpArrow => (selectedTable.Position.Item1, selectedTable.Position.Item2 - 1),
ConsoleKey.DownArrow => (selectedTable.Position.Item1, selectedTable.Position.Item2 + 1),
ConsoleKey.LeftArrow => (selectedTable.Position.Item1 - 1, selectedTable.Position.Item2),
ConsoleKey.RightArrow => (selectedTable.Position.Item1 + 1, selectedTable.Position.Item2),
_ => selectedTable.Position
};

selectedTable = tables.FirstOrDefault(t => t.Position == nextPos) ?? selectedTable;
}

public class Table
{
public int Id { get; init; }
public (int, int) Position { get; init; }
}
List<Table> tables =
[
new() { Id = 1, Position = (1, 1) },
new() { Id = 2, Position = (1, 2) },
new() { Id = 3, Position = (2, 1) },
new() { Id = 4, Position = (2, 2) },
];

Table selectedTable = tables[0];

while (true)
{
Console.Clear();
foreach (var table in tables)
{
var x = table.Position.Item1 * 10;
var y = table.Position.Item2 * 10;
Console.SetCursorPosition(x, y);
Console.WriteLine(table.Id);

if (selectedTable == table)
{
Console.SetCursorPosition(x - 1, y);
Console.WriteLine(">");
}
}

var key = Console.ReadKey();
var nextPos = key.Key switch
{
ConsoleKey.UpArrow => (selectedTable.Position.Item1, selectedTable.Position.Item2 - 1),
ConsoleKey.DownArrow => (selectedTable.Position.Item1, selectedTable.Position.Item2 + 1),
ConsoleKey.LeftArrow => (selectedTable.Position.Item1 - 1, selectedTable.Position.Item2),
ConsoleKey.RightArrow => (selectedTable.Position.Item1 + 1, selectedTable.Position.Item2),
_ => selectedTable.Position
};

selectedTable = tables.FirstOrDefault(t => t.Position == nextPos) ?? selectedTable;
}

public class Table
{
public int Id { get; init; }
public (int, int) Position { get; init; }
}
this works obviously extremely crude and basic, but the general concept works
Buddy
Buddy3w ago
ReadKey also have a boolean on whether you want to silence the output of the key
CarlJohnson
CarlJohnsonOP3w ago
Interesting
Pobiega
Pobiega3w ago
yep, not relevant for arrows as they dont have any output anyway, but useful for like "press space to select this table" or whatever
HtmlCompiler
HtmlCompiler3w ago
if you don't want to use a pre-made package for managing console ui it's a bit of work you have to disable some flags for example for scrolling and manually capture the input if i'm not overcomplicating it
Want results from more Discord servers?
Add your server