Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp12
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] numbers = new int[] { 1, 2, 3, 4, 5 };
- bool exit = false;
- int menuBar = 0;
- string[] menu = { "1. Вывести массив.", "2. Перемешать массив.", "3. Выйти." };
- Console.CursorVisible = false;
- while (exit == false)
- {
- string selectMenuParagraph;
- DrawMenu(menuBar, menu);
- ChangeDirection(ref menuBar, menu, out selectMenuParagraph);
- Console.Clear();
- switch (selectMenuParagraph)
- {
- case "1. Вывести массив.":
- DrawaArray(numbers);
- break;
- case "2. Перемешать массив.":
- Shuffle(numbers);
- break;
- case "3. Выйти.":
- exit = true;
- break;
- }
- }
- }
- static void DrawLabels(string text)
- {
- Console.SetCursorPosition(30, 0);
- Console.Write(text);
- }
- static void DrawaArray(int[] array)
- {
- Console.SetCursorPosition(30, 0);
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write($"{array[i]} ");
- }
- }
- static void Shuffle(int[] array)
- {
- Random rand = new Random();
- for (int i = array.Length - 1; i >= 1; i--)
- {
- int j = rand.Next(i + 1);
- int temp = array[j];
- array[j] = array[i];
- array[i] = temp;
- }
- }
- static void DrawMenu(int surnameSearch, string[] items)
- {
- Console.SetCursorPosition(0, 0);
- for (int i = 0; i < items.Length; i++)
- {
- if (i == surnameSearch)
- {
- Console.BackgroundColor = ConsoleColor.Gray;
- Console.ForegroundColor = ConsoleColor.Black;
- Console.WriteLine(items[i]);
- }
- else
- {
- Console.WriteLine(items[i]);
- }
- Console.ResetColor();
- }
- }
- static string GetChoise(string[] items, int menuBar)
- {
- return items[menuBar];
- }
- static void ChangeDirection(ref int menuBar, string[] items, out string selectMenuParagraph)
- {
- selectMenuParagraph = "";
- ConsoleKeyInfo key = Console.ReadKey();
- switch (key.Key)
- {
- case ConsoleKey.UpArrow:
- if (menuBar <= 0)
- {
- menuBar = items.Length - 1;
- DrawMenu(menuBar, items);
- }
- else
- {
- menuBar--;
- DrawMenu(menuBar, items);
- }
- break;
- case ConsoleKey.DownArrow:
- if (menuBar == items.Length - 1)
- {
- menuBar = 0;
- DrawMenu(menuBar, items);
- }
- else
- {
- menuBar++;
- DrawMenu(menuBar, items);
- }
- break;
- case ConsoleKey.Enter:
- {
- selectMenuParagraph = GetChoise(items, menuBar);
- }
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment