Untitled
unknown
plain_text
a year ago
3.8 kB
5
Indexable
int selectedIndex = 0; string[] menu = new string[] { "Book", "Settings", "Exit" }; while (true) { Console.Clear(); Console.WriteLine("Menu"); for (int i = 0; i < menu.GetLength(0); i++) { if (selectedIndex == i) { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine($"{i + 1}. {menu[i]} <<<"); } else { Console.ResetColor(); Console.WriteLine($"{i + 1}. {menu[i]}"); } } ConsoleKeyInfo keyInfo = Console.ReadKey(); switch (keyInfo.Key) { case ConsoleKey.UpArrow: if (selectedIndex > 0) { selectedIndex--; } break; case ConsoleKey.DownArrow: if (selectedIndex < menu.GetLength(0) - 1) { selectedIndex++; } break; case ConsoleKey.Enter: if (selectedIndex == 0) { Console.Clear(); ShowSeats(); Console.ReadKey(); } else if (selectedIndex == 1) { Console.Clear(); Console.WriteLine("Here are some settings"); Console.ReadKey(); } else if (selectedIndex == 2) { Console.Clear(); Console.ResetColor(); return; } break; } Console.ResetColor(); } static void ShowSeats() { int selectedIndexY = 0; int selectedIndexX = 0; while (true) { Console.Clear(); string[,] aviaTickets = new string[6, 4] { { " [A1] ", " [A2] "," [A3] "," [A4] " }, { " [B1] ", " [B2] "," [B3] "," [B4] " }, { " [C1] ", " [C2] "," [C3] "," [C4] " }, { " [D1] ", " [D2] "," [D3] "," [D4] " }, { " [E1] ", " [E2] "," [E3] "," [E4] " }, { " [F1] ", " [F2] "," [F3] "," [F4] " } }; Console.WriteLine("Book"); for (int i = 0; i < aviaTickets.GetLength(0); i++) { for (int j = 0; j < aviaTickets.GetLength(1); j++) { if (i == selectedIndexY && j == selectedIndexX) { Console.ForegroundColor = ConsoleColor.Green; } else { Console.ResetColor(); } Console.Write(aviaTickets[i, j]); } Console.WriteLine(); } ConsoleKeyInfo keyInfo = Console.ReadKey(); switch (keyInfo.Key) { case ConsoleKey.UpArrow: { if (selectedIndexY > 0) { selectedIndexY--; } } break; case ConsoleKey.DownArrow: { if (selectedIndexY < aviaTickets.GetLength(0) - 1) { selectedIndexY++; } } break; case ConsoleKey.LeftArrow: { if (selectedIndexX > 0) { selectedIndexX--; } } break; case ConsoleKey.RightArrow: { if (selectedIndexX < aviaTickets.GetLength(1) - 1) { selectedIndexX++; } } break; } Console.ResetColor (); } }
Editor is loading...
Leave a Comment