Advertisement
yakovmonarh

Untitled

Aug 13th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.18 KB | None | 0 0
  1. // 1.3.8.4 С помощью циклов организуйте обработку команд. В программе должны быть следующие команды:  1. SetName ​ (устанавливает имя) 2. DisplayName ​ (запрашивает число, и выводит столько раз имя) 3. SetColor ​ (установка цвета фона консоли и символов)  4. DisplayBoxWithName ​ (отображение полого квадрата из символов ‘#’ с надписью имени внутри)
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using System.IO;
  7.  
  8. namespace source
  9. {
  10.     class Program
  11.     {
  12.         public static void Main(string[] args)
  13.         {  
  14.             while(true)
  15.             {
  16.                 Console.WriteLine("Введите команду:");
  17.                 GetCommand();
  18.                 CommandExecution(Console.ReadLine());
  19.             }
  20.         }
  21.        
  22.         static string Name = "Djon";
  23.         static int CountName = 20;
  24.  
  25.         enum Commands
  26.         {
  27.             SetName,
  28.             DisplayName,
  29.             SetColor,
  30.             DicplayBoxWithName
  31.         }
  32.        
  33.         static void CommandExecution(string command)
  34.         {
  35.             switch(command)
  36.             {
  37.                 case "SetName":
  38.                 Name = SetName();
  39.                 break;
  40.                 case "DisplayName":
  41.                 CountName = DisplayName();
  42.                 break;
  43.                 case "SetColor":
  44.                 SetColor();
  45.                 break;
  46.                 case "DicplayBoxWithName":
  47.                 DicplayBoxWithName(CountName);
  48.                 break;
  49.                 default:
  50.                 Console.WriteLine("Нет такой команды");
  51.                 break;
  52.             }
  53.         }
  54.        
  55.         static string SetName()
  56.         {
  57.             Console.WriteLine("Введите имя:");
  58.             return Console.ReadLine();
  59.         }
  60.        
  61.         static int DisplayName()
  62.         {
  63.             Console.WriteLine("Введите целое число:");
  64.             int count = int.Parse(Console.ReadLine());
  65.             for(int i = 0; i < count; i++)
  66.             {
  67.                 Console.WriteLine(Name);
  68.             }
  69.             return count;
  70.         }
  71.        
  72.         static void SetColor()
  73.         {
  74.             Console.WriteLine("Выберите цифру цвета:");
  75.             var colors = Enum.GetValues(typeof(ConsoleColor));
  76.             for(int i = 0; i < colors.Length; i++)
  77.             {
  78.                 Console.WriteLine("Цвет - {0}; Команда - {1}", colors.GetValue(i), i);
  79.             }
  80.             Console.WriteLine("Цвет фона:");
  81.             Console.BackgroundColor = (ConsoleColor)colors.GetValue(int.Parse(Console.ReadLine()));
  82.             Console.Clear();
  83.             Console.WriteLine("Цвет текста:");
  84.             Console.ForegroundColor = (ConsoleColor)colors.GetValue(int.Parse(Console.ReadLine()));
  85.         }
  86.        
  87.         static void DicplayBoxWithName(int sizeSquare)
  88.         {
  89.             for(int i = 0; i < sizeSquare; i++)
  90.             {
  91.                 if(i == 0 || i == sizeSquare-1)
  92.                 {
  93.                     Console.WriteLine(new String('#', sizeSquare));
  94.                 }
  95.                 else
  96.                 {
  97.                     Char[] mass = Name.ToCharArray();
  98.                     if(sizeSquare/2 == i)
  99.                     {
  100.                         Console.WriteLine("#" + new String(mass, 0, mass.Length) + new String(' ', sizeSquare-2-mass.Length) + "#");
  101.                     }
  102.                     else
  103.                     {
  104.                         Console.WriteLine("#" + new String(' ', sizeSquare - 2) + "#");
  105.                     }
  106.                    
  107.                 }
  108.             }
  109.         }
  110.        
  111.         static void GetCommand()
  112.         {
  113.             var comm = Enum.GetValues(typeof(Commands));
  114.             for(int i = 0; i < comm.Length; i++)
  115.             {
  116.                 Console.WriteLine(comm.GetValue(i));
  117.             }
  118.             Console.WriteLine("");
  119.         }
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement