Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApp1;
- using System.Text;
- public class Task13
- {
- const string SetNameCommand = "SetName";
- const string ChangeConsoleColorCommand = "ChangeConsoleColor";
- const string SetPasswordCommand = "SetPassword";
- const string WriteNameCommand = "WriteName";
- const string WritePasswordCommand = "WritePassword";
- const string EscapeCommand = "Escape";
- public void Run()
- {
- Console.InputEncoding = Encoding.Unicode;
- Console.OutputEncoding = Encoding.Unicode;
- string name = string.Empty;
- string password = string.Empty;
- bool canExit = false;
- string concatedCommandsNames = $"\n{SetNameCommand}, \n{ChangeConsoleColorCommand}, \n{SetPasswordCommand}, \n{WriteNameCommand}, " +
- $"\n{WritePasswordCommand}, \n{EscapeCommand}";
- while ( canExit == false )
- {
- Console.WriteLine($"All commands: {concatedCommandsNames} \n\nEnter command:");
- string enteredCommand = Console.ReadLine();
- switch ( enteredCommand )
- {
- case SetNameCommand:
- Console.Write("Input name : ");
- name = Console.ReadLine();
- break;
- case ChangeConsoleColorCommand:
- Console.Write( "Input color : " );
- string consoleColor = Console.ReadLine();
- TrySetConsoleColor( consoleColor );
- break;
- case SetPasswordCommand:
- Console.Write( "Input password : " );
- password = Console.ReadLine();
- break;
- case WriteNameCommand:
- Console.WriteLine($"Current name is {name}");
- break;
- case WritePasswordCommand:
- Console.WriteLine( $"Current password is {password}" );
- break;
- case EscapeCommand:
- canExit = true;
- break;
- default:
- Console.WriteLine( $"Such command is not valid" );
- break;
- }
- }
- }
- private void TrySetConsoleColor(string inputColor)
- {
- string[] colorNames = Enum.GetNames<ConsoleColor>();
- ConsoleColor[] colorValues = Enum.GetValues<ConsoleColor>();
- if ( colorNames.Contains( inputColor ) )
- {
- int colorIndex = colorNames.ToList().FindIndex( color => string.Equals( color, inputColor ) );
- Console.ForegroundColor = colorValues[colorIndex];
- Console.WriteLine("Console color changed successfully");
- }
- else
- {
- Console.WriteLine( $"Entered color {inputColor} is invalid" );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement