Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1.3.8.4 С помощью циклов организуйте обработку команд. В программе должны быть следующие команды: 1. SetName (устанавливает имя) 2. DisplayName (запрашивает число, и выводит столько раз имя) 3. SetColor (установка цвета фона консоли и символов) 4. DisplayBoxWithName (отображение полого квадрата из символов ‘#’ с надписью имени внутри)
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- namespace source
- {
- class Program
- {
- public static void Main(string[] args)
- {
- while(true)
- {
- Console.WriteLine("Введите команду:");
- GetCommand();
- CommandExecution(Console.ReadLine());
- }
- }
- static string Name = "Djon";
- static int CountName = 20;
- enum Commands
- {
- SetName,
- DisplayName,
- SetColor,
- DicplayBoxWithName
- }
- static void CommandExecution(string command)
- {
- switch(command)
- {
- case "SetName":
- Name = SetName();
- break;
- case "DisplayName":
- CountName = DisplayName();
- break;
- case "SetColor":
- SetColor();
- break;
- case "DicplayBoxWithName":
- DicplayBoxWithName(CountName);
- break;
- default:
- Console.WriteLine("Нет такой команды");
- break;
- }
- }
- static string SetName()
- {
- Console.WriteLine("Введите имя:");
- return Console.ReadLine();
- }
- static int DisplayName()
- {
- Console.WriteLine("Введите целое число:");
- int count = int.Parse(Console.ReadLine());
- for(int i = 0; i < count; i++)
- {
- Console.WriteLine(Name);
- }
- return count;
- }
- static void SetColor()
- {
- Console.WriteLine("Выберите цифру цвета:");
- var colors = Enum.GetValues(typeof(ConsoleColor));
- for(int i = 0; i < colors.Length; i++)
- {
- Console.WriteLine("Цвет - {0}; Команда - {1}", colors.GetValue(i), i);
- }
- Console.WriteLine("Цвет фона:");
- Console.BackgroundColor = (ConsoleColor)colors.GetValue(int.Parse(Console.ReadLine()));
- Console.Clear();
- Console.WriteLine("Цвет текста:");
- Console.ForegroundColor = (ConsoleColor)colors.GetValue(int.Parse(Console.ReadLine()));
- }
- static void DicplayBoxWithName(int sizeSquare)
- {
- for(int i = 0; i < sizeSquare; i++)
- {
- if(i == 0 || i == sizeSquare-1)
- {
- Console.WriteLine(new String('#', sizeSquare));
- }
- else
- {
- Char[] mass = Name.ToCharArray();
- if(sizeSquare/2 == i)
- {
- Console.WriteLine("#" + new String(mass, 0, mass.Length) + new String(' ', sizeSquare-2-mass.Length) + "#");
- }
- else
- {
- Console.WriteLine("#" + new String(' ', sizeSquare - 2) + "#");
- }
- }
- }
- }
- static void GetCommand()
- {
- var comm = Enum.GetValues(typeof(Commands));
- for(int i = 0; i < comm.Length; i++)
- {
- Console.WriteLine(comm.GetValue(i));
- }
- Console.WriteLine("");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement